-
Notifications
You must be signed in to change notification settings - Fork 51
/
Plugin.php
59 lines (44 loc) · 1.64 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
*
* Plugin API
*
*/
class csscrush_plugin {
// The required prefix to all plugin function names
static public $prefix = 'csscrush__';
// The current loaded plugins
static protected $associated_hooks = array();
// Externally associate a hook with the plugin
static public function registerHook ( $plugin_name, $hook ) {
self::$associated_hooks[ $plugin_name ] = $hook;
}
static public function enable ( $plugin_name ) {
$plugin_function = self::$prefix . $plugin_name;
// Require the plugin file if it hasn't been already
if ( ! function_exists( $plugin_function ) ) {
$path = csscrush::$config->location . "/plugins/$plugin_name.php";
if ( ! file_exists( $path ) ) {
trigger_error( __METHOD__ .
": <b>$plugin_name</b> plugin not found.\n", E_USER_NOTICE );
return false;
}
require_once $path;
}
// If the plugin is associated with a hook, we make sure it is hooked
if ( isset( self::$associated_hooks[ $plugin_name ] ) ) {
csscrush_hook::add(
self::$associated_hooks[ $plugin_name ],
$plugin_function );
}
return true;
}
static public function disable ( $plugin_name ) {
// If the plugin is associated with a hook, we 'un-hook' it
if ( isset( self::$associated_hooks[ $plugin_name ] ) ) {
csscrush_hook::remove(
self::$associated_hooks[ $plugin_name ],
self::$prefix . str_replace( '-', '_', $plugin_name ) );
}
}
}