|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file `autoload_packages.php`was generated by automattic/jetpack-autoloader. |
|
4
|
|
|
* |
|
5
|
|
|
* From your plugin include this file with: |
|
6
|
|
|
* require_once . plugin_dir_path( __FILE__ ) . '/vendor/autoload_packages.php'; |
|
7
|
|
|
* |
|
8
|
|
|
* @package automattic/jetpack-autoloader |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
// phpcs:disable PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ns_separatorFound |
|
12
|
|
|
// phpcs:disable PHPCompatibility.Keywords.NewKeywords.t_namespaceFound |
|
13
|
|
|
// phpcs:disable PHPCompatibility.Keywords.NewKeywords.t_ns_cFound |
|
14
|
|
|
|
|
15
|
|
|
namespace Automattic\Jetpack\Autoloader; |
|
16
|
|
|
|
|
17
|
|
View Code Duplication |
if ( ! function_exists( __NAMESPACE__ . '\enqueue_package_class' ) ) { |
|
18
|
|
|
global $jetpack_packages_classes; |
|
19
|
|
|
|
|
20
|
|
|
if ( ! is_array( $jetpack_packages_classes ) ) { |
|
21
|
|
|
$jetpack_packages_classes = array(); |
|
22
|
|
|
} |
|
23
|
|
|
/** |
|
24
|
|
|
* Adds the version of a package to the $jetpack_packages global array so that |
|
25
|
|
|
* the autoloader is able to find it. |
|
26
|
|
|
* |
|
27
|
|
|
* @param string $class_name Name of the class that you want to autoload. |
|
28
|
|
|
* @param string $version Version of the class. |
|
29
|
|
|
* @param string $path Absolute path to the class so that we can load it. |
|
30
|
|
|
*/ |
|
31
|
|
|
function enqueue_package_class( $class_name, $version, $path ) { |
|
32
|
|
|
global $jetpack_packages_classes; |
|
33
|
|
|
|
|
34
|
|
|
if ( ! isset( $jetpack_packages_classes[ $class_name ] ) ) { |
|
35
|
|
|
$jetpack_packages_classes[ $class_name ] = array( |
|
36
|
|
|
'version' => $version, |
|
37
|
|
|
'path' => $path, |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
return; |
|
41
|
|
|
} |
|
42
|
|
|
// If we have a @dev version set always use that one! |
|
43
|
|
|
if ( 'dev-' === substr( $jetpack_packages_classes[ $class_name ]['version'], 0, 4 ) ) { |
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
// Always favour the @dev version. Since that version is the same as bleeding edge. |
|
48
|
|
|
// We need to make sure that we don't do this in production! |
|
49
|
|
|
if ( 'dev-' === substr( $version, 0, 4 ) ) { |
|
50
|
|
|
$jetpack_packages_classes[ $class_name ] = array( |
|
51
|
|
|
'version' => $version, |
|
52
|
|
|
'path' => $path, |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
return; |
|
56
|
|
|
} |
|
57
|
|
|
// Set the latest version! |
|
58
|
|
|
if ( version_compare( $jetpack_packages_classes[ $class_name ]['version'], $version, '<' ) ) { |
|
59
|
|
|
$jetpack_packages_classes[ $class_name ] = array( |
|
60
|
|
|
'version' => $version, |
|
61
|
|
|
'path' => $path, |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
View Code Duplication |
if ( ! function_exists( __NAMESPACE__ . '\enqueue_package_file' ) ) { |
|
68
|
|
|
global $jetpack_packages_files; |
|
69
|
|
|
|
|
70
|
|
|
if ( ! is_array( $jetpack_packages_files ) ) { |
|
71
|
|
|
$jetpack_packages_files = array(); |
|
72
|
|
|
} |
|
73
|
|
|
/** |
|
74
|
|
|
* Adds the version of a package file to the $jetpack_packages_files global array so that |
|
75
|
|
|
* we can load the most recent version after 'plugins_loaded'. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $file_identifier Unique id to file assigned by composer based on package name and filename. |
|
78
|
|
|
* @param string $version Version of the file. |
|
79
|
|
|
* @param string $path Absolute path to the file so that we can load it. |
|
80
|
|
|
*/ |
|
81
|
|
|
function enqueue_package_file( $file_identifier, $version, $path ) { |
|
82
|
|
|
global $jetpack_packages_files; |
|
83
|
|
|
|
|
84
|
|
|
if ( ! isset( $jetpack_packages_files[ $file_identifier ] ) ) { |
|
85
|
|
|
$jetpack_packages_files[ $file_identifier ] = array( |
|
86
|
|
|
'version' => $version, |
|
87
|
|
|
'path' => $path, |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
return; |
|
91
|
|
|
} |
|
92
|
|
|
// If we have a @dev version set always use that one! |
|
93
|
|
|
if ( 'dev-' === substr( $jetpack_packages_files[ $file_identifier ]['version'], 0, 4 ) ) { |
|
94
|
|
|
return; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
// Always favour the @dev version. Since that version is the same as bleeding edge. |
|
98
|
|
|
// We need to make sure that we don't do this in production! |
|
99
|
|
|
if ( 'dev-' === substr( $version, 0, 4 ) ) { |
|
100
|
|
|
$jetpack_packages_files[ $file_identifier ] = array( |
|
101
|
|
|
'version' => $version, |
|
102
|
|
|
'path' => $path, |
|
103
|
|
|
); |
|
104
|
|
|
|
|
105
|
|
|
return; |
|
106
|
|
|
} |
|
107
|
|
|
// Set the latest version! |
|
108
|
|
|
if ( version_compare( $jetpack_packages_files[ $file_identifier ]['version'], $version, '<' ) ) { |
|
109
|
|
|
$jetpack_packages_files[ $file_identifier ] = array( |
|
110
|
|
|
'version' => $version, |
|
111
|
|
|
'path' => $path, |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
if ( ! function_exists( __NAMESPACE__ . '\file_loader' ) ) { |
|
118
|
|
|
/** |
|
119
|
|
|
* Include latest version of all enqueued files. Should be called after all plugins are loaded. |
|
120
|
|
|
*/ |
|
121
|
|
|
function file_loader() { |
|
122
|
|
|
global $jetpack_packages_files; |
|
123
|
|
|
foreach ( $jetpack_packages_files as $file_identifier => $file_data ) { |
|
124
|
|
|
if ( empty( $GLOBALS['__composer_autoload_files'][ $file_identifier ] ) ) { |
|
125
|
|
|
require $file_data['path']; |
|
126
|
|
|
|
|
127
|
|
|
$GLOBALS['__composer_autoload_files'][ $file_identifier ] = true; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
if ( ! function_exists( __NAMESPACE__ . '\autoloader' ) ) { |
|
134
|
|
|
/** |
|
135
|
|
|
* Used for autoloading jetpack packages. |
|
136
|
|
|
* |
|
137
|
|
|
* @param string $class_name Class Name to load. |
|
138
|
|
|
*/ |
|
139
|
|
|
function autoloader( $class_name ) { |
|
140
|
|
|
global $jetpack_packages_classes; |
|
141
|
|
|
|
|
142
|
|
|
if ( isset( $jetpack_packages_classes[ $class_name ] ) ) { |
|
143
|
|
|
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
144
|
|
|
if ( function_exists( 'did_action' ) && ! did_action( 'plugins_loaded' ) ) { |
|
145
|
|
|
_doing_it_wrong( |
|
146
|
|
|
esc_html( $class_name ), |
|
147
|
|
|
sprintf( |
|
148
|
|
|
/* translators: %s Name of a PHP Class */ |
|
149
|
|
|
esc_html__( 'Not all plugins have loaded yet but we requested the class %s', 'jetpack' ), |
|
150
|
|
|
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
151
|
|
|
$class_name |
|
152
|
|
|
), |
|
153
|
|
|
esc_html( $jetpack_packages_classes[ $class_name ]['version'] ) |
|
154
|
|
|
); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
if ( file_exists( $jetpack_packages_classes[ $class_name ]['path'] ) ) { |
|
159
|
|
|
require_once $jetpack_packages_classes[ $class_name ]['path']; |
|
160
|
|
|
|
|
161
|
|
|
return true; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
return false; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
// Add the jetpack autoloader. |
|
169
|
|
|
spl_autoload_register( __NAMESPACE__ . '\autoloader' ); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
|