author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* These functions are needed to load WordPress. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
9 |
* Return the HTTP protocol sent by the server. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* @return string The HTTP protocol. Default: HTTP/1.0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
function wp_get_server_protocol() { |
16 | 16 |
$protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : ''; |
17 |
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ), true ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
$protocol = 'HTTP/1.0'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
return $protocol; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
/** |
5 | 24 |
* Fix `$_SERVER` variables for various setups. |
0 | 25 |
* |
5 | 26 |
* @since 3.0.0 |
0 | 27 |
* @access private |
5 | 28 |
* |
29 |
* @global string $PHP_SELF The filename of the currently executing script, |
|
30 |
* relative to the document root. |
|
0 | 31 |
*/ |
32 |
function wp_fix_server_vars() { |
|
33 |
global $PHP_SELF; |
|
34 |
||
35 |
$default_server_values = array( |
|
36 |
'SERVER_SOFTWARE' => '', |
|
9 | 37 |
'REQUEST_URI' => '', |
0 | 38 |
); |
39 |
||
40 |
$_SERVER = array_merge( $default_server_values, $_SERVER ); |
|
41 |
||
16 | 42 |
// Fix for IIS when running with PHP ISAPI. |
43 |
if ( empty( $_SERVER['REQUEST_URI'] ) || ( 'cgi-fcgi' !== PHP_SAPI && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) { |
|
0 | 44 |
|
45 |
if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) { |
|
16 | 46 |
// IIS Mod-Rewrite. |
0 | 47 |
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; |
9 | 48 |
} elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) { |
16 | 49 |
// IIS Isapi_Rewrite. |
0 | 50 |
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; |
51 |
} else { |
|
16 | 52 |
// Use ORIG_PATH_INFO if there is no PATH_INFO. |
9 | 53 |
if ( ! isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) ) { |
0 | 54 |
$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; |
9 | 55 |
} |
0 | 56 |
|
16 | 57 |
// Some IIS + PHP configurations put the script-name in the path-info (no need to append it twice). |
0 | 58 |
if ( isset( $_SERVER['PATH_INFO'] ) ) { |
9 | 59 |
if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) { |
0 | 60 |
$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']; |
9 | 61 |
} else { |
0 | 62 |
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']; |
9 | 63 |
} |
0 | 64 |
} |
65 |
||
16 | 66 |
// Append the query string if it exists and isn't null. |
0 | 67 |
if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { |
68 |
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
69 |
} |
|
70 |
} |
|
71 |
} |
|
72 |
||
16 | 73 |
// Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests. |
9 | 74 |
if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) ) { |
0 | 75 |
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED']; |
9 | 76 |
} |
0 | 77 |
|
16 | 78 |
// Fix for Dreamhost and other PHP as CGI hosts. |
9 | 79 |
if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) { |
0 | 80 |
unset( $_SERVER['PATH_INFO'] ); |
9 | 81 |
} |
0 | 82 |
|
16 | 83 |
// Fix empty PHP_SELF. |
0 | 84 |
$PHP_SELF = $_SERVER['PHP_SELF']; |
9 | 85 |
if ( empty( $PHP_SELF ) ) { |
16 | 86 |
$_SERVER['PHP_SELF'] = preg_replace( '/(\?.*)?$/', '', $_SERVER['REQUEST_URI'] ); |
87 |
$PHP_SELF = $_SERVER['PHP_SELF']; |
|
9 | 88 |
} |
0 | 89 |
} |
90 |
||
91 |
/** |
|
5 | 92 |
* Check for the required PHP version, and the MySQL extension or |
93 |
* a database drop-in. |
|
0 | 94 |
* |
95 |
* Dies if requirements are not met. |
|
96 |
* |
|
5 | 97 |
* @since 3.0.0 |
0 | 98 |
* @access private |
5 | 99 |
* |
100 |
* @global string $required_php_version The required PHP version string. |
|
101 |
* @global string $wp_version The WordPress version string. |
|
0 | 102 |
*/ |
103 |
function wp_check_php_mysql_versions() { |
|
104 |
global $required_php_version, $wp_version; |
|
105 |
$php_version = phpversion(); |
|
5 | 106 |
|
0 | 107 |
if ( version_compare( $required_php_version, $php_version, '>' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
$protocol = wp_get_server_protocol(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); |
5 | 110 |
header( 'Content-Type: text/html; charset=utf-8' ); |
16 | 111 |
printf( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.', $php_version, $wp_version, $required_php_version ); |
9 | 112 |
exit( 1 ); |
0 | 113 |
} |
114 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) { |
16 | 116 |
require_once ABSPATH . WPINC . '/functions.php'; |
0 | 117 |
wp_load_translations_early(); |
9 | 118 |
$args = array( |
119 |
'exit' => false, |
|
120 |
'code' => 'mysql_not_found', |
|
121 |
); |
|
122 |
wp_die( |
|
123 |
__( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ), |
|
16 | 124 |
__( 'Requirements Not Met' ), |
9 | 125 |
$args |
126 |
); |
|
127 |
exit( 1 ); |
|
0 | 128 |
} |
129 |
} |
|
130 |
||
131 |
/** |
|
16 | 132 |
* Retrieves the current environment type. |
133 |
* |
|
134 |
* The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable, |
|
135 |
* or a constant of the same name. |
|
136 |
* |
|
137 |
* Possible values include 'local', 'development', 'staging', 'production'. |
|
138 |
* If not set, the type defaults to 'production'. |
|
139 |
* |
|
140 |
* @since 5.5.0 |
|
141 |
* @since 5.5.1 Added the 'local' type. |
|
142 |
* @since 5.5.1 Removed the ability to alter the list of types. |
|
143 |
* |
|
144 |
* @return string The current environment type. |
|
145 |
*/ |
|
146 |
function wp_get_environment_type() { |
|
147 |
static $current_env = ''; |
|
148 |
||
149 |
if ( $current_env ) { |
|
150 |
return $current_env; |
|
151 |
} |
|
152 |
||
153 |
$wp_environments = array( |
|
154 |
'local', |
|
155 |
'development', |
|
156 |
'staging', |
|
157 |
'production', |
|
158 |
); |
|
159 |
||
160 |
// Add a note about the deprecated WP_ENVIRONMENT_TYPES constant. |
|
161 |
if ( defined( 'WP_ENVIRONMENT_TYPES' ) && function_exists( '_deprecated_argument' ) ) { |
|
162 |
if ( function_exists( '__' ) ) { |
|
163 |
/* translators: %s: WP_ENVIRONMENT_TYPES */ |
|
164 |
$message = sprintf( __( 'The %s constant is no longer supported.' ), 'WP_ENVIRONMENT_TYPES' ); |
|
165 |
} else { |
|
166 |
$message = sprintf( 'The %s constant is no longer supported.', 'WP_ENVIRONMENT_TYPES' ); |
|
167 |
} |
|
168 |
||
169 |
_deprecated_argument( |
|
170 |
'define()', |
|
171 |
'5.5.1', |
|
172 |
$message |
|
173 |
); |
|
174 |
} |
|
175 |
||
176 |
// Check if the environment variable has been set, if `getenv` is available on the system. |
|
177 |
if ( function_exists( 'getenv' ) ) { |
|
178 |
$has_env = getenv( 'WP_ENVIRONMENT_TYPE' ); |
|
179 |
if ( false !== $has_env ) { |
|
180 |
$current_env = $has_env; |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
// Fetch the environment from a constant, this overrides the global system variable. |
|
185 |
if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) { |
|
186 |
$current_env = WP_ENVIRONMENT_TYPE; |
|
187 |
} |
|
188 |
||
189 |
// Make sure the environment is an allowed one, and not accidentally set to an invalid value. |
|
190 |
if ( ! in_array( $current_env, $wp_environments, true ) ) { |
|
191 |
$current_env = 'production'; |
|
192 |
} |
|
193 |
||
194 |
return $current_env; |
|
195 |
} |
|
196 |
||
197 |
/** |
|
0 | 198 |
* Don't load all of WordPress when handling a favicon.ico request. |
5 | 199 |
* |
0 | 200 |
* Instead, send the headers for a zero-length favicon and bail. |
201 |
* |
|
202 |
* @since 3.0.0 |
|
16 | 203 |
* @deprecated 5.4.0 Deprecated in favor of do_favicon(). |
0 | 204 |
*/ |
205 |
function wp_favicon_request() { |
|
16 | 206 |
if ( '/favicon.ico' === $_SERVER['REQUEST_URI'] ) { |
9 | 207 |
header( 'Content-Type: image/vnd.microsoft.icon' ); |
0 | 208 |
exit; |
209 |
} |
|
210 |
} |
|
211 |
||
212 |
/** |
|
5 | 213 |
* Die with a maintenance message when conditions are met. |
0 | 214 |
* |
215 |
* The default message can be replaced by using a drop-in (maintenance.php in |
|
216 |
* the wp-content directory). |
|
217 |
* |
|
5 | 218 |
* @since 3.0.0 |
0 | 219 |
* @access private |
220 |
*/ |
|
221 |
function wp_maintenance() { |
|
16 | 222 |
// Return if maintenance mode is disabled. |
223 |
if ( ! wp_is_maintenance_mode() ) { |
|
0 | 224 |
return; |
9 | 225 |
} |
0 | 226 |
|
16 | 227 |
if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { |
228 |
require_once WP_CONTENT_DIR . '/maintenance.php'; |
|
229 |
die(); |
|
230 |
} |
|
231 |
||
232 |
require_once ABSPATH . WPINC . '/functions.php'; |
|
233 |
wp_load_translations_early(); |
|
234 |
||
235 |
header( 'Retry-After: 600' ); |
|
236 |
||
237 |
wp_die( |
|
238 |
__( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ), |
|
239 |
__( 'Maintenance' ), |
|
240 |
503 |
|
241 |
); |
|
242 |
} |
|
243 |
||
244 |
/** |
|
245 |
* Check if maintenance mode is enabled. |
|
246 |
* |
|
247 |
* Checks for a file in the WordPress root directory named ".maintenance". |
|
248 |
* This file will contain the variable $upgrading, set to the time the file |
|
249 |
* was created. If the file was created less than 10 minutes ago, WordPress |
|
250 |
* is in maintenance mode. |
|
251 |
* |
|
252 |
* @since 5.5.0 |
|
253 |
* |
|
254 |
* @global int $upgrading The Unix timestamp marking when upgrading WordPress began. |
|
255 |
* |
|
256 |
* @return bool True if maintenance mode is enabled, false otherwise. |
|
257 |
*/ |
|
258 |
function wp_is_maintenance_mode() { |
|
0 | 259 |
global $upgrading; |
260 |
||
16 | 261 |
if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) { |
262 |
return false; |
|
263 |
} |
|
264 |
||
265 |
require ABSPATH . '.maintenance'; |
|
266 |
// If the $upgrading timestamp is older than 10 minutes, consider maintenance over. |
|
267 |
if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) { |
|
268 |
return false; |
|
9 | 269 |
} |
0 | 270 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
* Filters whether to enable maintenance mode. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
* This filter runs before it can be used by plugins. It is designed for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
* non-web runtimes. If this filter returns true, maintenance mode will be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
* active and the request will end. If false, the request will be allowed to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
* continue processing even if maintenance mode should be active. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
* @param bool $enable_checks Whether to enable maintenance mode. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
* @param int $upgrading The timestamp set in the .maintenance file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) { |
16 | 285 |
return false; |
0 | 286 |
} |
287 |
||
16 | 288 |
return true; |
0 | 289 |
} |
290 |
||
291 |
/** |
|
5 | 292 |
* Start the WordPress micro-timer. |
0 | 293 |
* |
5 | 294 |
* @since 0.71 |
0 | 295 |
* @access private |
5 | 296 |
* |
297 |
* @global float $timestart Unix timestamp set at the beginning of the page load. |
|
298 |
* @see timer_stop() |
|
299 |
* |
|
0 | 300 |
* @return bool Always returns true. |
301 |
*/ |
|
302 |
function timer_start() { |
|
303 |
global $timestart; |
|
304 |
$timestart = microtime( true ); |
|
305 |
return true; |
|
306 |
} |
|
307 |
||
308 |
/** |
|
5 | 309 |
* Retrieve or display the time from the page start to when function is called. |
0 | 310 |
* |
311 |
* @since 0.71 |
|
5 | 312 |
* |
313 |
* @global float $timestart Seconds from when timer_start() is called. |
|
314 |
* @global float $timeend Seconds from when function is called. |
|
0 | 315 |
* |
5 | 316 |
* @param int|bool $display Whether to echo or return the results. Accepts 0|false for return, |
317 |
* 1|true for echo. Default 0|false. |
|
318 |
* @param int $precision The number of digits from the right of the decimal to display. |
|
319 |
* Default 3. |
|
320 |
* @return string The "second.microsecond" finished time calculation. The number is formatted |
|
321 |
* for human consumption, both localized and rounded. |
|
0 | 322 |
*/ |
5 | 323 |
function timer_stop( $display = 0, $precision = 3 ) { |
0 | 324 |
global $timestart, $timeend; |
9 | 325 |
$timeend = microtime( true ); |
0 | 326 |
$timetotal = $timeend - $timestart; |
9 | 327 |
$r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision ); |
328 |
if ( $display ) { |
|
0 | 329 |
echo $r; |
9 | 330 |
} |
0 | 331 |
return $r; |
332 |
} |
|
333 |
||
334 |
/** |
|
5 | 335 |
* Set PHP error reporting based on WordPress debug settings. |
336 |
* |
|
337 |
* Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
* All three can be defined in wp-config.php. By default, `WP_DEBUG` and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
* `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true. |
0 | 340 |
* |
5 | 341 |
* When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also |
342 |
* display internal notices: when a deprecated WordPress function, function |
|
343 |
* argument, or file is used. Deprecated code may be removed from a later |
|
344 |
* version. |
|
0 | 345 |
* |
5 | 346 |
* It is strongly recommended that plugin and theme developers use `WP_DEBUG` |
347 |
* in their development environments. |
|
0 | 348 |
* |
5 | 349 |
* `WP_DEBUG_DISPLAY` and `WP_DEBUG_LOG` perform no function unless `WP_DEBUG` |
350 |
* is true. |
|
0 | 351 |
* |
5 | 352 |
* When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed. |
353 |
* `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress |
|
354 |
* from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY` |
|
355 |
* as false will force errors to be hidden. |
|
0 | 356 |
* |
9 | 357 |
* When `WP_DEBUG_LOG` is true, errors will be logged to `wp-content/debug.log`. |
358 |
* When `WP_DEBUG_LOG` is a valid path, errors will be logged to the specified file. |
|
0 | 359 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
* Errors are never displayed for XML-RPC, REST, and Ajax requests. |
0 | 361 |
* |
5 | 362 |
* @since 3.0.0 |
9 | 363 |
* @since 5.1.0 `WP_DEBUG_LOG` can be a file path. |
0 | 364 |
* @access private |
365 |
*/ |
|
366 |
function wp_debug_mode() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
* Filters whether to allow the debug mode check to occur. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
* This filter runs before it can be used by plugins. It is designed for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
* non-web run-times. Returning false causes the `WP_DEBUG` and related |
16 | 372 |
* constants to not be checked and the default PHP values for errors |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* will be used unless you take care to update them yourself. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
* @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
*/ |
9 | 379 |
if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
|
0 | 383 |
if ( WP_DEBUG ) { |
384 |
error_reporting( E_ALL ); |
|
385 |
||
9 | 386 |
if ( WP_DEBUG_DISPLAY ) { |
0 | 387 |
ini_set( 'display_errors', 1 ); |
9 | 388 |
} elseif ( null !== WP_DEBUG_DISPLAY ) { |
0 | 389 |
ini_set( 'display_errors', 0 ); |
9 | 390 |
} |
0 | 391 |
|
9 | 392 |
if ( in_array( strtolower( (string) WP_DEBUG_LOG ), array( 'true', '1' ), true ) ) { |
393 |
$log_path = WP_CONTENT_DIR . '/debug.log'; |
|
394 |
} elseif ( is_string( WP_DEBUG_LOG ) ) { |
|
395 |
$log_path = WP_DEBUG_LOG; |
|
396 |
} else { |
|
397 |
$log_path = false; |
|
398 |
} |
|
399 |
||
400 |
if ( $log_path ) { |
|
0 | 401 |
ini_set( 'log_errors', 1 ); |
9 | 402 |
ini_set( 'error_log', $log_path ); |
0 | 403 |
} |
404 |
} else { |
|
405 |
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR ); |
|
406 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
|
9 | 408 |
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) { |
16 | 409 |
ini_set( 'display_errors', 0 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
} |
0 | 411 |
} |
412 |
||
413 |
/** |
|
5 | 414 |
* Set the location of the language directory. |
0 | 415 |
* |
5 | 416 |
* To set directory manually, define the `WP_LANG_DIR` constant |
417 |
* in wp-config.php. |
|
0 | 418 |
* |
5 | 419 |
* If the language directory exists within `WP_CONTENT_DIR`, it |
420 |
* is used. Otherwise the language directory is assumed to live |
|
421 |
* in `WPINC`. |
|
0 | 422 |
* |
5 | 423 |
* @since 3.0.0 |
0 | 424 |
* @access private |
425 |
*/ |
|
426 |
function wp_set_lang_dir() { |
|
9 | 427 |
if ( ! defined( 'WP_LANG_DIR' ) ) { |
428 |
if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || ! @is_dir( ABSPATH . WPINC . '/languages' ) ) { |
|
5 | 429 |
/** |
430 |
* Server path of the language directory. |
|
431 |
* |
|
432 |
* No leading slash, no trailing slash, full path, not relative to ABSPATH |
|
433 |
* |
|
434 |
* @since 2.1.0 |
|
435 |
*/ |
|
436 |
define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); |
|
9 | 437 |
if ( ! defined( 'LANGDIR' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
// Old static relative path maintained for limited backward compatibility - won't work in some cases. |
0 | 439 |
define( 'LANGDIR', 'wp-content/languages' ); |
440 |
} |
|
441 |
} else { |
|
5 | 442 |
/** |
443 |
* Server path of the language directory. |
|
444 |
* |
|
445 |
* No leading slash, no trailing slash, full path, not relative to `ABSPATH`. |
|
446 |
* |
|
447 |
* @since 2.1.0 |
|
448 |
*/ |
|
449 |
define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); |
|
9 | 450 |
if ( ! defined( 'LANGDIR' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
// Old relative path maintained for backward compatibility. |
0 | 452 |
define( 'LANGDIR', WPINC . '/languages' ); |
453 |
} |
|
454 |
} |
|
455 |
} |
|
456 |
} |
|
457 |
||
458 |
/** |
|
5 | 459 |
* Load the database class file and instantiate the `$wpdb` global. |
0 | 460 |
* |
461 |
* @since 2.5.0 |
|
5 | 462 |
* |
16 | 463 |
* @global wpdb $wpdb WordPress database abstraction object. |
0 | 464 |
*/ |
465 |
function require_wp_db() { |
|
466 |
global $wpdb; |
|
467 |
||
16 | 468 |
require_once ABSPATH . WPINC . '/wp-db.php'; |
9 | 469 |
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) { |
16 | 470 |
require_once WP_CONTENT_DIR . '/db.php'; |
9 | 471 |
} |
0 | 472 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
if ( isset( $wpdb ) ) { |
0 | 474 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
} |
0 | 476 |
|
9 | 477 |
$dbuser = defined( 'DB_USER' ) ? DB_USER : ''; |
478 |
$dbpassword = defined( 'DB_PASSWORD' ) ? DB_PASSWORD : ''; |
|
479 |
$dbname = defined( 'DB_NAME' ) ? DB_NAME : ''; |
|
480 |
$dbhost = defined( 'DB_HOST' ) ? DB_HOST : ''; |
|
481 |
||
482 |
$wpdb = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost ); |
|
0 | 483 |
} |
484 |
||
485 |
/** |
|
5 | 486 |
* Set the database table prefix and the format specifiers for database |
487 |
* table columns. |
|
0 | 488 |
* |
5 | 489 |
* Columns not listed here default to `%s`. |
0 | 490 |
* |
5 | 491 |
* @since 3.0.0 |
492 |
* @access private |
|
0 | 493 |
* |
16 | 494 |
* @global wpdb $wpdb WordPress database abstraction object. |
5 | 495 |
* @global string $table_prefix The database table prefix. |
0 | 496 |
*/ |
497 |
function wp_set_wpdb_vars() { |
|
498 |
global $wpdb, $table_prefix; |
|
9 | 499 |
if ( ! empty( $wpdb->error ) ) { |
0 | 500 |
dead_db(); |
9 | 501 |
} |
0 | 502 |
|
9 | 503 |
$wpdb->field_types = array( |
504 |
'post_author' => '%d', |
|
505 |
'post_parent' => '%d', |
|
506 |
'menu_order' => '%d', |
|
507 |
'term_id' => '%d', |
|
508 |
'term_group' => '%d', |
|
509 |
'term_taxonomy_id' => '%d', |
|
510 |
'parent' => '%d', |
|
511 |
'count' => '%d', |
|
512 |
'object_id' => '%d', |
|
513 |
'term_order' => '%d', |
|
514 |
'ID' => '%d', |
|
515 |
'comment_ID' => '%d', |
|
516 |
'comment_post_ID' => '%d', |
|
517 |
'comment_parent' => '%d', |
|
518 |
'user_id' => '%d', |
|
519 |
'link_id' => '%d', |
|
520 |
'link_owner' => '%d', |
|
521 |
'link_rating' => '%d', |
|
522 |
'option_id' => '%d', |
|
523 |
'blog_id' => '%d', |
|
524 |
'meta_id' => '%d', |
|
525 |
'post_id' => '%d', |
|
526 |
'user_status' => '%d', |
|
527 |
'umeta_id' => '%d', |
|
528 |
'comment_karma' => '%d', |
|
529 |
'comment_count' => '%d', |
|
16 | 530 |
// Multisite: |
9 | 531 |
'active' => '%d', |
532 |
'cat_id' => '%d', |
|
533 |
'deleted' => '%d', |
|
534 |
'lang_id' => '%d', |
|
535 |
'mature' => '%d', |
|
536 |
'public' => '%d', |
|
537 |
'site_id' => '%d', |
|
538 |
'spam' => '%d', |
|
0 | 539 |
); |
540 |
||
541 |
$prefix = $wpdb->set_prefix( $table_prefix ); |
|
542 |
||
543 |
if ( is_wp_error( $prefix ) ) { |
|
544 |
wp_load_translations_early(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
wp_die( |
9 | 546 |
sprintf( |
16 | 547 |
/* translators: 1: $table_prefix, 2: wp-config.php */ |
548 |
__( '<strong>Error</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
'<code>$table_prefix</code>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
'<code>wp-config.php</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
); |
0 | 553 |
} |
554 |
} |
|
555 |
||
556 |
/** |
|
5 | 557 |
* Toggle `$_wp_using_ext_object_cache` on and off without directly |
558 |
* touching global. |
|
0 | 559 |
* |
560 |
* @since 3.7.0 |
|
561 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
* @global bool $_wp_using_ext_object_cache |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
* |
5 | 564 |
* @param bool $using Whether external object cache is being used. |
565 |
* @return bool The current 'using' setting. |
|
0 | 566 |
*/ |
567 |
function wp_using_ext_object_cache( $using = null ) { |
|
568 |
global $_wp_using_ext_object_cache; |
|
569 |
$current_using = $_wp_using_ext_object_cache; |
|
9 | 570 |
if ( null !== $using ) { |
0 | 571 |
$_wp_using_ext_object_cache = $using; |
9 | 572 |
} |
0 | 573 |
return $current_using; |
574 |
} |
|
575 |
||
576 |
/** |
|
5 | 577 |
* Start the WordPress object cache. |
0 | 578 |
* |
579 |
* If an object-cache.php file exists in the wp-content directory, |
|
580 |
* it uses that drop-in as an external object cache. |
|
581 |
* |
|
5 | 582 |
* @since 3.0.0 |
0 | 583 |
* @access private |
5 | 584 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
* @global array $wp_filter Stores all of the filters. |
0 | 586 |
*/ |
587 |
function wp_start_object_cache() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
global $wp_filter; |
9 | 589 |
static $first_init = true; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
|
9 | 591 |
// Only perform the following checks once. |
592 |
if ( $first_init ) { |
|
593 |
if ( ! function_exists( 'wp_cache_init' ) ) { |
|
594 |
/* |
|
595 |
* This is the normal situation. First-run of this function. No |
|
596 |
* caching backend has been loaded. |
|
597 |
* |
|
598 |
* We try to load a custom caching backend, and then, if it |
|
599 |
* results in a wp_cache_init() function existing, we note |
|
600 |
* that an external object cache is being used. |
|
601 |
*/ |
|
602 |
if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { |
|
16 | 603 |
require_once WP_CONTENT_DIR . '/object-cache.php'; |
9 | 604 |
if ( function_exists( 'wp_cache_init' ) ) { |
605 |
wp_using_ext_object_cache( true ); |
|
606 |
} |
|
0 | 607 |
|
16 | 608 |
// Re-initialize any hooks added manually by object-cache.php. |
9 | 609 |
if ( $wp_filter ) { |
610 |
$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter ); |
|
611 |
} |
|
612 |
} |
|
613 |
} elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { |
|
614 |
/* |
|
615 |
* Sometimes advanced-cache.php can load object-cache.php before |
|
616 |
* this function is run. This breaks the function_exists() check |
|
617 |
* above and can result in wp_using_ext_object_cache() returning |
|
618 |
* false when actually an external cache is in use. |
|
619 |
*/ |
|
620 |
wp_using_ext_object_cache( true ); |
|
621 |
} |
|
0 | 622 |
} |
623 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
if ( ! wp_using_ext_object_cache() ) { |
16 | 625 |
require_once ABSPATH . WPINC . '/cache.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
} |
0 | 627 |
|
16 | 628 |
require_once ABSPATH . WPINC . '/cache-compat.php'; |
629 |
||
5 | 630 |
/* |
631 |
* If cache supports reset, reset instead of init if already |
|
632 |
* initialized. Reset signals to the cache that global IDs |
|
633 |
* have changed and it may need to update keys and cleanup caches. |
|
634 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
wp_cache_switch_to_blog( get_current_blog_id() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
} elseif ( function_exists( 'wp_cache_init' ) ) { |
0 | 638 |
wp_cache_init(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
} |
0 | 640 |
|
641 |
if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
|
9 | 642 |
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); |
0 | 644 |
} |
9 | 645 |
|
646 |
$first_init = false; |
|
0 | 647 |
} |
648 |
||
649 |
/** |
|
5 | 650 |
* Redirect to the installer if WordPress is not installed. |
0 | 651 |
* |
5 | 652 |
* Dies with an error message when Multisite is enabled. |
0 | 653 |
* |
5 | 654 |
* @since 3.0.0 |
0 | 655 |
* @access private |
656 |
*/ |
|
657 |
function wp_not_installed() { |
|
658 |
if ( is_multisite() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
if ( ! is_blog_installed() && ! wp_installing() ) { |
5 | 660 |
nocache_headers(); |
661 |
||
0 | 662 |
wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) ); |
5 | 663 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
664 |
} elseif ( ! is_blog_installed() && ! wp_installing() ) { |
5 | 665 |
nocache_headers(); |
666 |
||
16 | 667 |
require ABSPATH . WPINC . '/kses.php'; |
668 |
require ABSPATH . WPINC . '/pluggable.php'; |
|
0 | 669 |
|
670 |
$link = wp_guess_url() . '/wp-admin/install.php'; |
|
671 |
||
672 |
wp_redirect( $link ); |
|
673 |
die(); |
|
674 |
} |
|
675 |
} |
|
676 |
||
677 |
/** |
|
5 | 678 |
* Retrieve an array of must-use plugin files. |
0 | 679 |
* |
5 | 680 |
* The default directory is wp-content/mu-plugins. To change the default |
681 |
* directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL` |
|
0 | 682 |
* in wp-config.php. |
683 |
* |
|
5 | 684 |
* @since 3.0.0 |
0 | 685 |
* @access private |
5 | 686 |
* |
16 | 687 |
* @return string[] Array of absolute paths of files to include. |
0 | 688 |
*/ |
689 |
function wp_get_mu_plugins() { |
|
690 |
$mu_plugins = array(); |
|
9 | 691 |
if ( ! is_dir( WPMU_PLUGIN_DIR ) ) { |
0 | 692 |
return $mu_plugins; |
9 | 693 |
} |
16 | 694 |
$dh = opendir( WPMU_PLUGIN_DIR ); |
695 |
if ( ! $dh ) { |
|
0 | 696 |
return $mu_plugins; |
9 | 697 |
} |
0 | 698 |
while ( ( $plugin = readdir( $dh ) ) !== false ) { |
16 | 699 |
if ( '.php' === substr( $plugin, -4 ) ) { |
0 | 700 |
$mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin; |
9 | 701 |
} |
0 | 702 |
} |
703 |
closedir( $dh ); |
|
704 |
sort( $mu_plugins ); |
|
705 |
||
706 |
return $mu_plugins; |
|
707 |
} |
|
708 |
||
709 |
/** |
|
5 | 710 |
* Retrieve an array of active and valid plugin files. |
0 | 711 |
* |
5 | 712 |
* While upgrading or installing WordPress, no plugins are returned. |
713 |
* |
|
9 | 714 |
* The default directory is `wp-content/plugins`. To change the default |
5 | 715 |
* directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` |
9 | 716 |
* in `wp-config.php`. |
0 | 717 |
* |
5 | 718 |
* @since 3.0.0 |
0 | 719 |
* @access private |
5 | 720 |
* |
16 | 721 |
* @return string[] Array of paths to plugin files relative to the plugins directory. |
0 | 722 |
*/ |
723 |
function wp_get_active_and_valid_plugins() { |
|
9 | 724 |
$plugins = array(); |
0 | 725 |
$active_plugins = (array) get_option( 'active_plugins', array() ); |
726 |
||
16 | 727 |
// Check for hacks file if the option is enabled. |
0 | 728 |
if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
_deprecated_file( 'my-hacks.php', '1.5.0' ); |
0 | 730 |
array_unshift( $plugins, ABSPATH . 'my-hacks.php' ); |
731 |
} |
|
732 |
||
9 | 733 |
if ( empty( $active_plugins ) || wp_installing() ) { |
0 | 734 |
return $plugins; |
9 | 735 |
} |
0 | 736 |
|
737 |
$network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; |
|
738 |
||
739 |
foreach ( $active_plugins as $plugin ) { |
|
16 | 740 |
if ( ! validate_file( $plugin ) // $plugin must validate as file. |
741 |
&& '.php' === substr( $plugin, -4 ) // $plugin must end with '.php'. |
|
742 |
&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist. |
|
743 |
// Not already included as a network plugin. |
|
744 |
&& ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) ) |
|
9 | 745 |
) { |
746 |
$plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
|
747 |
} |
|
748 |
} |
|
749 |
||
750 |
/* |
|
751 |
* Remove plugins from the list of active plugins when we're on an endpoint |
|
752 |
* that should be protected against WSODs and the plugin is paused. |
|
753 |
*/ |
|
754 |
if ( wp_is_recovery_mode() ) { |
|
755 |
$plugins = wp_skip_paused_plugins( $plugins ); |
|
756 |
} |
|
757 |
||
758 |
return $plugins; |
|
759 |
} |
|
760 |
||
761 |
/** |
|
762 |
* Filters a given list of plugins, removing any paused plugins from it. |
|
763 |
* |
|
764 |
* @since 5.2.0 |
|
765 |
* |
|
16 | 766 |
* @param string[] $plugins Array of absolute plugin main file paths. |
767 |
* @return string[] Filtered array of plugins, without any paused plugins. |
|
9 | 768 |
*/ |
769 |
function wp_skip_paused_plugins( array $plugins ) { |
|
770 |
$paused_plugins = wp_paused_plugins()->get_all(); |
|
771 |
||
772 |
if ( empty( $paused_plugins ) ) { |
|
773 |
return $plugins; |
|
774 |
} |
|
775 |
||
776 |
foreach ( $plugins as $index => $plugin ) { |
|
777 |
list( $plugin ) = explode( '/', plugin_basename( $plugin ) ); |
|
778 |
||
779 |
if ( array_key_exists( $plugin, $paused_plugins ) ) { |
|
780 |
unset( $plugins[ $index ] ); |
|
781 |
||
782 |
// Store list of paused plugins for displaying an admin notice. |
|
783 |
$GLOBALS['_paused_plugins'][ $plugin ] = $paused_plugins[ $plugin ]; |
|
784 |
} |
|
785 |
} |
|
786 |
||
787 |
return $plugins; |
|
788 |
} |
|
789 |
||
790 |
/** |
|
791 |
* Retrieves an array of active and valid themes. |
|
792 |
* |
|
793 |
* While upgrading or installing WordPress, no themes are returned. |
|
794 |
* |
|
795 |
* @since 5.1.0 |
|
796 |
* @access private |
|
797 |
* |
|
16 | 798 |
* @return string[] Array of absolute paths to theme directories. |
9 | 799 |
*/ |
800 |
function wp_get_active_and_valid_themes() { |
|
801 |
global $pagenow; |
|
802 |
||
803 |
$themes = array(); |
|
804 |
||
805 |
if ( wp_installing() && 'wp-activate.php' !== $pagenow ) { |
|
806 |
return $themes; |
|
807 |
} |
|
808 |
||
809 |
if ( TEMPLATEPATH !== STYLESHEETPATH ) { |
|
810 |
$themes[] = STYLESHEETPATH; |
|
811 |
} |
|
812 |
||
813 |
$themes[] = TEMPLATEPATH; |
|
814 |
||
815 |
/* |
|
816 |
* Remove themes from the list of active themes when we're on an endpoint |
|
817 |
* that should be protected against WSODs and the theme is paused. |
|
818 |
*/ |
|
819 |
if ( wp_is_recovery_mode() ) { |
|
820 |
$themes = wp_skip_paused_themes( $themes ); |
|
821 |
||
822 |
// If no active and valid themes exist, skip loading themes. |
|
823 |
if ( empty( $themes ) ) { |
|
824 |
add_filter( 'wp_using_themes', '__return_false' ); |
|
825 |
} |
|
826 |
} |
|
827 |
||
828 |
return $themes; |
|
829 |
} |
|
830 |
||
831 |
/** |
|
832 |
* Filters a given list of themes, removing any paused themes from it. |
|
833 |
* |
|
834 |
* @since 5.2.0 |
|
835 |
* |
|
16 | 836 |
* @param string[] $themes Array of absolute theme directory paths. |
837 |
* @return string[] Filtered array of absolute paths to themes, without any paused themes. |
|
9 | 838 |
*/ |
839 |
function wp_skip_paused_themes( array $themes ) { |
|
840 |
$paused_themes = wp_paused_themes()->get_all(); |
|
841 |
||
842 |
if ( empty( $paused_themes ) ) { |
|
843 |
return $themes; |
|
0 | 844 |
} |
9 | 845 |
|
846 |
foreach ( $themes as $index => $theme ) { |
|
847 |
$theme = basename( $theme ); |
|
848 |
||
849 |
if ( array_key_exists( $theme, $paused_themes ) ) { |
|
850 |
unset( $themes[ $index ] ); |
|
851 |
||
852 |
// Store list of paused themes for displaying an admin notice. |
|
853 |
$GLOBALS['_paused_themes'][ $theme ] = $paused_themes[ $theme ]; |
|
854 |
} |
|
855 |
} |
|
856 |
||
857 |
return $themes; |
|
858 |
} |
|
859 |
||
860 |
/** |
|
861 |
* Is WordPress in Recovery Mode. |
|
862 |
* |
|
863 |
* In this mode, plugins or themes that cause WSODs will be paused. |
|
864 |
* |
|
865 |
* @since 5.2.0 |
|
866 |
* |
|
867 |
* @return bool |
|
868 |
*/ |
|
869 |
function wp_is_recovery_mode() { |
|
870 |
return wp_recovery_mode()->is_active(); |
|
871 |
} |
|
872 |
||
873 |
/** |
|
874 |
* Determines whether we are currently on an endpoint that should be protected against WSODs. |
|
875 |
* |
|
876 |
* @since 5.2.0 |
|
877 |
* |
|
878 |
* @return bool True if the current endpoint should be protected. |
|
879 |
*/ |
|
880 |
function is_protected_endpoint() { |
|
881 |
// Protect login pages. |
|
882 |
if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) { |
|
883 |
return true; |
|
884 |
} |
|
885 |
||
886 |
// Protect the admin backend. |
|
887 |
if ( is_admin() && ! wp_doing_ajax() ) { |
|
888 |
return true; |
|
889 |
} |
|
890 |
||
16 | 891 |
// Protect Ajax actions that could help resolve a fatal error should be available. |
9 | 892 |
if ( is_protected_ajax_action() ) { |
893 |
return true; |
|
894 |
} |
|
895 |
||
896 |
/** |
|
897 |
* Filters whether the current request is against a protected endpoint. |
|
898 |
* |
|
899 |
* This filter is only fired when an endpoint is requested which is not already protected by |
|
900 |
* WordPress core. As such, it exclusively allows providing further protected endpoints in |
|
16 | 901 |
* addition to the admin backend, login pages and protected Ajax actions. |
9 | 902 |
* |
903 |
* @since 5.2.0 |
|
904 |
* |
|
16 | 905 |
* @param bool $is_protected_endpoint Whether the currently requested endpoint is protected. |
906 |
* Default false. |
|
9 | 907 |
*/ |
908 |
return (bool) apply_filters( 'is_protected_endpoint', false ); |
|
909 |
} |
|
910 |
||
911 |
/** |
|
16 | 912 |
* Determines whether we are currently handling an Ajax action that should be protected against WSODs. |
9 | 913 |
* |
914 |
* @since 5.2.0 |
|
915 |
* |
|
16 | 916 |
* @return bool True if the current Ajax action should be protected. |
9 | 917 |
*/ |
918 |
function is_protected_ajax_action() { |
|
919 |
if ( ! wp_doing_ajax() ) { |
|
920 |
return false; |
|
921 |
} |
|
922 |
||
923 |
if ( ! isset( $_REQUEST['action'] ) ) { |
|
924 |
return false; |
|
925 |
} |
|
926 |
||
927 |
$actions_to_protect = array( |
|
928 |
'edit-theme-plugin-file', // Saving changes in the core code editor. |
|
929 |
'heartbeat', // Keep the heart beating. |
|
930 |
'install-plugin', // Installing a new plugin. |
|
931 |
'install-theme', // Installing a new theme. |
|
932 |
'search-plugins', // Searching in the list of plugins. |
|
933 |
'search-install-plugins', // Searching for a plugin in the plugin install screen. |
|
934 |
'update-plugin', // Update an existing plugin. |
|
935 |
'update-theme', // Update an existing theme. |
|
936 |
); |
|
937 |
||
938 |
/** |
|
16 | 939 |
* Filters the array of protected Ajax actions. |
9 | 940 |
* |
16 | 941 |
* This filter is only fired when doing Ajax and the Ajax request has an 'action' property. |
9 | 942 |
* |
943 |
* @since 5.2.0 |
|
944 |
* |
|
16 | 945 |
* @param string[] $actions_to_protect Array of strings with Ajax actions to protect. |
9 | 946 |
*/ |
947 |
$actions_to_protect = (array) apply_filters( 'wp_protected_ajax_actions', $actions_to_protect ); |
|
948 |
||
949 |
if ( ! in_array( $_REQUEST['action'], $actions_to_protect, true ) ) { |
|
950 |
return false; |
|
951 |
} |
|
952 |
||
953 |
return true; |
|
0 | 954 |
} |
955 |
||
956 |
/** |
|
5 | 957 |
* Set internal encoding. |
0 | 958 |
* |
5 | 959 |
* In most cases the default internal encoding is latin1, which is |
960 |
* of no use, since we want to use the `mb_` functions for `utf-8` strings. |
|
0 | 961 |
* |
5 | 962 |
* @since 3.0.0 |
0 | 963 |
* @access private |
964 |
*/ |
|
965 |
function wp_set_internal_encoding() { |
|
966 |
if ( function_exists( 'mb_internal_encoding' ) ) { |
|
967 |
$charset = get_option( 'blog_charset' ); |
|
16 | 968 |
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
9 | 969 |
if ( ! $charset || ! @mb_internal_encoding( $charset ) ) { |
0 | 970 |
mb_internal_encoding( 'UTF-8' ); |
9 | 971 |
} |
0 | 972 |
} |
973 |
} |
|
974 |
||
975 |
/** |
|
5 | 976 |
* Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`. |
0 | 977 |
* |
5 | 978 |
* Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`, |
979 |
* `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly. |
|
0 | 980 |
* |
5 | 981 |
* @since 3.0.0 |
0 | 982 |
* @access private |
983 |
*/ |
|
984 |
function wp_magic_quotes() { |
|
985 |
// Escape with wpdb. |
|
9 | 986 |
$_GET = add_magic_quotes( $_GET ); |
987 |
$_POST = add_magic_quotes( $_POST ); |
|
0 | 988 |
$_COOKIE = add_magic_quotes( $_COOKIE ); |
989 |
$_SERVER = add_magic_quotes( $_SERVER ); |
|
990 |
||
991 |
// Force REQUEST to be GET + POST. |
|
992 |
$_REQUEST = array_merge( $_GET, $_POST ); |
|
993 |
} |
|
994 |
||
995 |
/** |
|
996 |
* Runs just before PHP shuts down execution. |
|
997 |
* |
|
5 | 998 |
* @since 1.2.0 |
0 | 999 |
* @access private |
1000 |
*/ |
|
1001 |
function shutdown_action_hook() { |
|
1002 |
/** |
|
1003 |
* Fires just before PHP shuts down execution. |
|
1004 |
* |
|
1005 |
* @since 1.2.0 |
|
1006 |
*/ |
|
1007 |
do_action( 'shutdown' ); |
|
5 | 1008 |
|
0 | 1009 |
wp_cache_close(); |
1010 |
} |
|
1011 |
||
1012 |
/** |
|
1013 |
* Copy an object. |
|
1014 |
* |
|
1015 |
* @since 2.7.0 |
|
5 | 1016 |
* @deprecated 3.2.0 |
0 | 1017 |
* |
5 | 1018 |
* @param object $object The object to clone. |
1019 |
* @return object The cloned object. |
|
0 | 1020 |
*/ |
1021 |
function wp_clone( $object ) { |
|
16 | 1022 |
// Use parens for clone to accommodate PHP 4. See #17880. |
0 | 1023 |
return clone( $object ); |
1024 |
} |
|
1025 |
||
1026 |
/** |
|
9 | 1027 |
* Determines whether the current request is for an administrative interface page. |
0 | 1028 |
* |
9 | 1029 |
* Does not check if the user is an administrator; use current_user_can() |
5 | 1030 |
* for checking roles and capabilities. |
0 | 1031 |
* |
9 | 1032 |
* For more information on this and similar theme functions, check out |
1033 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1034 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
1035 |
* |
|
0 | 1036 |
* @since 1.5.1 |
1037 |
* |
|
16 | 1038 |
* @global WP_Screen $current_screen WordPress current screen object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
* |
5 | 1040 |
* @return bool True if inside WordPress administration interface, false otherwise. |
0 | 1041 |
*/ |
1042 |
function is_admin() { |
|
9 | 1043 |
if ( isset( $GLOBALS['current_screen'] ) ) { |
0 | 1044 |
return $GLOBALS['current_screen']->in_admin(); |
9 | 1045 |
} elseif ( defined( 'WP_ADMIN' ) ) { |
0 | 1046 |
return WP_ADMIN; |
9 | 1047 |
} |
0 | 1048 |
|
1049 |
return false; |
|
1050 |
} |
|
1051 |
||
1052 |
/** |
|
16 | 1053 |
* Whether the current request is for a site's administrative interface. |
0 | 1054 |
* |
5 | 1055 |
* e.g. `/wp-admin/` |
1056 |
* |
|
9 | 1057 |
* Does not check if the user is an administrator; use current_user_can() |
5 | 1058 |
* for checking roles and capabilities. |
0 | 1059 |
* |
1060 |
* @since 3.1.0 |
|
1061 |
* |
|
16 | 1062 |
* @global WP_Screen $current_screen WordPress current screen object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
* |
5 | 1064 |
* @return bool True if inside WordPress blog administration pages. |
0 | 1065 |
*/ |
1066 |
function is_blog_admin() { |
|
9 | 1067 |
if ( isset( $GLOBALS['current_screen'] ) ) { |
0 | 1068 |
return $GLOBALS['current_screen']->in_admin( 'site' ); |
9 | 1069 |
} elseif ( defined( 'WP_BLOG_ADMIN' ) ) { |
0 | 1070 |
return WP_BLOG_ADMIN; |
9 | 1071 |
} |
0 | 1072 |
|
1073 |
return false; |
|
1074 |
} |
|
1075 |
||
1076 |
/** |
|
5 | 1077 |
* Whether the current request is for the network administrative interface. |
0 | 1078 |
* |
5 | 1079 |
* e.g. `/wp-admin/network/` |
1080 |
* |
|
9 | 1081 |
* Does not check if the user is an administrator; use current_user_can() |
5 | 1082 |
* for checking roles and capabilities. |
0 | 1083 |
* |
16 | 1084 |
* Does not check if the site is a Multisite network; use is_multisite() |
1085 |
* for checking if Multisite is enabled. |
|
1086 |
* |
|
0 | 1087 |
* @since 3.1.0 |
1088 |
* |
|
16 | 1089 |
* @global WP_Screen $current_screen WordPress current screen object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
* |
0 | 1091 |
* @return bool True if inside WordPress network administration pages. |
1092 |
*/ |
|
1093 |
function is_network_admin() { |
|
9 | 1094 |
if ( isset( $GLOBALS['current_screen'] ) ) { |
0 | 1095 |
return $GLOBALS['current_screen']->in_admin( 'network' ); |
9 | 1096 |
} elseif ( defined( 'WP_NETWORK_ADMIN' ) ) { |
0 | 1097 |
return WP_NETWORK_ADMIN; |
9 | 1098 |
} |
0 | 1099 |
|
1100 |
return false; |
|
1101 |
} |
|
1102 |
||
1103 |
/** |
|
5 | 1104 |
* Whether the current request is for a user admin screen. |
1105 |
* |
|
1106 |
* e.g. `/wp-admin/user/` |
|
0 | 1107 |
* |
9 | 1108 |
* Does not check if the user is an administrator; use current_user_can() |
1109 |
* for checking roles and capabilities. |
|
0 | 1110 |
* |
1111 |
* @since 3.1.0 |
|
1112 |
* |
|
16 | 1113 |
* @global WP_Screen $current_screen WordPress current screen object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
* |
0 | 1115 |
* @return bool True if inside WordPress user administration pages. |
1116 |
*/ |
|
1117 |
function is_user_admin() { |
|
9 | 1118 |
if ( isset( $GLOBALS['current_screen'] ) ) { |
0 | 1119 |
return $GLOBALS['current_screen']->in_admin( 'user' ); |
9 | 1120 |
} elseif ( defined( 'WP_USER_ADMIN' ) ) { |
0 | 1121 |
return WP_USER_ADMIN; |
9 | 1122 |
} |
0 | 1123 |
|
1124 |
return false; |
|
1125 |
} |
|
1126 |
||
1127 |
/** |
|
5 | 1128 |
* If Multisite is enabled. |
0 | 1129 |
* |
1130 |
* @since 3.0.0 |
|
1131 |
* |
|
5 | 1132 |
* @return bool True if Multisite is enabled, false otherwise. |
0 | 1133 |
*/ |
1134 |
function is_multisite() { |
|
9 | 1135 |
if ( defined( 'MULTISITE' ) ) { |
0 | 1136 |
return MULTISITE; |
9 | 1137 |
} |
0 | 1138 |
|
9 | 1139 |
if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) { |
0 | 1140 |
return true; |
9 | 1141 |
} |
0 | 1142 |
|
1143 |
return false; |
|
1144 |
} |
|
1145 |
||
1146 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
* Retrieve the current site ID. |
0 | 1148 |
* |
1149 |
* @since 3.1.0 |
|
1150 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
* @global int $blog_id |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1152 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
* @return int Site ID. |
0 | 1154 |
*/ |
1155 |
function get_current_blog_id() { |
|
1156 |
global $blog_id; |
|
9 | 1157 |
return absint( $blog_id ); |
0 | 1158 |
} |
1159 |
||
1160 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
* Retrieves the current network ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
* @return int The ID of the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
function get_current_network_id() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
if ( ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
return 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
$current_network = get_network(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
if ( ! isset( $current_network->id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
return get_main_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
return absint( $current_network->id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
/** |
5 | 1182 |
* Attempt an early load of translations. |
0 | 1183 |
* |
5 | 1184 |
* Used for errors encountered during the initial loading process, before |
1185 |
* the locale has been properly detected and loaded. |
|
0 | 1186 |
* |
5 | 1187 |
* Designed for unusual load sequences (like setup-config.php) or for when |
1188 |
* the script will then terminate with an error, otherwise there is a risk |
|
1189 |
* that a file can be double-included. |
|
0 | 1190 |
* |
1191 |
* @since 3.4.0 |
|
1192 |
* @access private |
|
5 | 1193 |
* |
16 | 1194 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
0 | 1195 |
*/ |
1196 |
function wp_load_translations_early() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
global $wp_locale; |
0 | 1198 |
|
1199 |
static $loaded = false; |
|
9 | 1200 |
if ( $loaded ) { |
0 | 1201 |
return; |
9 | 1202 |
} |
0 | 1203 |
$loaded = true; |
1204 |
||
9 | 1205 |
if ( function_exists( 'did_action' ) && did_action( 'init' ) ) { |
0 | 1206 |
return; |
9 | 1207 |
} |
0 | 1208 |
|
16 | 1209 |
// We need $wp_local_package. |
0 | 1210 |
require ABSPATH . WPINC . '/version.php'; |
1211 |
||
16 | 1212 |
// Translation and localization. |
0 | 1213 |
require_once ABSPATH . WPINC . '/pomo/mo.php'; |
1214 |
require_once ABSPATH . WPINC . '/l10n.php'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
require_once ABSPATH . WPINC . '/class-wp-locale.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; |
0 | 1217 |
|
16 | 1218 |
// General libraries. |
0 | 1219 |
require_once ABSPATH . WPINC . '/plugin.php'; |
1220 |
||
16 | 1221 |
$locales = array(); |
1222 |
$locations = array(); |
|
0 | 1223 |
|
1224 |
while ( true ) { |
|
1225 |
if ( defined( 'WPLANG' ) ) { |
|
16 | 1226 |
if ( '' === WPLANG ) { |
0 | 1227 |
break; |
9 | 1228 |
} |
0 | 1229 |
$locales[] = WPLANG; |
1230 |
} |
|
1231 |
||
9 | 1232 |
if ( isset( $wp_local_package ) ) { |
0 | 1233 |
$locales[] = $wp_local_package; |
9 | 1234 |
} |
0 | 1235 |
|
9 | 1236 |
if ( ! $locales ) { |
0 | 1237 |
break; |
9 | 1238 |
} |
0 | 1239 |
|
9 | 1240 |
if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) { |
0 | 1241 |
$locations[] = WP_LANG_DIR; |
9 | 1242 |
} |
0 | 1243 |
|
9 | 1244 |
if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) { |
0 | 1245 |
$locations[] = WP_CONTENT_DIR . '/languages'; |
9 | 1246 |
} |
0 | 1247 |
|
9 | 1248 |
if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) { |
0 | 1249 |
$locations[] = ABSPATH . 'wp-content/languages'; |
9 | 1250 |
} |
0 | 1251 |
|
9 | 1252 |
if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) { |
0 | 1253 |
$locations[] = ABSPATH . WPINC . '/languages'; |
9 | 1254 |
} |
0 | 1255 |
|
9 | 1256 |
if ( ! $locations ) { |
0 | 1257 |
break; |
9 | 1258 |
} |
0 | 1259 |
|
1260 |
$locations = array_unique( $locations ); |
|
1261 |
||
1262 |
foreach ( $locales as $locale ) { |
|
1263 |
foreach ( $locations as $location ) { |
|
1264 |
if ( file_exists( $location . '/' . $locale . '.mo' ) ) { |
|
1265 |
load_textdomain( 'default', $location . '/' . $locale . '.mo' ); |
|
9 | 1266 |
if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) { |
0 | 1267 |
load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' ); |
9 | 1268 |
} |
0 | 1269 |
break 2; |
1270 |
} |
|
1271 |
} |
|
1272 |
} |
|
1273 |
||
1274 |
break; |
|
1275 |
} |
|
1276 |
||
1277 |
$wp_locale = new WP_Locale(); |
|
1278 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
* Check or set whether WordPress is in "installation" mode. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
* If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
* @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1288 |
* Omit this parameter if you only want to fetch the current status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1289 |
* @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1290 |
* report whether WP was in installing mode prior to the change to `$is_installing`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1292 |
function wp_installing( $is_installing = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1293 |
static $installing = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1294 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1295 |
// Support for the `WP_INSTALLING` constant, defined before WP is loaded. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1296 |
if ( is_null( $installing ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1297 |
$installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1299 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1300 |
if ( ! is_null( $is_installing ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
$old_installing = $installing; |
9 | 1302 |
$installing = $is_installing; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
return (bool) $old_installing; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
return (bool) $installing; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
* Determines if SSL is used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
* @since 2.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
* @since 4.6.0 Moved from functions.php to load.php. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
* @return bool True if SSL, otherwise false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
function is_ssl() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
if ( isset( $_SERVER['HTTPS'] ) ) { |
16 | 1319 |
if ( 'on' === strtolower( $_SERVER['HTTPS'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
if ( '1' == $_SERVER['HTTPS'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
} |
9 | 1326 |
} elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1329 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
* Converts a shorthand byte value to an integer byte value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
* @since 2.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
* @since 4.6.0 Moved from media.php to load.php. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1337 |
* |
16 | 1338 |
* @link https://www.php.net/manual/en/function.ini-get.php |
1339 |
* @link https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
* @param string $value A (PHP ini) byte value, either shorthand or ordinary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
* @return int An integer byte value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
function wp_convert_hr_to_bytes( $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1345 |
$value = strtolower( trim( $value ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
$bytes = (int) $value; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1348 |
if ( false !== strpos( $value, 'g' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
$bytes *= GB_IN_BYTES; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
} elseif ( false !== strpos( $value, 'm' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
$bytes *= MB_IN_BYTES; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
} elseif ( false !== strpos( $value, 'k' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
$bytes *= KB_IN_BYTES; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
// Deal with large (float) values which run into the maximum integer size. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1357 |
return min( $bytes, PHP_INT_MAX ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
* Determines whether a PHP ini value is changeable at runtime. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
* |
16 | 1365 |
* @link https://www.php.net/manual/en/function.ini-get-all.php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1366 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
* @param string $setting The name of the ini setting to check. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
* @return bool True if the value is changeable at runtime. False otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
function wp_is_ini_value_changeable( $setting ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
static $ini_all; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
if ( ! isset( $ini_all ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
$ini_all = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1375 |
// Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes". |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
if ( function_exists( 'ini_get_all' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
$ini_all = ini_get_all(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1378 |
} |
9 | 1379 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1380 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
// Bit operator to workaround https://bugs.php.net/bug.php?id=44936 which changes access level to 63 in PHP 5.2.6 - 5.2.17. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
// If we were unable to retrieve the details, fail gracefully to assume it's changeable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
if ( ! is_array( $ini_all ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1388 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1389 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1392 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1393 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1394 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
* Determines whether the current request is a WordPress Ajax request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
* @return bool True if it's a WordPress Ajax request, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
function wp_doing_ajax() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
* Filters whether the current request is a WordPress Ajax request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
* @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1409 |
return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
/** |
9 | 1413 |
* Determines whether the current request should use themes. |
1414 |
* |
|
1415 |
* @since 5.1.0 |
|
1416 |
* |
|
1417 |
* @return bool True if themes should be used, false otherwise. |
|
1418 |
*/ |
|
1419 |
function wp_using_themes() { |
|
1420 |
/** |
|
1421 |
* Filters whether the current request should use themes. |
|
1422 |
* |
|
1423 |
* @since 5.1.0 |
|
1424 |
* |
|
1425 |
* @param bool $wp_using_themes Whether the current request should use themes. |
|
1426 |
*/ |
|
1427 |
return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES ); |
|
1428 |
} |
|
1429 |
||
1430 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1431 |
* Determines whether the current request is a WordPress cron request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1434 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1435 |
* @return bool True if it's a WordPress cron request, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1437 |
function wp_doing_cron() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1438 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1439 |
* Filters whether the current request is a WordPress cron request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1440 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1441 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1443 |
* @param bool $wp_doing_cron Whether the current request is a WordPress cron request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1444 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1445 |
return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1446 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1447 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1448 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
* Check whether variable is a WordPress Error. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1451 |
* Returns true if $thing is an object of the WP_Error class. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1452 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1453 |
* @since 2.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1454 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1455 |
* @param mixed $thing Check if unknown variable is a WP_Error object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1456 |
* @return bool True, if WP_Error. False, if not WP_Error. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1457 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1458 |
function is_wp_error( $thing ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1459 |
return ( $thing instanceof WP_Error ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1460 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1461 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1462 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1463 |
* Determines whether file modifications are allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1464 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1465 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1466 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1467 |
* @param string $context The usage context. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1468 |
* @return bool True if file modification is allowed, false otherwise. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1469 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
function wp_is_file_mod_allowed( $context ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
* Filters whether file modifications are allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1474 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1475 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
* @param bool $file_mod_allowed Whether file modifications are allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1477 |
* @param string $context The usage context. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1478 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
return apply_filters( 'file_mod_allowed', ! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS, $context ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1480 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1481 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1482 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
* Start scraping edited file errors. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1484 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1486 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
function wp_start_scraping_edited_file_errors() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1488 |
if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1489 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1490 |
} |
9 | 1491 |
$key = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
$nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
echo "###### wp_scraping_result_start:$key ######"; |
9 | 1496 |
echo wp_json_encode( |
1497 |
array( |
|
1498 |
'code' => 'scrape_nonce_failure', |
|
1499 |
'message' => __( 'Scrape nonce check failed. Please try again.' ), |
|
1500 |
) |
|
1501 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1502 |
echo "###### wp_scraping_result_end:$key ######"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1503 |
die(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1504 |
} |
9 | 1505 |
if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { |
1506 |
define( 'WP_SANDBOX_SCRAPING', true ); |
|
1507 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1508 |
register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1509 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1510 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1511 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1512 |
* Finalize scraping for edited file errors. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1513 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1514 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1515 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
* @param string $scrape_key Scrape key. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1517 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1518 |
function wp_finalize_scraping_edited_file_errors( $scrape_key ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1519 |
$error = error_get_last(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1520 |
echo "\n###### wp_scraping_result_start:$scrape_key ######\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1521 |
if ( ! empty( $error ) && in_array( $error['type'], array( E_CORE_ERROR, E_COMPILE_ERROR, E_ERROR, E_PARSE, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1522 |
$error = str_replace( ABSPATH, '', $error ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1523 |
echo wp_json_encode( $error ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1524 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1525 |
echo wp_json_encode( true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1526 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
echo "\n###### wp_scraping_result_end:$scrape_key ######\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1528 |
} |
9 | 1529 |
|
1530 |
/** |
|
1531 |
* Checks whether current request is a JSON request, or is expecting a JSON response. |
|
1532 |
* |
|
1533 |
* @since 5.0.0 |
|
1534 |
* |
|
16 | 1535 |
* @return bool True if `Accepts` or `Content-Type` headers contain `application/json`. |
1536 |
* False otherwise. |
|
9 | 1537 |
*/ |
1538 |
function wp_is_json_request() { |
|
1539 |
||
1540 |
if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) { |
|
1541 |
return true; |
|
1542 |
} |
|
1543 |
||
1544 |
if ( isset( $_SERVER['CONTENT_TYPE'] ) && 'application/json' === $_SERVER['CONTENT_TYPE'] ) { |
|
1545 |
return true; |
|
1546 |
} |
|
1547 |
||
1548 |
return false; |
|
1549 |
||
1550 |
} |
|
1551 |
||
1552 |
/** |
|
1553 |
* Checks whether current request is a JSONP request, or is expecting a JSONP response. |
|
1554 |
* |
|
1555 |
* @since 5.2.0 |
|
1556 |
* |
|
1557 |
* @return bool True if JSONP request, false otherwise. |
|
1558 |
*/ |
|
1559 |
function wp_is_jsonp_request() { |
|
1560 |
if ( ! isset( $_GET['_jsonp'] ) ) { |
|
1561 |
return false; |
|
1562 |
} |
|
1563 |
||
1564 |
if ( ! function_exists( 'wp_check_jsonp_callback' ) ) { |
|
1565 |
require_once ABSPATH . WPINC . '/functions.php'; |
|
1566 |
} |
|
1567 |
||
1568 |
$jsonp_callback = $_GET['_jsonp']; |
|
1569 |
if ( ! wp_check_jsonp_callback( $jsonp_callback ) ) { |
|
1570 |
return false; |
|
1571 |
} |
|
1572 |
||
1573 |
/** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */ |
|
1574 |
$jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true ); |
|
1575 |
||
1576 |
return $jsonp_enabled; |
|
1577 |
||
1578 |
} |
|
1579 |
||
1580 |
/** |
|
1581 |
* Checks whether current request is an XML request, or is expecting an XML response. |
|
1582 |
* |
|
1583 |
* @since 5.2.0 |
|
1584 |
* |
|
16 | 1585 |
* @return bool True if `Accepts` or `Content-Type` headers contain `text/xml` |
1586 |
* or one of the related MIME types. False otherwise. |
|
9 | 1587 |
*/ |
1588 |
function wp_is_xml_request() { |
|
1589 |
$accepted = array( |
|
1590 |
'text/xml', |
|
1591 |
'application/rss+xml', |
|
1592 |
'application/atom+xml', |
|
1593 |
'application/rdf+xml', |
|
1594 |
'text/xml+oembed', |
|
1595 |
'application/xml+oembed', |
|
1596 |
); |
|
1597 |
||
1598 |
if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) { |
|
1599 |
foreach ( $accepted as $type ) { |
|
1600 |
if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) { |
|
1601 |
return true; |
|
1602 |
} |
|
1603 |
} |
|
1604 |
} |
|
1605 |
||
1606 |
if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) { |
|
1607 |
return true; |
|
1608 |
} |
|
1609 |
||
1610 |
return false; |
|
1611 |
} |