rwsite / wp-field
Modern Laravel-style field generator for WordPress with 50+ field types, fluent API, React UI, repeater/flexible content fields, conditional logic, and complete storage strategies.
Package info
github.com/tikhomirov/wp-field-plugin
Type:wordpress-plugin
pkg:composer/rwsite/wp-field
Requires
- php: >=8.3
Requires (Dev)
- laravel/pint: ^1.16
- pestphp/pest: ^4.1
- phpstan/phpstan: ^1.10
- phpunit/phpunit: 12.4.1
- szepeviktor/phpstan-wordpress: ^1.3
README
WP_Field
HTML Fields Library for WordPress
A foundation for building custom frameworks, settings systems, and admin UIs.
Fluent API, 48 unique field types (+4 aliases), React/Vanilla UI, and modern v3 architecture.
Features • Installation • Quick Start • Field Types • Examples • Dependencies • RU version
Features
v3.0 — Modern Laravel-Style API
- ✨ Fluent Interface — Chain methods like Laravel:
Field::text('name')->label('Name')->required() - 🔁 Repeater Fields — Infinite nesting support with min/max constraints
- 🎨 Flexible Content — ACF-style layout builder with multiple block types
- ⚛️ React UI — Modern React components with Vanilla JS fallback
- 🏗️ SOLID Architecture — Interfaces, traits, dependency injection
- 📦 Storage Strategies — PostMeta, TermMeta, UserMeta, Options, CustomTable
- 🛡️ Type Safety — PHPStan Level 9, strict types, full PHPDoc
Core Features
- 🚀 48 Unique Field Types — Text, select, repeater, flexible content, and more
- ♻️ 4 Compatibility Aliases —
date_time,datetime-local,image_picker,imagepicker - 🔗 Conditional Logic — 14 operators with AND/OR relations
- 🧪 Full Test Coverage — Pest/PHPUnit tests with 100% pass rate
- 🎨 WP Components — Native WordPress UI integration
- 🌍 i18n Ready — Multilingual support
Requirements
- PHP 8.3+
- WordPress 6.0+
- Composer (for installation)
Installation
Via Composer (Recommended)
composer require rwsite/wp-field
Manual Installation
- Clone or download to
wp-content/plugins/wp-field-plugin - Run
composer install --no-dev - Activate the plugin in WordPress admin
Build React Components (Optional)
npm install npm run build
Quick Start
Modern API (v3.0)
use WpField\Field\Field; use WpField\Container\MetaboxContainer; // Fluent interface $field = Field::text('email') ->label('Email Address') ->placeholder('user@example.com') ->required() ->email() ->class('regular-text'); // Render field echo $field->render(); // Create metabox with fields $metabox = new MetaboxContainer('product_details', [ 'title' => 'Product Details', 'post_types' => ['product'], ]); $metabox->addField( Field::text('sku')->label('SKU')->required() ); $metabox->addField( Field::text('price')->label('Price')->required() ); $metabox->register();
Repeater Field
$repeater = Field::repeater('team_members') ->label('Team Members') ->fields([ Field::text('name')->label('Name')->required(), Field::text('position')->label('Position'), Field::text('email')->label('Email')->email(), ]) ->min(1) ->max(10) ->buttonLabel('Add Member') ->layout('table');
Flexible Content Field
$flexible = Field::flexibleContent('page_sections') ->label('Page Sections') ->addLayout('text_block', 'Text Block', [ Field::text('heading')->label('Heading'), Field::text('content')->label('Content'), ]) ->addLayout('image', 'Image', [ Field::text('image_url')->label('Image URL')->url(), Field::text('caption')->label('Caption'), ]) ->min(1) ->buttonLabel('Add Section');
Field Types (48 unique + 4 aliases)
Basic (9)
text— Text inputpassword— Password fieldemail— Email inputurl— URL inputtel— Telephone inputnumber— Number inputrange— Range sliderhidden— Hidden fieldtextarea— Multi-line text
Choice (5)
select— Dropdown listmultiselect— Multiple selectionradio— Radio buttonscheckbox— Single checkboxcheckbox_group— Checkbox group
Advanced (9)
editor— wp_editormedia— Media library (ID or URL)image— Image with previewfile— File uploadgallery— Image gallerycolor— Color pickerdate— Date pickertime— Time pickerdatetime— Date and time
Composite (2)
group— Nested fieldsrepeater— Repeating elements
Simple Fields (9)
switcher— On/off switcherspinner— Number spinnerbutton_set— Button selectionslider— Value sliderheading— Headingsubheading— Subheadingnotice— Notice (info/success/warning/error)content— Custom HTML contentfieldset— Field grouping
Medium Complexity Fields (10)
accordion— Collapsible sectionstabbed— Tabstypography— Typography settingsspacing— Spacing controlsdimensions— Size controlsborder— Border settingsbackground— Background optionslink_color— Link colorscolor_group— Color groupimage_select— Image selection
High Complexity Fields (8)
code_editor— Code editor with syntax highlightingicon— Icon picker from librarymap— Google Maps locationsortable— Drag & drop sortingsorter— Enabled/disabled sortingpalette— Color palettelink— Link field (URL + text + target)backup— Settings export/import
Examples
Dependencies
// Show field only if another field has specific value Field::text('courier_address') ->label('Delivery Address') ->when('delivery_type', '==', 'courier'); // Multiple conditions (AND) Field::text('special_field') ->label('Special Field') ->when('field1', '==', 'value1') ->when('field2', '!=', 'value2'); // Multiple conditions (OR) Field::text('notification') ->label('Notification') ->when('type', '==', 'sms') ->orWhen('type', '==', 'email');
Repeater
Field::repeater('work_times') ->label('Work Times') ->min(1) ->max(7) ->buttonLabel('Add Day') ->fields([ Field::make('select', 'day') ->label('Day') ->options(['mon' => 'Mon', 'tue' => 'Tue']), Field::make('time', 'from') ->label('From'), Field::make('time', 'to') ->label('To'), ]);
Group
Field::make('group', 'address') ->label('Address') ->fields([ Field::text('city')->label('City'), Field::text('street')->label('Street'), Field::text('number')->label('Number'), ]);
Code Editor
Field::make('code_editor', 'custom_css') ->label('Custom CSS') ->mode('css') // css, javascript, php, html ->height('400px');
Icon Picker
Field::make('icon', 'menu_icon') ->label('Menu Icon') ->library('dashicons');
Map
Field::make('map', 'location') ->label('Location') ->apiKey('YOUR_GOOGLE_MAPS_API_KEY') ->zoom(12) ->center(['lat' => 55.7558, 'lng' => 37.6173]);
Sortable
Field::make('sortable', 'menu_order') ->label('Menu Order') ->options([ 'home' => 'Home', 'about' => 'About', 'services' => 'Services', 'contact' => 'Contact', ]);
Palette
Field::make('palette', 'color_scheme') ->label('Color Scheme') ->palettes([ 'blue' => ['#0073aa', '#005a87', '#003d82'], 'green' => ['#28a745', '#218838', '#1e7e34'], 'red' => ['#dc3545', '#c82333', '#bd2130'], ]);
Link
Field::make('link', 'cta_button') ->label('CTA Button'); // Get value: // $link = get_post_meta($post_id, 'cta_button', true); // ['url' => '...', 'text' => '...', 'target' => '_blank']
Accordion
Field::make('accordion', 'settings_accordion') ->label('Settings') ->sections([ [ 'title' => 'General', 'open' => true, 'fields' => [ Field::text('title')->label('Title'), ], ], [ 'title' => 'Advanced', 'fields' => [ Field::make('textarea', 'desc')->label('Description'), ], ], ]);
Typography
Field::make('typography', 'heading_typography') ->label('Heading Typography'); // Saved as: // [ // 'font_family' => 'Arial', // 'font_size' => '24', // 'font_weight' => '700', // 'line_height' => '1.5', // 'text_align' => 'center', // 'color' => '#333333' // ]
Dependency Operators
==— Equal!=— Not equal>,>=,<,<=— Comparisonin— In arraynot_in— Not in arraycontains— Containsnot_contains— Not containsempty— Emptynot_empty— Not empty
Interactive Demo
See all 48 field types in action:
👉 Tools → WP_Field Examples (Classic API demo)
👉 /wp-admin/tools.php?page=wp-field-examples
👉 Tools → WP_Field v3.0 Demo (Modern Fluent API)
👉 /wp-admin/tools.php?page=wp-field-v3-demo
The demo pages include:
- ✅ All 48 field types with live examples
- ✅ Code for each field
- ✅ Fluent API demonstrations (v3.0)
- ✅ Repeater and Flexible Content examples
- ✅ Conditional Logic with 14 operators
- ✅ React/Vanilla UI mode switching
- ✅ Dependency system demonstration
- ✅ Ability to save and test
Extensibility
Adding Custom Field Types
add_filter('wp_field_types', function($types) { $types['custom_type'] = ['render_custom', ['default' => 'value']]; return $types; });
Adding Icon Libraries
add_filter('wp_field_icon_library', function($icons, $library) { if ($library === 'fontawesome') { return ['fa-home', 'fa-user', 'fa-cog', ...]; } return $icons; }, 10, 2);
Custom Value Retrieval
add_filter('wp_field_get_value', function($value, $storage_type, $key, $id, $field) { if ($storage_type === 'custom') { return get_custom_value($key, $id); } return $value; }, 10, 5);
Changelog
See CHANGELOG.md for detailed version history.
Project Stats
- PHP Lines: 2705 (WP_Field.php)
- JS Lines: 1222 (wp-field.js)
- CSS Lines: 1839 (wp-field.css)
- Field Types: 48
- Dependency Operators: 12
- Storage Types: 5
- External Dependencies: 0
Compatibility
- WordPress: 6.0+
- PHP: 8.3+
- Dependencies: jQuery, jQuery UI Sortable, WordPress built-in components
- Browsers: Chrome, Firefox, Safari, Edge (latest 2 versions)
Performance
- Minimal CSS size: ~20KB
- Minimal JS size: ~15KB
- Lazy loading for heavy components (CodeMirror, Google Maps)
- Optimized selectors and events
License
GPL v2 or later
Author
Aleksei Tikhomirov (https://rwsite.ru)