Every theme requires to have one dedicated plugin created. This allows customers who are using our theme to change theme and still have ‘some’ functionality available. Although it won’t look too pretty, all custom post types, basic shortcode structure and hooks will still be available.
Note
Basic structure can be downloaded here: Theme Plugin boilerplate
It is recommended to put most functionality in the plugin as it has higher chances of passing the review. In particular put there:
custom post types settings
shortcodes
widgets
Note
When developing functionality which can be used in other projects, place it in the plugin ( preferably as an extension ) to allow easy copying from project to project.
plugins/ │--themename-plugin/ │--theme-name.php # load bumblebee │--vendor/ │ │--bumblebee/ │ │--bumblebee/ # bumblebee core │ │--unyson/ # unyson core │--extensions/ │--example-extension-name/ │ │--includes/ # additional extension files │ │--views/ # view files │ │ │--view.php │ │--class-fw-extension-example-extension-name.php # ( optional ) shortcode class to handle extension logic │ │--manifest.php # Extension details: title, description, version, dependencies, etc. │ │--hooks.php # Extension specific hooks ( add_filter, add_action ) │ │--helpers.php # Extension functions accessible globally │ │--static.php # Add script and styles │ │-─posts.php # Register post types, taxonomies etc. │ │-─shortcodes/ │ │--example-shortcode-name/ │ │ │--includes/ # additional shortcode files │ │ │--class-fw-shortcode-example-shortcode-name.php # ( optional ) shortcode class to handle shortcode logic │ │ │--config.php # simple options: title, tab, icon, description, custom markup │ │ │--options.php # shortcode options array │ │ │--views/ │ │ │--view.php │ │--... │--...
Note
Theme plugin slug should be themename-plugin
, ie. My Theme plugin slug would be mytheme-plugin
, see Coding Standards for more explanation
Sample project data do fill in the theme plugin would be (for an example My Theme theme):
/**
* Plugin Name: My Plugin
* Plugin URI: http://createit.pl/
* Version: 1.0
* Description: Plugin containing essential functionality required by My Theme.
* Author: createIT
* Author URI: http://createit.pl
*/
When you clone Theme Plugin from repository, there will be composer.json
and composer.lock
files there. In order to get
vendor files, you will need to have composer
installed and run in the main plugin dir:
composer install
ie.:
C:\dimy\disrupt\wp-content\plugins\disrupt-plugin>composer install
This will pull both Bumblebee and Unyson from repositories. Unyson is the framework core with basic functionality. Bumblebee adds additional features to the core.