| 1 |
<?php |
| 2 |
function jetpack_require_lib( $slug ) { |
| 3 |
if ( !preg_match( '|^[a-z0-9/_.-]+$|i', $slug ) ) { |
| 4 |
trigger_error( "Cannot load a library with invalid slug $slug.", E_USER_ERROR ); |
| 5 |
return; |
| 6 |
} |
| 7 |
$basename = basename( $slug ); |
| 8 |
|
| 9 |
if ( defined( 'ABSPATH' ) && ! defined( 'WP_CONTENT_DIR' ) ) { |
| 10 |
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down |
| 11 |
} |
| 12 |
|
| 13 |
$lib_dir = WP_CONTENT_DIR . '/lib'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Filter the location of the library directory. |
| 17 |
* |
| 18 |
* @since 2.5.0 |
| 19 |
* |
| 20 |
* @param string $lib_dir Path to the library directory. |
| 21 |
*/ |
| 22 |
$lib_dir = apply_filters( 'jetpack_require_lib_dir', $lib_dir ); |
| 23 |
$choices = array( |
| 24 |
JETPACK__PLUGIN_DIR . "vendor/automattic/jetpack-compat/lib/$slug.php", |
| 25 |
"$lib_dir/$slug.php", |
| 26 |
"$lib_dir/$slug/0-load.php", |
| 27 |
"$lib_dir/$slug/$basename.php", |
| 28 |
); |
| 29 |
foreach( $choices as $file_name ) { |
| 30 |
if ( is_readable( $file_name ) ) { |
| 31 |
require_once $file_name; |
| 32 |
return; |
| 33 |
} |
| 34 |
} |
| 35 |
trigger_error( "Cannot find a library with slug $slug.", E_USER_ERROR ); |
| 36 |
} |
| 37 |
|