forked from scribu/wp-scb-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.php
105 lines (83 loc) · 2.22 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
$GLOBALS['_scb_data'] = array( 61, __FILE__, array(
'scbUtil',
'scbOptions',
'scbForms',
'scbTable',
'scbWidget',
'scbAdminPage',
'scbBoxesPage',
'scbPostMetabox',
'scbCron',
'scbHooks',
) );
if ( ! class_exists( 'scbLoad4' ) ) :
/**
* The main idea behind this class is to load the most recent version of the scb classes available.
*
* It waits until all plugins are loaded and then does some crazy hacks to make activation hooks work.
*/
class scbLoad4 {
private static $candidates = array();
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' ) );
}
if ( did_action( 'plugins_loaded' ) ) {
self::load();
} else {
add_action( 'plugins_loaded', array( __CLASS__, 'load' ), 9, 0 );
}
}
public 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;
}
}
}
public 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;