forked from scribu/wp-scb-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload.php
86 lines (64 loc) · 1.9 KB
/
load.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
$GLOBALS['_scb_data'] = array( 38, __FILE__, array(
'scbUtil', 'scbOptions', 'scbForms', 'scbTable',
'scbWidget', 'scbAdminPage', 'scbBoxesPage',
'scbCron', 'scbHooks',
) );
if ( !class_exists( 'scbLoad4' ) ) :
class scbLoad4 {
private static $candidates;
private static $classes;
private static $callbacks = array();
private static $loaded;
static function init( $callback = '' ) {
list( $rev, $file, $classes ) = $GLOBALS['_scb_data'];
self::$candidates[$file] = $rev;
self::$classes[$file] = $classes;
if ( !empty( $callback ) ) {
self::$callbacks[$file] = $callback;
add_action( 'activate_plugin', array( __CLASS__, 'delayed_activation' ) );
}
// TODO: don't load when activating a plugin ?
add_action( 'plugins_loaded', array( __CLASS__, 'load' ), 9, 0 );
}
static function delayed_activation( $plugin ) {
$plugin_dir = dirname( $plugin );
if ( '.' == $plugin_dir )
return;
foreach ( self::$callbacks as $file => $callback ) {
if ( dirname( dirname( plugin_basename( $file ) ) ) == $plugin_dir ) {
self::load( false );
call_user_func( $callback );
do_action( 'scb_activation_' . $plugin );
break;
}
}
}
static function load( $do_callbacks = true ) {
arsort( self::$candidates );
$file = key( self::$candidates );
$path = dirname( $file ) . '/';
foreach ( self::$classes[$file] as $class_name ) {
if ( class_exists( $class_name ) )
continue;
$fpath = $path . substr( $class_name, 3 ) . '.php';
if ( file_exists( $fpath ) ) {
include $fpath;
self::$loaded[] = $fpath;
}
}
if ( $do_callbacks )
foreach ( self::$callbacks as $callback )
call_user_func( $callback );
}
static function get_info() {
arsort( self::$candidates );
return array( self::$loaded, self::$candidates );
}
}
endif;
if ( !function_exists( 'scb_init' ) ) :
function scb_init( $callback = '' ) {
scbLoad4::init( $callback );
}
endif;