Download the PHP package kevinpirnie/kpt-wpfieldframework without Composer
On this page you can find all versions of the php package kevinpirnie/kpt-wpfieldframework. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kevinpirnie/kpt-wpfieldframework
More information about kevinpirnie/kpt-wpfieldframework
Files in kevinpirnie/kpt-wpfieldframework
Package kpt-wpfieldframework
Short Description A PHP framework for creating WordPress Options Pages, Meta Boxes, and Gutenberg Blocks with repeatable field groups.
License MIT
Homepage https://kevinpirnie.com/
Informations about the package kpt-wpfieldframework
KPT WP Field Framework
A PHP framework for creating WordPress Options Pages, Meta Boxes, and Gutenberg Blocks with repeatable field groups.
Requirements
- PHP 8.2+
- WordPress 6.8+
Installation
Quick Start
In a Plugin
In a Theme
Options Pages
Basic Options Page
Tabbed Options Page
Tabbed options pages allow you to organize settings into multiple tabs. Each tab's settings are preserved when saving - only the current tab's fields are updated while other tabs' data remains intact.
Submenu Options Page
Retrieving Options
Meta Boxes
Post/Page Meta Box
Custom Post Type Meta Box
User Profile Meta Box
Nav Menu Item Meta Box
Retrieving Meta Values
Gutenberg Blocks
Creating a Block from a Meta Box
Custom Block Rendering
Block template file (blocks/testimonial.php):
Field Types
Text-Based Fields
Date/Time Fields
Selection Fields
Text Areas & Editors
Media Fields
Special Fields
Layout Fields
Conditional Fields
Fields can be shown or hidden based on the values of other fields in the same section. Conditionals are evaluated in real-time using JavaScript.
Single Condition
Multiple Conditions (AND)
All conditions must be true for the field to be visible.
Multiple Conditions (OR)
At least one condition must be true for the field to be visible.
Available Condition Operators
| Operator | Description |
|---|---|
== |
Equal to |
!= |
Not equal to |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal to |
<= |
Less than or equal to |
IN |
Value is in array/comma-separated list |
NOT_IN |
Value is not in array/comma-separated list |
CONTAINS |
Value contains substring or array contains value |
NOT_CONTAINS |
Value does not contain substring |
EMPTY |
Value is empty |
NOT_EMPTY |
Value is not empty |
Conditional with Radio Buttons
Conditionals on Groups and Accordions
Groups and accordions fully support conditional logic. You can show/hide entire groups or accordions based on other field values.
Nested Conditionals (Inside Accordions/Groups)
When using conditionals on fields inside an accordion or group, the field IDs are automatically prefixed with the parent's ID. You must use the prefixed field ID when referencing sibling fields within the same parent.
For example, if you have an accordion with ID my_accordion containing a switch with ID enable_option, the actual field ID becomes my_accordion_enable_option. Any conditional referencing this field must use the full prefixed ID:
Important: When a conditional references a field outside the accordion/group (at the root level), use the original field ID without any prefix:
Repeater Fields
Basic Repeater
Repeater with Multiple Field Types
Retrieving Repeater Data
Field Groups
Basic Group
Inline Group Fields
Use the inline option to display fields side-by-side within a group:
Retrieving Group Data
Note: Group sub-field values are stored with the group ID as a prefix (e.g., address_street for a field with ID street inside a group with ID address).
Accordion Fields
Accordions provide a collapsible container for organizing related fields:
Field Configuration Options
All fields support these common options:
| Option | Type | Description |
|---|---|---|
id |
string | Unique field identifier (required) |
type |
string | Field type (required) |
label |
string | Field label |
sublabel |
string | Secondary label displayed below the main label |
description |
string | Help text displayed below field |
default |
mixed | Default value |
placeholder |
string | Placeholder text |
required |
bool | Whether field is required |
disabled |
bool | Whether field is disabled |
readonly |
bool | Whether field is read-only |
class |
string | Additional CSS class(es) |
inline |
bool | Display field inline (for groups/repeaters) |
attributes |
array | Additional HTML attributes |
sanitize |
callable | Custom sanitization callback |
validate |
callable | Custom validation callback |
conditional |
array | Conditional display rules |
Custom Sanitization
Custom Validation
Storage API
The Storage class provides a unified interface for all WordPress data storage:
Export / Import Settings
The framework includes built-in functionality to export and import settings, making it easy to backup configurations or migrate settings between environments.
Enabling Export/Import UI
Add show_export_import => true to your options page configuration:
This adds an "Export / Import Settings" panel at the bottom of your options page that allows users to:
- Export: Download all current settings (including defaults for unsaved fields) as a JSON file
- Import: Upload a previously exported JSON file to restore settings
Programmatic Export/Import
You can also export and import settings programmatically:
Export File Format
Exported JSON files include metadata and all settings:
Security Considerations
- Export/Import requires the
manage_optionscapability - Imports are validated against registered option keys (whitelist)
- All values pass through the framework's sanitization on import
- AJAX endpoints are protected with nonce verification
Advanced Usage
Manual Initialization
Requirements Check
The framework automatically checks requirements when using Loader::init(). If requirements are not met, an admin notice is displayed.
Without Composer Autoloader
JavaScript Events
The framework triggers custom jQuery events for extensibility:
Global JavaScript Object
The framework exposes a global KpWsfAdmin object:
Hooks & Filters
The framework integrates with standard WordPress hooks. Meta boxes use these hooks:
add_meta_boxes- Register meta boxessave_post- Save post metapersonal_options_update- Save user meta (own profile)edit_user_profile_update- Save user meta (other profiles)show_user_profile- Display user fields (own profile)edit_user_profile- Display user fields (other profiles)wp_nav_menu_item_custom_fields- Display nav menu fieldswp_update_nav_menu_item- Save nav menu meta
License
MIT License. See LICENSE file for details.
Author
Kevin Pirnie - [email protected]
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter any issues or have questions, please open an issue on GitHub.