mirror of
https://github.com/inretio/WordPress-Plugin-Boilerplate
synced 2024-12-22 11:53:53 +02:00
implemented the singleton pattern
This commit is contained in:
parent
11af5e0d11
commit
6d141e700f
1 changed files with 19 additions and 3 deletions
|
@ -29,21 +29,37 @@ License:
|
|||
// TODO: rename this class to a proper name for your plugin
|
||||
class PluginName {
|
||||
|
||||
/*--------------------------------------------*
|
||||
* Attributes
|
||||
*--------------------------------------------*/
|
||||
|
||||
/** Refers to a single instance of this class. */
|
||||
private static $instance;
|
||||
|
||||
/*--------------------------------------------*
|
||||
* Constructor
|
||||
*--------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Creates or returns an instance of this class.
|
||||
*
|
||||
* @return PluginName A single instance of this class.
|
||||
*/
|
||||
public function get_instance() {
|
||||
return null == self::$instance ? new self : self::$instance;
|
||||
} // end get_instance;
|
||||
|
||||
/**
|
||||
* Initializes the plugin by setting localization, filters, and administration functions.
|
||||
*/
|
||||
function __construct() {
|
||||
private function __construct() {
|
||||
|
||||
// Load plugin text domain
|
||||
add_action( 'init', array( $this, 'plugin_textdomain' ) );
|
||||
|
||||
// Add the options page and menu item
|
||||
// Uncomment the following line to enable the Settings Page for the plugin
|
||||
# add_action('admin_menu', array( $this, 'plugin_admin_menu' ) );
|
||||
# add_action('admin_menu', array( $this, 'plugin_admin_menu' ) );
|
||||
|
||||
// Register admin styles and scripts
|
||||
// If the Settings page has been activated (above), the scripts and styles
|
||||
|
@ -232,4 +248,4 @@ class PluginName {
|
|||
} // end class
|
||||
|
||||
// TODO: Update the instantiation call of your plugin to the name given at the class definition
|
||||
$plugin_name = new PluginName();
|
||||
PluginName::get_instance();
|
||||
|
|
Loading…
Reference in a new issue