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