Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
CRAP | n/a |
0 / 0 |
|
| require_lib | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Implementation of wpcom's `require_lib()` function. |
| 4 | * |
| 5 | * @package wpcomsh |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Require library helper function |
| 10 | * |
| 11 | * @param mixed $slug Slug of library. |
| 12 | * @return void |
| 13 | */ |
| 14 | function require_lib( $slug ) { |
| 15 | if ( ! preg_match( '|^[a-z0-9/_.-]+$|i', $slug ) ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | $basename = basename( $slug ); |
| 20 | |
| 21 | $lib_dir = __DIR__; |
| 22 | |
| 23 | /** |
| 24 | * Filter the location of the library directory. |
| 25 | * |
| 26 | * @since 2.5.0 |
| 27 | * |
| 28 | * @param string $lib_dir Path to the library directory. |
| 29 | */ |
| 30 | $lib_dir = apply_filters( 'require_lib_dir', $lib_dir ); |
| 31 | |
| 32 | $choices = array( |
| 33 | "$lib_dir/$slug.php", |
| 34 | "$lib_dir/$slug/0-load.php", |
| 35 | "$lib_dir/$slug/$basename.php", |
| 36 | ); |
| 37 | foreach ( $choices as $file_name ) { |
| 38 | if ( is_readable( $file_name ) ) { |
| 39 | require_once $file_name; |
| 40 | return; |
| 41 | } |
| 42 | } |
| 43 | } |