1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Bootstrap file for the autoloader test suite. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-autoloader |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
if ( ! function_exists( 'trailingslashit' ) ) { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* A drop-in for a WordPress core function. |
12
|
|
|
* |
13
|
|
|
* @param String $string string. |
14
|
|
|
* @return String |
15
|
|
|
*/ |
16
|
|
|
function trailingslashit( $string ) { |
17
|
|
|
return rtrim( $string, '/\\' ) . '/'; |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
if ( ! function_exists( 'wp_unslash' ) ) { |
22
|
|
|
/** |
23
|
|
|
* A drop-in for a WordPress core function. |
24
|
|
|
* |
25
|
|
|
* @param string|string[] $value String or array of strings to unslash. |
26
|
|
|
* @return string|string[] Unslashed $value |
27
|
|
|
*/ |
28
|
|
|
function wp_unslash( $value ) { |
29
|
|
|
return stripslashes_deep( $value ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* A drop-in for a WordPress core function. |
34
|
|
|
* |
35
|
|
|
* @param mixed $value The value to be stripped. |
36
|
|
|
* @return mixed Stripped value. |
37
|
|
|
*/ |
38
|
|
|
function stripslashes_deep( $value ) { |
39
|
|
|
return map_deep( $value, 'stripslashes_from_strings_only' ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* A drop-in for a WordPress core function. |
44
|
|
|
* |
45
|
|
|
* @param mixed $value The array, object, or scalar. |
46
|
|
|
* @param callable $callback The function to map onto $value. |
47
|
|
|
* @return mixed The value with the callback applied to all non-arrays and non-objects inside it. |
48
|
|
|
*/ |
49
|
|
View Code Duplication |
function map_deep( $value, $callback ) { |
|
|
|
|
50
|
|
|
if ( is_array( $value ) ) { |
51
|
|
|
foreach ( $value as $index => $item ) { |
52
|
|
|
$value[ $index ] = map_deep( $item, $callback ); |
53
|
|
|
} |
54
|
|
|
} elseif ( is_object( $value ) ) { |
55
|
|
|
$object_vars = get_object_vars( $value ); |
56
|
|
|
foreach ( $object_vars as $property_name => $property_value ) { |
57
|
|
|
$value->$property_name = map_deep( $property_value, $callback ); |
58
|
|
|
} |
59
|
|
|
} else { |
60
|
|
|
$value = call_user_func( $callback, $value ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $value; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* A drop-in for a WordPress core function. |
68
|
|
|
* |
69
|
|
|
* @param mixed $value The array or string to be stripped. |
70
|
|
|
* @return mixed $value The stripped value. |
71
|
|
|
*/ |
72
|
|
|
function stripslashes_from_strings_only( $value ) { |
73
|
|
|
return is_string( $value ) ? stripslashes( $value ) : $value; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php'; |
78
|
|
|
require_once __DIR__ . '/../../src/functions.php'; |
79
|
|
|
require_once __DIR__ . '/../../src/class-plugins-handler.php'; |
80
|
|
|
require_once __DIR__ . '/../../src/class-classes-handler.php'; |
81
|
|
|
require_once __DIR__ . '/../../src/class-files-handler.php'; |
82
|
|
|
require_once __DIR__ . '/../../src/class-version-selector.php'; |
83
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.