-
Notifications
You must be signed in to change notification settings - Fork 1
Setup
Wireframe Plugin uses the wireframe.php file as a bootstrapper where most of the setup happens. The wireframe.php file is split up into easy-to-read and well-documented sections:
- § 01. Namespaces
- § 02. Access
- § 03. Functions
- § 04. Objects
- § 05. Container
- § 06. Configs
- § 07. Services
- § 08. Wireframe
- § 09. Housekeeping
- § 10. Hooks
| 💡 TIP |
|---|
Wireframe Plugin's wireframe.php file can get large. We recommend using code folding in your IDE or Text Editor, then only work on the blocks you need at any given time. In case you're wondering, we use Sublime Text 3 with Seti_UI. |
Declare your PHP namespaces and any sub-namespace dependencies in all of your class files. In your wireframe.php file, you should also declare any sub-namespace dependencies you need. If you create or extend a class, don't forget to add your namespace dependencies and maybe recompile your autoloader for changes to take effect.
Example of the Wireframe Plugin namespace:
namespace MixaTheme\Wireframe\Plugin;| 💡 TIP |
|---|
| PHP Namespaces requires PHP version 5.3.0 or above. Wireframe Plugin is only compatible with PHP 5.6 or above. PHP 7.x is recommended. |
| 💡 TIP |
|---|
If you need to use another namespace, don't forget to add an alias use MixaTheme\Wireframe\Plugin\<sub-namespace>\<Object> declaration within your files. |
No direct access to this file. Although this is a small line of code, this can get complex, depending on how you wish to perform your access checks. So we decided this deserves it's own section. Also, all files should be pre-screened in one way or another for security purposes.
Example to deny loading a file directly:
defined( 'ABSPATH' ) or die();Some of your files and objects may use helper functions. You need to grab them so they're available throughout your development.
Example of the Wireframe Helpers section:
require_once WIREFRAME_PLUGIN_API . 'functions/functions-helpers.php';
require_once WIREFRAME_PLUGIN_API . 'functions/functions-views.php';You now need to load any class files for your plugin. Use require_once() to load your dependencies 1-by-1. This is the default option because some Developers don't use Composer. You can also load classes via Composer's composer.json file. If you prefer autoloading and add new class files, you must re-compile composer.json`. Autoloading is the preferred option for loading your objects.
Example loading class files manually:
require_once WIREFRAME_PLUGIN_OBJECTS . 'core/core-module-abstract.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'core/core-container-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'core/core-container.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'core/core-enqueue-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'core/core-enqueue.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'core/core-language-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'core/core-language.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'core/core-plugin-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'core/core-plugin.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/notices/module-notices-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/notices/module-notices.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/admin/module-admin-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/admin/module-admin.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/cpt/module-cpt-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/cpt/module-cpt.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/dbtables/module-dbtables-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/dbtables/module-dbtables.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/options/module-options-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/options/module-options.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/settings/module-settings-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/settings/module-settings.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/shortcode/module-shortcode-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/shortcode/module-shortcode.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/taxonomy/module-taxonomy-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/taxonomy/module-taxonomy.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/ui/module-ui-interface.php';
require_once WIREFRAME_PLUGIN_OBJECTS . 'module/ui/module-ui.php';Example loading class files with Autoloading:
require_once WIREFRAME_PLUGIN_DEV . 'vendor/autoload.php';| 💡 TIP |
|---|
How to re-compile your composer.json file for autoloading: composer dump-autoload -o
|
Wireframe Plugin needs to wire objects to the Core_Container $_storage array. You must first declare a variable for your Core_Container object. Then, you can add services later using closure syntax.
Example declaration for your services container:
$wireframe_plugin_container = new Core_Container();Your services objects need data, so you should grab them. You store your data in callable functions which return arrays of data. These functions are individual config files you then pass into your service objects as a parameter.
Example:
require_once trailingslashit( WIREFRAME_PLUGIN_DIR . 'wireframe_cfg' ) . 'cfg-language.php';
require_once trailingslashit( WIREFRAME_PLUGIN_DIR . 'wireframe_cfg' ) . 'cfg-notices.php';
require_once trailingslashit( WIREFRAME_PLUGIN_DIR . 'wireframe_cfg' ) . 'cfg-admin.php';
require_once trailingslashit( WIREFRAME_PLUGIN_DIR . 'wireframe_cfg' ) . 'cfg-dbtables.php';
require_once trailingslashit( WIREFRAME_PLUGIN_DIR . 'wireframe_cfg' ) . 'cfg-cpt.php';
require_once trailingslashit( WIREFRAME_PLUGIN_DIR . 'wireframe_cfg' ) . 'cfg-taxonomy.php';
require_once trailingslashit( WIREFRAME_PLUGIN_DIR . 'wireframe_cfg' ) . 'cfg-shortcode.php';
require_once trailingslashit( WIREFRAME_PLUGIN_DIR . 'wireframe_cfg' ) . 'cfg-options.php';
require_once trailingslashit( WIREFRAME_PLUGIN_DIR . 'wireframe_cfg' ) . 'cfg-settings.php';
require_once trailingslashit( WIREFRAME_PLUGIN_DIR . 'wireframe_cfg' ) . 'cfg-ui.php';Wireframe Plugin "services" are closures you register to be added to the (object) Core_Container $_storage array. The Core_Container holds all your services so you can have access to them later. Your Core_Plugin object uses these services to instantiate your dependency objects, with config data passed in (as a parameter).
Example of a Wireframe Plugin service with config data passed in:
$wireframe_plugin_container->language = function () {
return new Core_Language( wireframe_plugin_cfg_language() );
};What does this code do?
- Registers a language service with the Core_Container.
- Instantiates the Core_Language object.
- Pass-in config data from wireframe_plugin_cfg_language() function.
| 💡 TIP |
|---|
Since PHP 5.3 you can use anonymous functions. Wireframe Plugin is not compatible with PHP 5.2. PHP 7.x is recommended. |
| 💡 TIP |
|---|
Since PHP 5.4 you can use array brackets [ ] but Wireframe Plugin uses array() downstream to better identify arrays or for search & replace situations. |
You can now "wire" all your dependencies together (hence, the name, Wireframe) by instantiating your dependencies into the Core_Plugin object.
Example of multiple Wireframe Plugin services passed into the Core_Plugin object:
$wireframe_plugin = new Core_Plugin(
$wireframe_plugin_container->language,
$wireframe_plugin_container->admin,
$wireframe_plugin_container->notices,
$wireframe_plugin_container->cpt,
$wireframe_plugin_container->taxonomy,
$wireframe_plugin_container->shortcode,
$wireframe_plugin_container->options,
$wireframe_plugin_container->settings,
$wireframe_plugin_container->ui,
$wireframe_plugin_container->dbtables
);What does this code do?
- Instantiates the Core_Plugin object.
- Pass-in services objects as dependencies.
| 💡 TIP |
|---|
| You might habitually add a comma at the end of array arguments, but do not add a trailing comma on the last parameter of an object. |
Check if Wireframe Plugin is properly initialized. You can perform any clean-up tasks here, or simply output a warning if $wireframe_plugin fails. Your files now have access to objects beyond this point.
Example error notice hook if initialization fails:
add_action( 'admin_notices', array( $wireframe_plugin_container->notices, 'error_init' ), 10, 0 );After your objects are initialized, you can target any public object method you need using hooks. You generally do not need to run hooks via the __construct() magic method in your objects, since you can always manually fire hooks like so...
Example of the Wireframe Plugin Hooks section with array callable syntax:
register_deactivation_hook( __FILE__, array( $wireframe_plugin, 'deactivate' ) );| 💡 TIP |
|---|
| After you get the hang of Wireframe Plugin, you'll probably want to condense things. Your custom plugin may or may not need all the docblock comments we provided. You may also wish to put all of your includes into a single file, etc. We feel Wireframe Plugin can be more condensed to save on file size and file count, but we wanted to start you off with a structure we feel helps you the most! |
This Wiki will continue to be updated. Keep checking back!
Copyright © 2016 MixaTheme. All rights reserved. Wireframe Plugin is licensed GPL-2.0.
🐞 Found a Bug, Typo, Error? Help the community by reporting an Issue.
❌ Report a Vulnerability? Please private message us via our Website.
❤️ Thanks for using MIXA products! Follow us? Twitter | Facebook