Class AdminPageFramework_PluginBootstrap
Provides an abstract base to create a bootstrap class for Wordpress plugins.
Usage
Extend the class and insert your own plugin routine in thesetUp()
method. If you have classes you want them to be auto-loaded, override the
getClasses()
method and return an array holding a list of class
files. The array should consist of keys of class names and the values of class
file paths. By overriding the replyToPluginActivation()
method, you
can write a handing routine for when the plugin gets activated. To set
localization files, override the setLocalization()
method and
insert your code in the method to set up translation files.
There are other methods you can override. All the public methods are meant to be overridden. Check out the public methods below.
Example
final class AdminPageFrameworkLoader_Bootstrap extends AdminPageFramework_PluginBootstrap { // Register classes to be auto-loaded. public function getClasses() { return include( dirname( $this->sFilePath ) . '/include/loader-class-map.php' ); } // The plugin activation callback method. public function replyToPluginActivation() { // Do plugin requirement checks and deactivate the plugin if necessary. $_oRequirementCheck = new AdminPageFramework_Requirement( AdminPageFrameworkLoader_Registry::$aRequirements, AdminPageFrameworkLoader_Registry::NAME ); if ( $_oRequirementCheck->check() ) { $_oRequirementCheck->deactivatePlugin( $this->sFilePath, __( 'Deactivating the plugin', 'admin-page-framework-loader' ), // additional message true // is in the activation hook. This will exit the script. ); } } // Set localization public function setLocalization() { // This plugin does not have messages to be displayed in the front end. if ( ! $this->bIsAdmin ) { return; } $_sPluginBaseNameDirName = dirname( plugin_basename( $this->sFilePath ) ); load_plugin_textdomain( AdminPageFrameworkLoader_Registry::TEXT_DOMAIN, false, $_sPluginBaseNameDirName . '/' . AdminPageFrameworkLoader_Registry::TEXT_DOMAIN_PATH ); load_plugin_textdomain( 'admin-page-framework', false, $_sPluginBaseNameDirName . '/' . AdminPageFrameworkLoader_Registry::TEXT_DOMAIN_PATH ); } public function setUp() { // Do the plugin task } } new AdminPageFrameworkLoader_Bootstrap( PLUGIN_MAIN_FILE_PATH );
Package: AdminPageFramework\Utility
Since: 3.5.0
Action: do {hook prefix}_action_before_loading_plugin
Action: do {hook prefix}_action_after_loading_plugin
Located at utility/plugin_bootstrap/AdminPageFramework_PluginBootstrap.php
Methods summary
public
|
#
__construct( string $sPluginFilePath, string $sPluginHookPrefix = '', string $sSetUpHook = 'plugins_loaded', integer|float $iPriority = 10 )
Sets up properties and hooks. Parameters
|
protected
|
|
public
|
|
public
|
|
public
array
|
#
getClasses( )
Returns an array holding class names in the key and the file path to the value. The returned array will be passed to the autoloader class. Returnsarray An array holding PHP classes. The array must consist of keys of class names and values of the class file paths. Since
3.5.0
|
public
array
|
#
getScanningDirs( )
Returns an array holding scanning directory paths. Returnsarray An array holding directory paths. Since
3.5.0
|
public
|
|
public
|
|
public
|
|
public
|
#
setUp( )
Loads plugin components. Use this method to load the main plugin components such as post type, admin pages, event routines etc as this method is triggered with the 'plugins_loaded' hook which is triggered after all the plugins are loaded. On the other hand, for extension plugins, use the construct() method below and hook into the "{$this->sHookPrefix}_action_after_loading_plugin" action hook. This way, the extension plugin can load their components after the main plugin components get loaded. Since
3.5.0
|
protected
|
#
construct( )
The protected user constructor method which is automatically called when the class is instantiated. For extension plugins, use this method to hook into the "{$this->sHookPrefix}_action_after_loading_plugin" action hook. Since
3.5.0
|
public
|boolean
|
#
start( )
The public user constructor method. Returns|boolean Return false to stop loading components. Since
3.5.0
|