Skelet is a framework for creating WordPress plugins, it eases the creation of:
- Advanced option pages
- Widgets
- Shortcodes
- Taxonomies
- Metaboxes
- WP Customize
- Templating
- Adding custom fields in pages, posts, custom post types, taxonomies, widgets and customizer.
- Installation and Adding Skelet to a Project
- Configuration Files
- Pulling Values
- Supported Options Fields
- Credits & Links
- Changelog
Let's assume that you want to use Skelet Framework in the plugin-boilerplate.
Instructions below assumes that you have already installed composer on your system, if not you can download it here.
- Including Skelet has been made easy with the use of composer. First create a
composer.json
file if it's not included on your/plugin-boilerplate/
. - Copy and paste code below on
composer.json
, make sure to edit name and description of your file to fit on your current plugin.
{
"name": "pressapps/plugin-boilerplate ( must be edited )",
"description": "This is composer.json file for plugin-boilerplate ( must be edited )",
"authors": [
{
"name": "PressApps Team",
"email": "[email protected]"
}
],
"config" : {
"vendor-dir" : "includes"
},
"repositories" : [
{
"type" : "package",
"package" : {
"name" : "skelet",
"version" : "1.0.0",
"source" : {
"url" : "https://github.com/pressapps/skelet.git",
"type" : "git",
"reference": "master"
}
}
}
],
"require": {
"skelet" : "1.0.*"
}
}
- Using your terminal type in
cd /path/to/plugin-boilerplate/
-/path/to/
refers to the exact path of yourplugin-boilerplate
. - Once your in the
plugin-boilerplate
directory type incomposer install
and you are now ready to configure some files. - In the
/plugin-boilerplate/includes
directory, open theclass-{plugin-name}-base.php
file and add the following codes inload_dependencies()
.
/**
* Skelet Config Path
*/
$GLOBALS['skelet_paths'][] = array(
'prefix' => 'pakb',
'dir' => wp_normalize_path( plugin_dir_path( dirname( __FILE__ ) ).'includes/' ),
'uri' => plugin_dir_url( dirname( __FILE__ ) ).'includes/skelet',
);
/**
* Load Skelet Framework
*/
if( ! class_exists( 'Skelet_LoadConfig' ) ){
include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/skelet/skelet.php';
}
Take Note: the prefix name should be unique per plugin
$GLOBALS['skelet_paths'][] = array(
'prefix' => 'your_unique_prefix_name',
....
);
- Create a new folder
options
in theplugin-boilerplate/admin
directory. - In
plugin-boilerplate/admin/options
, create a new fileframework.config.php
and add the following codes:
$settings = array(
'header_title' => 'Plugin BoilerPlate',
'current_version' => '1.0.0',
'menu_title' => 'BoilerPlate',
'menu_type' => 'add_submenu_page',
'menu_slug' => 'pa-boilerplate',
'ajax_save' => false,
);
$options = array();
/**
* a option section for options overview
*/
$options[] = array(
'name' => 'overwiew',
'title' => 'Overview',
'icon' => 'fa fa-star',
// begin: fields
'fields' => array(
// begin: a field
array(
'id' => 'text_1',
'type' => 'text',
'title' => 'Text',
'default' => 'Hello World!'
),
// end: a field
array(
'id' => 'textarea_1',
'type' => 'textarea',
'title' => 'Textarea',
'default' => 'How are you today?',
'help' => 'This option field is useful. You will love it!'
)
)
);
SkeletFramework::instance( $settings, $options );
- Now, let's activate the
plugin-boilerplate
and it should show thePressApps
in the admin side-menu.
- Your plugin is ready to use some cool features of Skelet. Read the Configuration Files.
There are 7 configuration files of Skelet that you can add in plugin-boilerplate/admin/options
directory.
- customize.config.php - Configure custom fields, sections and panels in customizer
- framework.config.php - Configure the option page, sections and fields.
- metabox.config.php - Configure custom fields, sections and panels in post/page.
- shortcode.config.php - Configure shortcodes and fields.
- taxonomy.config.php - Configure taxonomy & tags extra fields.
- template.config.php - Override template and queries.
- widget.config.php - Configure widgets custom fields, sections and display controller.
For supported options fields, read this documentation.
Here's how to pull options values with a plugin prefix name pabp
:
$skelet = new Skelet('pabp');
var_dump($skelet->get());
You can also get a specific option value by adding the name/id of the option field:
$skelet = new Skelet('pabp');
var_dump($skelet->get('text_1'));
Below example, we specify the meta id _custom_page_options
and get the section_1_text
field value.
$skelet = new Skelet('pabp');
// get all options values
var_dump($skelet->get_meta(get_the_ID(),'_custom_page_options'));
// get specific option value
var_dump($skelet->get_meta(get_the_ID(),'_custom_page_options','section_1_text'));
$skelet = new Skelet("pabp");
// get all options values
var_dump(array($skelet->get_customize_option()));
// get specific option value
var_dump(array($skelet->get_customize_option('color_option_with_default')));
```
##### Get taxonomy options values
````PHP
$skelet = new Skelet("pabp");
// get all options values
var_dump($skelet->get_taxonomy('category',50,));
// get specific option value
var_dump($skelet->get_taxonomy('category',50,'section_4_text'));
```
##### Get widget fields values
Skelet widget configuration comes up with controller settings to get fields values.
```PHP
$options[] = array(
'name' => 'skelet_widget_fields_1',
'title' => 'Skelet Widget Fields',
'description' => 'This is a description',
'settings' => array(
// text
array(
'name' => 'text_1',
'default' => 'Skelet widget is awesome',
'control' => array(
'label' => 'Sample Text Field',
'type' => 'text',
),
),
// setup widget controller
"frontend_tpl" => array(
"wrapper" => "<div class=\"item-wrapper\">%s</div>",
"before_item" => "<div>",
"after_item" => "</div>",
"show_label" => array(
"wrapper" => "<div>%s</div>",
"before" => "<label>",
"after" => ":</label> "
),
"walker_class" => array(
"name" => "SkeletWidgetWalker",
"path" => PABP_PLUGIN_DIR."template/widget/walkers/sk-widget-sample-class.php",
)
)
```
Get widget fields values in controller file `sk-widget-sample-class.php`
```PHP
if(!class_exists("SkeletWidgetWalker")){
class SkeletWidgetWalker{
public $widget_option_settings = array();
function __construct($args,$instance){
global $options;
var_dump($instance["text_1"]);
}
}
}
```
### Supported Options fields
------------
* Text
* Textarea
* Checkbox
* Radio
* Select
* Number
* Icons
* Group
* Image
* Upload
* Gallery
* Sorter
* Wysiwyg
* Switcher
* Background
* Color Picker
* Multi Checkbox
* Checkbox Image Select
* Radio Image Select
* Typography
* Backup
* Heading
* Sub Heading
* Fieldset
* Notice
* and extendable fields
### Credits and Links
------------
Skelet is based on awesome [Codestar Framework](http://codestarframework.com/), thank you for the great work.
### Changelog
-----------
* v 1.0.0 - Initial Release