A powerful, flexible Composer library for building WordPress plugins with custom post types, settings pages, and dynamic form fields.
- Custom Post Types: Easy registration with fluent interface and array configuration
- Settings Pages: Top-level and submenu pages with automatic rendering
- Dynamic Fields: 11 core field types with extensibility via custom field types
- Array Configuration: Register CPTs, settings, and fields from a single array ✨ NEW
- Asset System: Automatic CSS/JS loading for field styling and validation ✨ NEW
- Configuration-Driven: Create fields from PHP arrays or JSON files
- JSON Configuration: Load configurations from JSON files with schema validation ✨ NEW
- Advanced Validation: Enhanced schema with boundary checks and type-specific rules ✨ NEW
- Validation & Sanitization: Built-in security with customizable rules
- Asset Management: Context-aware CSS/JS enqueuing for fields
- Type-Safe: PSR-4 autoloading with full interface contracts
- Well-Tested: 229 PHPUnit tests with 691 assertions ✨ UPDATED
- Security: Nonces, capability checks, output escaping, and input sanitization
- i18n Ready: Full internationalization support with translation infrastructure ✨ NEW
composer require pedalcms/wp-cmfCreate a complete plugin with custom post types and settings in one configuration array:
<?php
/**
* Plugin Name: My Custom Plugin
* Description: Built with WP-CMF
*/
use Pedalcms\WpCmf\Core\Manager;
function my_plugin_init() {
$config = [
'cpts' => [
[
'id' => 'product',
'args' => [
'label' => 'Products',
'public' => true,
'has_archive' => true,
'supports' => [ 'title', 'editor', 'thumbnail' ],
'menu_icon' => 'dashicons-cart',
],
'fields' => [
[
'name' => 'sku',
'type' => 'text',
'label' => 'SKU',
'required' => true,
'placeholder' => 'PROD-001',
],
[
'name' => 'price',
'type' => 'number',
'label' => 'Price',
'min' => 0,
'step' => 0.01,
'default' => 0,
],
[
'name' => 'stock_status',
'type' => 'select',
'label' => 'Stock Status',
'options' => [
'in_stock' => 'In Stock',
'out_of_stock' => 'Out of Stock',
'on_backorder' => 'On Backorder',
],
'default' => 'in_stock',
],
[
'name' => 'featured',
'type' => 'checkbox',
'label' => 'Featured Product',
'description' => 'Display this product prominently',
],
],
],
],
'settings_pages' => [
[
'id' => 'my-plugin-settings',
'page_title' => 'My Plugin Settings',
'menu_title' => 'My Plugin',
'capability' => 'manage_options',
'icon' => 'dashicons-admin-settings',
'fields' => [
[
'name' => 'api_key',
'type' => 'text',
'label' => 'API Key',
'required' => true,
'description' => 'Enter your API key from the service provider',
],
[
'name' => 'api_secret',
'type' => 'password',
'label' => 'API Secret',
'required' => true,
],
[
'name' => 'enable_cache',
'type' => 'checkbox',
'label' => 'Enable Caching',
'description' => 'Cache API responses for better performance',
'default' => true,
],
[
'name' => 'cache_duration',
'type' => 'number',
'label' => 'Cache Duration (hours)',
'min' => 1,
'max' => 168,
'default' => 24,
],
],
],
],
];
Manager::init()->register_from_array( $config );
}
add_action( 'init', 'my_plugin_init' );use Pedalcms\WpCmf\Core\Manager;
function my_cpt_init() {
Manager::init()->register_from_array([
'cpts' => [
[
'id' => 'book',
'args' => [
'label' => 'Books',
'public' => true,
'supports' => [ 'title', 'editor', 'thumbnail' ],
],
'fields' => [
[
'name' => 'isbn',
'type' => 'text',
'label' => 'ISBN',
],
[
'name' => 'author',
'type' => 'text',
'label' => 'Author',
],
],
],
],
]);
}
add_action( 'init', 'my_cpt_init' );use Pedalcms\WpCmf\Core\Manager;
function extend_general_settings() {
Manager::init()->register_from_array([
'settings_pages' => [
[
'id' => 'general', // WordPress built-in page
'fields' => [
[
'name' => 'company_name',
'type' => 'text',
'label' => 'Company Name',
'description' => 'Your company or organization name',
],
[
'name' => 'contact_email',
'type' => 'email',
'label' => 'Contact Email',
],
],
],
],
]);
}
add_action( 'init', 'extend_general_settings' );WP-CMF includes 11 ready-to-use field types:
| Type | Description | Features |
|---|---|---|
text |
Single-line text input | Placeholder, maxlength, pattern |
textarea |
Multi-line text input | Rows, cols, maxlength |
select |
Dropdown select | Single/multiple, options |
checkbox |
Single or multiple checkboxes | Inline/stacked layout |
radio |
Radio button group | Inline/stacked layout |
number |
Numeric input | Min, max, step, validation |
email |
Email input | Automatic validation |
url |
URL input | Automatic validation |
date |
Date picker | Min/max date, format validation |
password |
Password input | Masked, security-focused |
color |
Color picker | WordPress color picker integration |
- Field API - Complete field system documentation
- Usage Guide - Comprehensive usage examples
- Examples - 13 working examples covering all features
WP-CMF includes 13 complete, working examples demonstrating all major features:
- Basic CPT (Array) - Simple custom post type with array configuration
- Basic CPT (JSON) - Simple custom post type with JSON configuration
- Settings Page (Array) - Basic settings page with array config
- Settings Page (JSON) - Basic settings page with JSON config
- Complete Array Example - Multiple CPTs and settings pages with all field types (array)
- Complete JSON Example - Multiple CPTs and settings pages with all field types (JSON)
- Existing Post Type (Array) - Add fields to WordPress core post types (array)
- Existing Post Type (JSON) - Add fields to WordPress core post types (JSON)
- Existing Settings Page (Array) - Add fields to WordPress General Settings (array)
- Existing Settings Page (JSON) - Add fields to WordPress General Settings (JSON)
- CPT with Submenu Settings (Array) ⭐ - Product CPT with settings submenu (13 fields + 19 settings, array config)
- CPT with Submenu Settings (JSON) ⭐ - Product CPT with settings submenu (13 fields + 19 settings, JSON config)
- Custom Field Type ⭐ - Create custom SliderField and use in settings
⭐ = Recommended starting points for complex projects
- PHP: 8.1 or higher
- WordPress: 6.0 or higher
- Composer: For autoloading
Core Framework
- ✅ Custom Post Types with full WordPress integration
- ✅ Settings Pages (top-level and submenu)
- ✅ 11 production-ready field types
- ✅ Custom field type extensibility via
AbstractField - ✅ FieldFactory for dynamic field creation
- ✅ Array-based configuration system
- ✅ JSON configuration with schema validation
- ✅ Context-aware asset enqueuing (CSS/JS)
Security & Standards
- ✅ Input sanitization and validation
- ✅ CSRF protection (nonces and capability checks)
- ✅ Output escaping (XSS prevention)
- ✅ WordPress coding standards compliant
- ✅ PSR-4 autoloading
Internationalization
- ✅ Full i18n support with
wp-cmftext domain - ✅ Translation template (POT file)
- ✅ WordPress and non-WordPress fallbacks
Quality Assurance
- ✅ 229 PHPUnit tests (691 assertions)
- ✅ Edge case and integration testing
- ✅ 13 complete working examples
- 📋 Milestone 6: Documentation expansion
- 🚀 Milestone 7: CI/CD pipeline & v1.0 release
Current Status: 229/229 tests passing (691 assertions) ✅
Run the test suite:
composer testContributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Write tests for your changes
- Ensure all tests pass (
composer test) - Submit a pull request
This project is licensed under the GPL-2.0-or-later License. See LICENSE for details.
- Issues: GitHub Issues
- Documentation: docs/
- Examples: examples/