Created
July 23, 2013 07:51
-
-
Save tddewey/6060592 to your computer and use it in GitHub Desktop.
Singleton template I'm currently using to namespace stuff.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class My_Singleton { | |
/** | |
* The only instance of the My_Singleton Object | |
* @var My_Singleton | |
*/ | |
private static $instance; | |
/** | |
* Returns the main instance. | |
* | |
* @return My_Singleton | |
*/ | |
public static function get_instance() { | |
if ( ! isset( self::$instance ) ) { | |
self::$instance = new My_Singleton; | |
self::$instance->setup_actions(); | |
} | |
return self::$instance; | |
} | |
/** | |
* A dummy constructor. | |
* | |
* @return My_Singleton | |
*/ | |
private function __construct() { | |
} | |
/** | |
* Set up WordPress hooks | |
*/ | |
function setup_actions() { | |
} | |
} | |
/** | |
* Gets the main My_Singleton Instance | |
* | |
* Calling this function places into motion the main functions of the class, but can also be utilized to get properties | |
* and run methods of the class. | |
* | |
* @return My_Singleton | |
*/ | |
function get_my_singleton() { | |
return My_Singleton::get_instance(); | |
} | |
add_action( 'init', 'get_my_singleton' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment