|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
function require_lib_from_dir( $slug, $lib_dir ) { |
|
4
|
|
|
if ( !preg_match( '|^[a-z0-9/_.-]+$|i', $slug ) ) { |
|
5
|
|
|
trigger_error( "Cannot load a library with invalid slug $slug.", E_USER_ERROR ); |
|
6
|
|
|
return; |
|
7
|
|
|
} |
|
8
|
|
|
$basename = basename( $slug ); |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Filter the location of the library directory. |
|
12
|
|
|
* |
|
13
|
|
|
* @since 2.5.0 |
|
14
|
|
|
* |
|
15
|
|
|
* @param string $lib_dir Path to the library directory. |
|
16
|
|
|
*/ |
|
17
|
|
|
$lib_dir = apply_filters( 'jetpack_require_lib_dir', $lib_dir ); |
|
18
|
|
|
$choices = array( |
|
19
|
|
|
"$lib_dir/$slug.php", |
|
20
|
|
|
"$lib_dir/$slug/0-load.php", |
|
21
|
|
|
"$lib_dir/$slug/$basename.php", |
|
22
|
|
|
); |
|
23
|
|
|
if ( defined( 'JETPACK__PLUGIN_DIR' ) ) { |
|
24
|
|
|
$choices[] = JETPACK__PLUGIN_DIR . '/_inc/lib'; |
|
25
|
|
|
} |
|
26
|
|
|
foreach( $choices as $file_name ) { |
|
27
|
|
|
if ( is_readable( $file_name ) ) { |
|
28
|
|
|
require_once $file_name; |
|
29
|
|
|
return; |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
trigger_error( "Cannot find a library with slug $slug.", E_USER_ERROR ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function jetpack_require_lib( $slug ) { |
|
36
|
|
|
if ( defined( 'ABSPATH' ) && ! defined( 'WP_CONTENT_DIR' ) ) { |
|
37
|
|
|
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
require_lib_from_dir( $slug, WP_CONTENT_DIR . '/lib' ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// Function check so we're able to sync it back to Jetpack, since it seems like a very common function name. |
|
44
|
|
|
if ( ! function_exists( 'require_lib' ) ) { |
|
45
|
|
|
function require_lib( $slug ) { |
|
46
|
|
|
return jetpack_require_lib( $slug ); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|