WordPress Settings Kit - Lightweight library for easily creating WordPress Settings Pages and Post Metaboxes
β βοΈ Make sure you β and π this repository!
Ever wanted to build custom settings (or metaboxes) inside your WordPress plugin or theme and didn't like the non-DRY approach for creating custom settings and metaboxes via WordPress API? Well, this package is an attempt to fix this. π
- You can install the library using composer
composer require youniwemi/wp-settings-kit
- You'll be able to use WP_Settings_Kit class after requiring vendor/autoload.php
- Prepare an array of options then instanciate WP_Settings_Kit
$options =
[
'name' => 'MY_AWESOME_FEATURE',
'title' => 'My Awesome Feature',
'description' => "My Awesome Feature description",
'side_panel' => "<p>A side Panel content : to add some explanations if necessary</p>",
'fields' => [
[
'id' => 'ACTIVE',
'type' => 'checkbox',
'title' => 'The feature is active' ,
],
[
'id' => 'FIRST_SETTING',
'type' => 'number',
'title' => 'First setting' ,
'default' => 0 ,
// This setting will be included only if the first checkbox is checked
'show_if' => function(){ return defined('MY_AWESOME_FEATURE_ACTIVE') && MY_AWESOME_FEATURE_ACTIVE == 'on'; }
]
]
];
$setting = new WP_Settings_Kit($options);
- Once the options are saved, constants MY_AWESOME_FEATURE_ACTIVE will be available and will be able to set the first setting MY_AWESOME_FEATURE_FIRST_SETTING
- Prepare an array of options as well as the metabox definition then instanciate WP_Settings_Kit
$options =
[
'name' => 'MY_AWESOME_FEATURE',
'title' => 'My Awesome Feature',
'fields' => [
[
'id' => 'ACTIVE',
'type' => 'checkbox',
'title' => 'The feature is active' ,
],
[
'id' => 'FIRST_SETTING',
'type' => 'number',
'title' => 'First setting' ,
'default' => 0 ,
// This field will be included only if the first checkbox is checked
'show_if' => function(){ return defined('MY_AWESOME_FEATURE_ACTIVE') && MY_AWESOME_FEATURE_ACTIVE == 'on'; }
]
]
];
$metabox = [
'id' => 'my_metabox',
'title' => 'My Awesome Metabox',
'post_types' => ['post'], // Post types to display meta box
'context' => 'advanced',
'priority' => 'default',
];
$metabox = new WP_Settings_Kit($options , $metabox);
- Once the metabox is saved, fields will be saved as post metas : MY_AWESOME_FEATURE_FIRST_ACTIVE and MY_AWESOME_FEATURE_FIRST_SETTING
- Basic Settings Page
- Tabs on Settings Page with JS
- Tabs on Settings Page with JS
- Documentation for code workflow
- Create Field:
text
- Create Field:
textarea
- Create Field:
url
- Create Field:
number
- Create Field:
checkbox
- Create Field:
multicheck
- Create Field:
radio
- Create Field:
select
- Create Field:
html
- Create Field:
wysiwyg
- Create Field:
file
- Create Field:
image
- Create Field:
password
- Create Field:
color
- Create Field:
email
- Create Field:
date
- Create Field (generated content with callback):
content
- Create Field:
range
- Support for post metabox
- Re-factor the code with WP Standards
- Tutorials
- Blog post
- Documentation
Release under GNU GPL v2.0
This package is a fork of https://github.com/ahmadawais/WP-OOP-Settings-API based on the work of @tareq1988 https://github.com/tareq1988/wordpress-settings-api-class
@AhmadAwais, @deviorobert, @MaedahBatool AND @WordPress, @tareq1988, @royboy789, @twigpress, @rahal.
π Youniwemi
This open source fork is maintained by the help of awesome businesses listed below :
This package is used in the following wordpress plugins
For anything else, tweet at @rahalaboulfeth