| 1 |
<?php |
| 2 |
|
| 3 |
function jetpack_require_lib( $slug ) { |
| 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 |
if ( defined( 'ABSPATH' ) && ! defined( 'WP_CONTENT_DIR' ) ) { |
| 11 |
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down |
| 12 |
} |
| 13 |
|
| 14 |
$lib_dir = WP_CONTENT_DIR . '/lib'; |
| 15 |
$lib_dir = apply_filters( 'jetpack_require_lib_dir', $lib_dir ); |
| 16 |
$choices = array( |
| 17 |
"$lib_dir/$slug.php", |
| 18 |
"$lib_dir/$slug/0-load.php", |
| 19 |
"$lib_dir/$slug/$basename.php", |
| 20 |
); |
| 21 |
foreach( $choices as $file_name ) { |
| 22 |
if ( is_readable( $file_name ) ) { |
| 23 |
require_once $file_name; |
| 24 |
return; |
| 25 |
} |
| 26 |
} |
| 27 |
trigger_error( "Cannot find a library with slug $slug.", E_USER_ERROR ); |
| 28 |
} |
| 29 |
|