Skip to content

Instantly share code, notes, and snippets.

@gish
Created March 28, 2013 10:11
Show Gist options
  • Save gish/5262145 to your computer and use it in GitHub Desktop.
Save gish/5262145 to your computer and use it in GitHub Desktop.
Functions file pattern for WordPress
<?php
add_action(
'plugins_loaded',
array( My_Plugin::get_instance(), 'setup' )
);
class My_Plugin
{
/**
* Instance of this class
*
* @see get_instance()
* @type My_Plugin
*/
protected static $instance = null;
/**
* Access to the working instance of this class
*
* @wp-hook init
* @return My_Plugin
*/
public static function get_instance()
{
null === self::$instance and self::$instance = new self;
return self::$instance;
}
/**
* Constructor. Intentionally left empty and public.
*
* @see setup()
*/
public function __construct() {}
/**
* Sets the theme up by adding init actions
* @wp-hook plugins_loaded
*/
public function setup()
{
// Do all initialization, such as adding filters
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment