Created
August 2, 2012 23:08
-
-
Save RalfAlbert/3241729 to your computer and use it in GitHub Desktop.
Plugin Grundgeruest
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
<?php | |
/*** MOCKING ***/ | |
function did_action( $hook ){ | |
static $calls = 0; | |
return $calls++; | |
} | |
function add_action(){}; | |
function register_activation_hook(){} | |
function register_deactivation_hook(){} | |
function register_uninstall_hook(){} | |
/*** MOCKING ENDE ***/ | |
class TestPlugin | |
{ | |
/** | |
* | |
* Constructor | |
*/ | |
private function __construct(){ | |
echo 'Plugin started<br>'; | |
} | |
/** | |
* | |
* Registering the plugin on plugins_loaded and starting the plugin on WordPress startup | |
* @internal hooked by plugins_loaded | |
*/ | |
public static function init_plugin(){ | |
switch( did_action( 'plugins_loaded' ) ){ | |
case 0: | |
add_action( | |
'plugins_loaded', | |
array( __CLASS__, 'init_plugin' ) | |
); | |
return TRUE; | |
break; | |
case 1: | |
return new self(); | |
break; | |
default: | |
return NULL; | |
break; | |
} | |
return; | |
} | |
/** | |
* | |
* Register the activation-, deactivation- and uninstall-hook | |
*/ | |
public static function init_plugin_install( $abspath = __FILE__ ){ | |
/* | |
if( ! class_exists( 'Plugin_Installer' ) ) | |
require_once 'classes/class-plugin_installer.php'; | |
// alternativ mit spl_autoloader | |
*/ | |
register_activation_hook( $abspath, array( 'Plugin_Installer', 'activate' ) ); | |
register_deactivation_hook( $abspath, array( 'Plugin_Installer', 'deactivate' ) ); | |
register_uninstall_hook( $abspath, array( 'Plugin_Installer', 'uninstall' ) ); | |
} | |
} | |
TestPlugin::init_plugin_install( __FILE__ ); | |
$a = array(); | |
$a[] = TestPlugin::init_plugin(); | |
$a[] = TestPlugin::init_plugin(); | |
$a[] = TestPlugin::init_plugin(); | |
$a[] = TestPlugin::init_plugin(); | |
var_dump( $a ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment