Completed
Push — update/sync-require-lib ( 3a2f31...26aa15 )
by
unknown
23:32 queued 06:26
created

require-lib.php ➔ require_lib()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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
	foreach( $choices as $file_name ) {
24
		if ( is_readable( $file_name ) ) {
25
			require_once $file_name;
26
			return;
27
		}
28
	}
29
	trigger_error( "Cannot find a library with slug $slug.", E_USER_ERROR );
30
}
31
32
function require_lib( $slug ) {
33
   if ( defined( 'ABSPATH' ) && ! defined( 'WP_CONTENT_DIR' ) ) {
34
       define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down
35
   }
36
37
   require_lib_from_dir( $slug, WP_CONTENT_DIR . '/lib' );
38
}
39
40
function jetpack_require_lib( $slug ) {
41
   require_lib_from_dir( $slug, JETPACK__PLUGIN_DIR . '/_inc/lib' );
42
}
43