4 * |
4 * |
5 * @package WordPress |
5 * @package WordPress |
6 */ |
6 */ |
7 |
7 |
8 /** |
8 /** |
9 * Return the HTTP protocol sent by the server. |
9 * Returns the HTTP protocol sent by the server. |
10 * |
10 * |
11 * @since 4.4.0 |
11 * @since 4.4.0 |
12 * |
12 * |
13 * @return string The HTTP protocol. Default: HTTP/1.0. |
13 * @return string The HTTP protocol. Default: HTTP/1.0. |
14 */ |
14 */ |
15 function wp_get_server_protocol() { |
15 function wp_get_server_protocol() { |
16 $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : ''; |
16 $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : ''; |
|
17 |
17 if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) { |
18 if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) { |
18 $protocol = 'HTTP/1.0'; |
19 $protocol = 'HTTP/1.0'; |
19 } |
20 } |
|
21 |
20 return $protocol; |
22 return $protocol; |
21 } |
23 } |
22 |
24 |
23 /** |
25 /** |
24 * Fix `$_SERVER` variables for various setups. |
26 * Fixes `$_SERVER` variables for various setups. |
25 * |
27 * |
26 * @since 3.0.0 |
28 * @since 3.0.0 |
27 * @access private |
29 * @access private |
28 * |
30 * |
29 * @global string $PHP_SELF The filename of the currently executing script, |
31 * @global string $PHP_SELF The filename of the currently executing script, |
38 ); |
40 ); |
39 |
41 |
40 $_SERVER = array_merge( $default_server_values, $_SERVER ); |
42 $_SERVER = array_merge( $default_server_values, $_SERVER ); |
41 |
43 |
42 // Fix for IIS when running with PHP ISAPI. |
44 // 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'] ) ) ) { |
45 if ( empty( $_SERVER['REQUEST_URI'] ) |
|
46 || ( 'cgi-fcgi' !== PHP_SAPI && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) |
|
47 ) { |
44 |
48 |
45 if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) { |
49 if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) { |
46 // IIS Mod-Rewrite. |
50 // IIS Mod-Rewrite. |
47 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; |
51 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; |
48 } elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) { |
52 } elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) { |
54 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; |
58 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; |
55 } |
59 } |
56 |
60 |
57 // Some IIS + PHP configurations put the script-name in the path-info (no need to append it twice). |
61 // Some IIS + PHP configurations put the script-name in the path-info (no need to append it twice). |
58 if ( isset( $_SERVER['PATH_INFO'] ) ) { |
62 if ( isset( $_SERVER['PATH_INFO'] ) ) { |
59 if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) { |
63 if ( $_SERVER['PATH_INFO'] === $_SERVER['SCRIPT_NAME'] ) { |
60 $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']; |
64 $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']; |
61 } else { |
65 } else { |
62 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']; |
66 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']; |
63 } |
67 } |
64 } |
68 } |
69 } |
73 } |
70 } |
74 } |
71 } |
75 } |
72 |
76 |
73 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests. |
77 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests. |
74 if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) ) { |
78 if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && str_ends_with( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) ) { |
75 $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED']; |
79 $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED']; |
76 } |
80 } |
77 |
81 |
78 // Fix for Dreamhost and other PHP as CGI hosts. |
82 // Fix for Dreamhost and other PHP as CGI hosts. |
79 if ( isset( $_SERVER['SCRIPT_NAME'] ) && ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) ) { |
83 if ( isset( $_SERVER['SCRIPT_NAME'] ) && str_contains( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) ) { |
80 unset( $_SERVER['PATH_INFO'] ); |
84 unset( $_SERVER['PATH_INFO'] ); |
81 } |
85 } |
82 |
86 |
83 // Fix empty PHP_SELF. |
87 // Fix empty PHP_SELF. |
84 $PHP_SELF = $_SERVER['PHP_SELF']; |
88 $PHP_SELF = $_SERVER['PHP_SELF']; |
120 |
124 |
121 // Removing `Basic ` the token would start six characters in. |
125 // Removing `Basic ` the token would start six characters in. |
122 $token = substr( $header, 6 ); |
126 $token = substr( $header, 6 ); |
123 $userpass = base64_decode( $token ); |
127 $userpass = base64_decode( $token ); |
124 |
128 |
125 list( $user, $pass ) = explode( ':', $userpass ); |
129 // There must be at least one colon in the string. |
|
130 if ( ! str_contains( $userpass, ':' ) ) { |
|
131 return; |
|
132 } |
|
133 |
|
134 list( $user, $pass ) = explode( ':', $userpass, 2 ); |
126 |
135 |
127 // Now shove them in the proper keys where we're expecting later on. |
136 // Now shove them in the proper keys where we're expecting later on. |
128 $_SERVER['PHP_AUTH_USER'] = $user; |
137 $_SERVER['PHP_AUTH_USER'] = $user; |
129 $_SERVER['PHP_AUTH_PW'] = $pass; |
138 $_SERVER['PHP_AUTH_PW'] = $pass; |
130 } |
139 } |
131 |
140 |
132 /** |
141 /** |
133 * Check for the required PHP version, and the MySQL extension or |
142 * Checks for the required PHP version, and the mysqli extension or |
134 * a database drop-in. |
143 * a database drop-in. |
135 * |
144 * |
136 * Dies if requirements are not met. |
145 * Dies if requirements are not met. |
137 * |
146 * |
138 * @since 3.0.0 |
147 * @since 3.0.0 |
141 * @global string $required_php_version The required PHP version string. |
150 * @global string $required_php_version The required PHP version string. |
142 * @global string $wp_version The WordPress version string. |
151 * @global string $wp_version The WordPress version string. |
143 */ |
152 */ |
144 function wp_check_php_mysql_versions() { |
153 function wp_check_php_mysql_versions() { |
145 global $required_php_version, $wp_version; |
154 global $required_php_version, $wp_version; |
146 $php_version = phpversion(); |
155 |
|
156 $php_version = PHP_VERSION; |
147 |
157 |
148 if ( version_compare( $required_php_version, $php_version, '>' ) ) { |
158 if ( version_compare( $required_php_version, $php_version, '>' ) ) { |
149 $protocol = wp_get_server_protocol(); |
159 $protocol = wp_get_server_protocol(); |
150 header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); |
160 header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); |
151 header( 'Content-Type: text/html; charset=utf-8' ); |
161 header( 'Content-Type: text/html; charset=utf-8' ); |
152 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 ); |
162 printf( |
|
163 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.', |
|
164 $php_version, |
|
165 $wp_version, |
|
166 $required_php_version |
|
167 ); |
153 exit( 1 ); |
168 exit( 1 ); |
154 } |
169 } |
155 |
170 |
156 if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) |
171 // This runs before default constants are defined, so we can't assume WP_CONTENT_DIR is set yet. |
157 // This runs before default constants are defined, so we can't assume WP_CONTENT_DIR is set yet. |
172 $wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content'; |
158 && ( defined( 'WP_CONTENT_DIR' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) |
173 |
159 || ! file_exists( ABSPATH . 'wp-content/db.php' ) ) |
174 if ( ! function_exists( 'mysqli_connect' ) |
|
175 && ! file_exists( $wp_content_dir . '/db.php' ) |
160 ) { |
176 ) { |
161 require_once ABSPATH . WPINC . '/functions.php'; |
177 require_once ABSPATH . WPINC . '/functions.php'; |
162 wp_load_translations_early(); |
178 wp_load_translations_early(); |
|
179 |
|
180 $message = '<p>' . __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) . "</p>\n"; |
|
181 |
|
182 $message .= '<p>' . sprintf( |
|
183 /* translators: %s: mysqli. */ |
|
184 __( 'Please check that the %s PHP extension is installed and enabled.' ), |
|
185 '<code>mysqli</code>' |
|
186 ) . "</p>\n"; |
|
187 |
|
188 $message .= '<p>' . sprintf( |
|
189 /* translators: %s: Support forums URL. */ |
|
190 __( 'If you are unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress support forums</a>.' ), |
|
191 __( 'https://wordpress.org/support/forums/' ) |
|
192 ) . "</p>\n"; |
|
193 |
163 $args = array( |
194 $args = array( |
164 'exit' => false, |
195 'exit' => false, |
165 'code' => 'mysql_not_found', |
196 'code' => 'mysql_not_found', |
166 ); |
197 ); |
167 wp_die( |
198 wp_die( |
168 __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ), |
199 $message, |
169 __( 'Requirements Not Met' ), |
200 __( 'Requirements Not Met' ), |
170 $args |
201 $args |
171 ); |
202 ); |
172 exit( 1 ); |
203 exit( 1 ); |
173 } |
204 } |
225 $current_env = $has_env; |
256 $current_env = $has_env; |
226 } |
257 } |
227 } |
258 } |
228 |
259 |
229 // Fetch the environment from a constant, this overrides the global system variable. |
260 // Fetch the environment from a constant, this overrides the global system variable. |
230 if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) { |
261 if ( defined( 'WP_ENVIRONMENT_TYPE' ) && WP_ENVIRONMENT_TYPE ) { |
231 $current_env = WP_ENVIRONMENT_TYPE; |
262 $current_env = WP_ENVIRONMENT_TYPE; |
232 } |
263 } |
233 |
264 |
234 // Make sure the environment is an allowed one, and not accidentally set to an invalid value. |
265 // Make sure the environment is an allowed one, and not accidentally set to an invalid value. |
235 if ( ! in_array( $current_env, $wp_environments, true ) ) { |
266 if ( ! in_array( $current_env, $wp_environments, true ) ) { |
238 |
269 |
239 return $current_env; |
270 return $current_env; |
240 } |
271 } |
241 |
272 |
242 /** |
273 /** |
243 * Don't load all of WordPress when handling a favicon.ico request. |
274 * Retrieves the current development mode. |
|
275 * |
|
276 * The development mode affects how certain parts of the WordPress application behave, |
|
277 * which is relevant when developing for WordPress. |
|
278 * |
|
279 * Development mode can be set via the `WP_DEVELOPMENT_MODE` constant in `wp-config.php`. |
|
280 * Possible values are 'core', 'plugin', 'theme', 'all', or an empty string to disable |
|
281 * development mode. 'all' is a special value to signify that all three development modes |
|
282 * ('core', 'plugin', and 'theme') are enabled. |
|
283 * |
|
284 * Development mode is considered separately from `WP_DEBUG` and wp_get_environment_type(). |
|
285 * It does not affect debugging output, but rather functional nuances in WordPress. |
|
286 * |
|
287 * This function retrieves the currently set development mode value. To check whether |
|
288 * a specific development mode is enabled, use wp_is_development_mode(). |
|
289 * |
|
290 * @since 6.3.0 |
|
291 * |
|
292 * @return string The current development mode. |
|
293 */ |
|
294 function wp_get_development_mode() { |
|
295 static $current_mode = null; |
|
296 |
|
297 if ( ! defined( 'WP_RUN_CORE_TESTS' ) && null !== $current_mode ) { |
|
298 return $current_mode; |
|
299 } |
|
300 |
|
301 $development_mode = WP_DEVELOPMENT_MODE; |
|
302 |
|
303 // Exclusively for core tests, rely on the `$_wp_tests_development_mode` global. |
|
304 if ( defined( 'WP_RUN_CORE_TESTS' ) && isset( $GLOBALS['_wp_tests_development_mode'] ) ) { |
|
305 $development_mode = $GLOBALS['_wp_tests_development_mode']; |
|
306 } |
|
307 |
|
308 $valid_modes = array( |
|
309 'core', |
|
310 'plugin', |
|
311 'theme', |
|
312 'all', |
|
313 '', |
|
314 ); |
|
315 |
|
316 if ( ! in_array( $development_mode, $valid_modes, true ) ) { |
|
317 $development_mode = ''; |
|
318 } |
|
319 |
|
320 $current_mode = $development_mode; |
|
321 |
|
322 return $current_mode; |
|
323 } |
|
324 |
|
325 /** |
|
326 * Checks whether the site is in the given development mode. |
|
327 * |
|
328 * @since 6.3.0 |
|
329 * |
|
330 * @param string $mode Development mode to check for. Either 'core', 'plugin', 'theme', or 'all'. |
|
331 * @return bool True if the given mode is covered by the current development mode, false otherwise. |
|
332 */ |
|
333 function wp_is_development_mode( $mode ) { |
|
334 $current_mode = wp_get_development_mode(); |
|
335 if ( empty( $current_mode ) ) { |
|
336 return false; |
|
337 } |
|
338 |
|
339 // Return true if the current mode encompasses all modes. |
|
340 if ( 'all' === $current_mode ) { |
|
341 return true; |
|
342 } |
|
343 |
|
344 // Return true if the current mode is the given mode. |
|
345 return $mode === $current_mode; |
|
346 } |
|
347 |
|
348 /** |
|
349 * Ensures all of WordPress is not loaded when handling a favicon.ico request. |
244 * |
350 * |
245 * Instead, send the headers for a zero-length favicon and bail. |
351 * Instead, send the headers for a zero-length favicon and bail. |
246 * |
352 * |
247 * @since 3.0.0 |
353 * @since 3.0.0 |
248 * @deprecated 5.4.0 Deprecated in favor of do_favicon(). |
354 * @deprecated 5.4.0 Deprecated in favor of do_favicon(). |
306 if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) { |
412 if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) { |
307 return false; |
413 return false; |
308 } |
414 } |
309 |
415 |
310 require ABSPATH . '.maintenance'; |
416 require ABSPATH . '.maintenance'; |
|
417 |
311 // If the $upgrading timestamp is older than 10 minutes, consider maintenance over. |
418 // If the $upgrading timestamp is older than 10 minutes, consider maintenance over. |
312 if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) { |
419 if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) { |
313 return false; |
420 return false; |
|
421 } |
|
422 |
|
423 // Don't enable maintenance mode while scraping for fatal errors. |
|
424 if ( is_int( $upgrading ) && isset( $_REQUEST['wp_scrape_key'], $_REQUEST['wp_scrape_nonce'] ) ) { |
|
425 $key = stripslashes( $_REQUEST['wp_scrape_key'] ); |
|
426 $nonce = stripslashes( $_REQUEST['wp_scrape_nonce'] ); |
|
427 |
|
428 if ( md5( $upgrading ) === $key && (int) $nonce === $upgrading ) { |
|
429 return false; |
|
430 } |
314 } |
431 } |
315 |
432 |
316 /** |
433 /** |
317 * Filters whether to enable maintenance mode. |
434 * Filters whether to enable maintenance mode. |
318 * |
435 * |
378 * @return string The "second.microsecond" finished time calculation. The number is formatted |
497 * @return string The "second.microsecond" finished time calculation. The number is formatted |
379 * for human consumption, both localized and rounded. |
498 * for human consumption, both localized and rounded. |
380 */ |
499 */ |
381 function timer_stop( $display = 0, $precision = 3 ) { |
500 function timer_stop( $display = 0, $precision = 3 ) { |
382 global $timestart, $timeend; |
501 global $timestart, $timeend; |
|
502 |
383 $timeend = microtime( true ); |
503 $timeend = microtime( true ); |
384 $timetotal = $timeend - $timestart; |
504 $timetotal = $timeend - $timestart; |
385 $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision ); |
505 |
|
506 if ( function_exists( 'number_format_i18n' ) ) { |
|
507 $r = number_format_i18n( $timetotal, $precision ); |
|
508 } else { |
|
509 $r = number_format( $timetotal, $precision ); |
|
510 } |
|
511 |
386 if ( $display ) { |
512 if ( $display ) { |
387 echo $r; |
513 echo $r; |
388 } |
514 } |
|
515 |
389 return $r; |
516 return $r; |
390 } |
517 } |
391 |
518 |
392 /** |
519 /** |
393 * Set PHP error reporting based on WordPress debug settings. |
520 * Sets PHP error reporting based on WordPress debug settings. |
394 * |
521 * |
395 * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`. |
522 * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`. |
396 * All three can be defined in wp-config.php. By default, `WP_DEBUG` and |
523 * All three can be defined in wp-config.php. By default, `WP_DEBUG` and |
397 * `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true. |
524 * `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true. |
398 * |
525 * |
479 } |
606 } |
480 } else { |
607 } else { |
481 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 ); |
608 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 ); |
482 } |
609 } |
483 |
610 |
484 if ( |
611 /* |
485 defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || defined( 'MS_FILES_REQUEST' ) || |
612 * The 'REST_REQUEST' check here is optimistic as the constant is most |
486 ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || |
613 * likely not set at this point even if it is in fact a REST request. |
487 wp_doing_ajax() || wp_is_json_request() ) { |
614 */ |
|
615 if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || defined( 'MS_FILES_REQUEST' ) |
|
616 || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) |
|
617 || wp_doing_ajax() || wp_is_json_request() |
|
618 ) { |
488 ini_set( 'display_errors', 0 ); |
619 ini_set( 'display_errors', 0 ); |
489 } |
620 } |
490 } |
621 } |
491 |
622 |
492 /** |
623 /** |
493 * Set the location of the language directory. |
624 * Sets the location of the language directory. |
494 * |
625 * |
495 * To set directory manually, define the `WP_LANG_DIR` constant |
626 * To set directory manually, define the `WP_LANG_DIR` constant |
496 * in wp-config.php. |
627 * in wp-config.php. |
497 * |
628 * |
498 * If the language directory exists within `WP_CONTENT_DIR`, it |
629 * If the language directory exists within `WP_CONTENT_DIR`, it |
502 * @since 3.0.0 |
633 * @since 3.0.0 |
503 * @access private |
634 * @access private |
504 */ |
635 */ |
505 function wp_set_lang_dir() { |
636 function wp_set_lang_dir() { |
506 if ( ! defined( 'WP_LANG_DIR' ) ) { |
637 if ( ! defined( 'WP_LANG_DIR' ) ) { |
507 if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || ! @is_dir( ABSPATH . WPINC . '/languages' ) ) { |
638 if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) |
|
639 || ! @is_dir( ABSPATH . WPINC . '/languages' ) |
|
640 ) { |
508 /** |
641 /** |
509 * Server path of the language directory. |
642 * Server path of the language directory. |
510 * |
643 * |
511 * No leading slash, no trailing slash, full path, not relative to ABSPATH |
644 * No leading slash, no trailing slash, full path, not relative to ABSPATH |
512 * |
645 * |
513 * @since 2.1.0 |
646 * @since 2.1.0 |
514 */ |
647 */ |
515 define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); |
648 define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); |
|
649 |
516 if ( ! defined( 'LANGDIR' ) ) { |
650 if ( ! defined( 'LANGDIR' ) ) { |
517 // Old static relative path maintained for limited backward compatibility - won't work in some cases. |
651 // Old static relative path maintained for limited backward compatibility - won't work in some cases. |
518 define( 'LANGDIR', 'wp-content/languages' ); |
652 define( 'LANGDIR', 'wp-content/languages' ); |
519 } |
653 } |
520 } else { |
654 } else { |
524 * No leading slash, no trailing slash, full path, not relative to `ABSPATH`. |
658 * No leading slash, no trailing slash, full path, not relative to `ABSPATH`. |
525 * |
659 * |
526 * @since 2.1.0 |
660 * @since 2.1.0 |
527 */ |
661 */ |
528 define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); |
662 define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); |
|
663 |
529 if ( ! defined( 'LANGDIR' ) ) { |
664 if ( ! defined( 'LANGDIR' ) ) { |
530 // Old relative path maintained for backward compatibility. |
665 // Old relative path maintained for backward compatibility. |
531 define( 'LANGDIR', WPINC . '/languages' ); |
666 define( 'LANGDIR', WPINC . '/languages' ); |
532 } |
667 } |
533 } |
668 } |
534 } |
669 } |
535 } |
670 } |
536 |
671 |
537 /** |
672 /** |
538 * Load the database class file and instantiate the `$wpdb` global. |
673 * Loads the database class file and instantiates the `$wpdb` global. |
539 * |
674 * |
540 * @since 2.5.0 |
675 * @since 2.5.0 |
541 * |
676 * |
542 * @global wpdb $wpdb WordPress database abstraction object. |
677 * @global wpdb $wpdb WordPress database abstraction object. |
543 */ |
678 */ |
544 function require_wp_db() { |
679 function require_wp_db() { |
545 global $wpdb; |
680 global $wpdb; |
546 |
681 |
547 require_once ABSPATH . WPINC . '/wp-db.php'; |
682 require_once ABSPATH . WPINC . '/class-wpdb.php'; |
|
683 |
548 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) { |
684 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) { |
549 require_once WP_CONTENT_DIR . '/db.php'; |
685 require_once WP_CONTENT_DIR . '/db.php'; |
550 } |
686 } |
551 |
687 |
552 if ( isset( $wpdb ) ) { |
688 if ( isset( $wpdb ) ) { |
573 * @global wpdb $wpdb WordPress database abstraction object. |
709 * @global wpdb $wpdb WordPress database abstraction object. |
574 * @global string $table_prefix The database table prefix. |
710 * @global string $table_prefix The database table prefix. |
575 */ |
711 */ |
576 function wp_set_wpdb_vars() { |
712 function wp_set_wpdb_vars() { |
577 global $wpdb, $table_prefix; |
713 global $wpdb, $table_prefix; |
|
714 |
578 if ( ! empty( $wpdb->error ) ) { |
715 if ( ! empty( $wpdb->error ) ) { |
579 dead_db(); |
716 dead_db(); |
580 } |
717 } |
581 |
718 |
582 $wpdb->field_types = array( |
719 $wpdb->field_types = array( |
622 if ( is_wp_error( $prefix ) ) { |
759 if ( is_wp_error( $prefix ) ) { |
623 wp_load_translations_early(); |
760 wp_load_translations_early(); |
624 wp_die( |
761 wp_die( |
625 sprintf( |
762 sprintf( |
626 /* translators: 1: $table_prefix, 2: wp-config.php */ |
763 /* translators: 1: $table_prefix, 2: wp-config.php */ |
627 __( '<strong>Error</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ), |
764 __( '<strong>Error:</strong> %1$s in %2$s can only contain numbers, letters, and underscores.' ), |
628 '<code>$table_prefix</code>', |
765 '<code>$table_prefix</code>', |
629 '<code>wp-config.php</code>' |
766 '<code>wp-config.php</code>' |
630 ) |
767 ) |
631 ); |
768 ); |
632 } |
769 } |
633 } |
770 } |
634 |
771 |
635 /** |
772 /** |
636 * Toggle `$_wp_using_ext_object_cache` on and off without directly |
773 * Toggles `$_wp_using_ext_object_cache` on and off without directly |
637 * touching global. |
774 * touching global. |
638 * |
775 * |
639 * @since 3.7.0 |
776 * @since 3.7.0 |
640 * |
777 * |
641 * @global bool $_wp_using_ext_object_cache |
778 * @global bool $_wp_using_ext_object_cache |
643 * @param bool $using Whether external object cache is being used. |
780 * @param bool $using Whether external object cache is being used. |
644 * @return bool The current 'using' setting. |
781 * @return bool The current 'using' setting. |
645 */ |
782 */ |
646 function wp_using_ext_object_cache( $using = null ) { |
783 function wp_using_ext_object_cache( $using = null ) { |
647 global $_wp_using_ext_object_cache; |
784 global $_wp_using_ext_object_cache; |
|
785 |
648 $current_using = $_wp_using_ext_object_cache; |
786 $current_using = $_wp_using_ext_object_cache; |
|
787 |
649 if ( null !== $using ) { |
788 if ( null !== $using ) { |
650 $_wp_using_ext_object_cache = $using; |
789 $_wp_using_ext_object_cache = $using; |
651 } |
790 } |
|
791 |
652 return $current_using; |
792 return $current_using; |
653 } |
793 } |
654 |
794 |
655 /** |
795 /** |
656 * Start the WordPress object cache. |
796 * Starts the WordPress object cache. |
657 * |
797 * |
658 * If an object-cache.php file exists in the wp-content directory, |
798 * If an object-cache.php file exists in the wp-content directory, |
659 * it uses that drop-in as an external object cache. |
799 * it uses that drop-in as an external object cache. |
660 * |
800 * |
661 * @since 3.0.0 |
801 * @since 3.0.0 |
690 * results in a wp_cache_init() function existing, we note |
830 * results in a wp_cache_init() function existing, we note |
691 * that an external object cache is being used. |
831 * that an external object cache is being used. |
692 */ |
832 */ |
693 if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { |
833 if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { |
694 require_once WP_CONTENT_DIR . '/object-cache.php'; |
834 require_once WP_CONTENT_DIR . '/object-cache.php'; |
|
835 |
695 if ( function_exists( 'wp_cache_init' ) ) { |
836 if ( function_exists( 'wp_cache_init' ) ) { |
696 wp_using_ext_object_cache( true ); |
837 wp_using_ext_object_cache( true ); |
697 } |
838 } |
698 |
839 |
699 // Re-initialize any hooks added manually by object-cache.php. |
840 // Re-initialize any hooks added manually by object-cache.php. |
728 } elseif ( function_exists( 'wp_cache_init' ) ) { |
869 } elseif ( function_exists( 'wp_cache_init' ) ) { |
729 wp_cache_init(); |
870 wp_cache_init(); |
730 } |
871 } |
731 |
872 |
732 if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
873 if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
733 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' ) ); |
874 wp_cache_add_global_groups( |
734 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); |
875 array( |
|
876 'blog-details', |
|
877 'blog-id-cache', |
|
878 'blog-lookup', |
|
879 'blog_meta', |
|
880 'global-posts', |
|
881 'networks', |
|
882 'network-queries', |
|
883 'sites', |
|
884 'site-details', |
|
885 'site-options', |
|
886 'site-queries', |
|
887 'site-transient', |
|
888 'theme_files', |
|
889 'translation_files', |
|
890 'rss', |
|
891 'users', |
|
892 'user-queries', |
|
893 'user_meta', |
|
894 'useremail', |
|
895 'userlogins', |
|
896 'userslugs', |
|
897 ) |
|
898 ); |
|
899 |
|
900 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) ); |
735 } |
901 } |
736 |
902 |
737 $first_init = false; |
903 $first_init = false; |
738 } |
904 } |
739 |
905 |
740 /** |
906 /** |
741 * Redirect to the installer if WordPress is not installed. |
907 * Redirects to the installer if WordPress is not installed. |
742 * |
908 * |
743 * Dies with an error message when Multisite is enabled. |
909 * Dies with an error message when Multisite is enabled. |
744 * |
910 * |
745 * @since 3.0.0 |
911 * @since 3.0.0 |
746 * @access private |
912 * @access private |
747 */ |
913 */ |
748 function wp_not_installed() { |
914 function wp_not_installed() { |
|
915 if ( is_blog_installed() || wp_installing() ) { |
|
916 return; |
|
917 } |
|
918 |
|
919 nocache_headers(); |
|
920 |
749 if ( is_multisite() ) { |
921 if ( is_multisite() ) { |
750 if ( ! is_blog_installed() && ! wp_installing() ) { |
922 wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) ); |
751 nocache_headers(); |
923 } |
752 |
924 |
753 wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) ); |
925 require ABSPATH . WPINC . '/kses.php'; |
754 } |
926 require ABSPATH . WPINC . '/pluggable.php'; |
755 } elseif ( ! is_blog_installed() && ! wp_installing() ) { |
927 |
756 nocache_headers(); |
928 $link = wp_guess_url() . '/wp-admin/install.php'; |
757 |
929 |
758 require ABSPATH . WPINC . '/kses.php'; |
930 wp_redirect( $link ); |
759 require ABSPATH . WPINC . '/pluggable.php'; |
931 die(); |
760 |
932 } |
761 $link = wp_guess_url() . '/wp-admin/install.php'; |
933 |
762 |
934 /** |
763 wp_redirect( $link ); |
935 * Retrieves an array of must-use plugin files. |
764 die(); |
|
765 } |
|
766 } |
|
767 |
|
768 /** |
|
769 * Retrieve an array of must-use plugin files. |
|
770 * |
936 * |
771 * The default directory is wp-content/mu-plugins. To change the default |
937 * The default directory is wp-content/mu-plugins. To change the default |
772 * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL` |
938 * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL` |
773 * in wp-config.php. |
939 * in wp-config.php. |
774 * |
940 * |
777 * |
943 * |
778 * @return string[] Array of absolute paths of files to include. |
944 * @return string[] Array of absolute paths of files to include. |
779 */ |
945 */ |
780 function wp_get_mu_plugins() { |
946 function wp_get_mu_plugins() { |
781 $mu_plugins = array(); |
947 $mu_plugins = array(); |
|
948 |
782 if ( ! is_dir( WPMU_PLUGIN_DIR ) ) { |
949 if ( ! is_dir( WPMU_PLUGIN_DIR ) ) { |
783 return $mu_plugins; |
950 return $mu_plugins; |
784 } |
951 } |
|
952 |
785 $dh = opendir( WPMU_PLUGIN_DIR ); |
953 $dh = opendir( WPMU_PLUGIN_DIR ); |
786 if ( ! $dh ) { |
954 if ( ! $dh ) { |
787 return $mu_plugins; |
955 return $mu_plugins; |
788 } |
956 } |
|
957 |
789 while ( ( $plugin = readdir( $dh ) ) !== false ) { |
958 while ( ( $plugin = readdir( $dh ) ) !== false ) { |
790 if ( '.php' === substr( $plugin, -4 ) ) { |
959 if ( str_ends_with( $plugin, '.php' ) ) { |
791 $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin; |
960 $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin; |
792 } |
961 } |
793 } |
962 } |
|
963 |
794 closedir( $dh ); |
964 closedir( $dh ); |
|
965 |
795 sort( $mu_plugins ); |
966 sort( $mu_plugins ); |
796 |
967 |
797 return $mu_plugins; |
968 return $mu_plugins; |
798 } |
969 } |
799 |
970 |
800 /** |
971 /** |
801 * Retrieve an array of active and valid plugin files. |
972 * Retrieves an array of active and valid plugin files. |
802 * |
973 * |
803 * While upgrading or installing WordPress, no plugins are returned. |
974 * While upgrading or installing WordPress, no plugins are returned. |
804 * |
975 * |
805 * The default directory is `wp-content/plugins`. To change the default |
976 * The default directory is `wp-content/plugins`. To change the default |
806 * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` |
977 * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` |
827 |
998 |
828 $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; |
999 $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; |
829 |
1000 |
830 foreach ( $active_plugins as $plugin ) { |
1001 foreach ( $active_plugins as $plugin ) { |
831 if ( ! validate_file( $plugin ) // $plugin must validate as file. |
1002 if ( ! validate_file( $plugin ) // $plugin must validate as file. |
832 && '.php' === substr( $plugin, -4 ) // $plugin must end with '.php'. |
1003 && str_ends_with( $plugin, '.php' ) // $plugin must end with '.php'. |
833 && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist. |
1004 && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist. |
834 // Not already included as a network plugin. |
1005 // Not already included as a network plugin. |
835 && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) ) |
1006 && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) ) |
836 ) { |
1007 ) { |
837 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
1008 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
838 } |
1009 } |
839 } |
1010 } |
840 |
1011 |
841 /* |
1012 /* |
852 /** |
1023 /** |
853 * Filters a given list of plugins, removing any paused plugins from it. |
1024 * Filters a given list of plugins, removing any paused plugins from it. |
854 * |
1025 * |
855 * @since 5.2.0 |
1026 * @since 5.2.0 |
856 * |
1027 * |
|
1028 * @global WP_Paused_Extensions_Storage $_paused_plugins |
|
1029 * |
857 * @param string[] $plugins Array of absolute plugin main file paths. |
1030 * @param string[] $plugins Array of absolute plugin main file paths. |
858 * @return string[] Filtered array of plugins, without any paused plugins. |
1031 * @return string[] Filtered array of plugins, without any paused plugins. |
859 */ |
1032 */ |
860 function wp_skip_paused_plugins( array $plugins ) { |
1033 function wp_skip_paused_plugins( array $plugins ) { |
861 $paused_plugins = wp_paused_plugins()->get_all(); |
1034 $paused_plugins = wp_paused_plugins()->get_all(); |
884 * While upgrading or installing WordPress, no themes are returned. |
1057 * While upgrading or installing WordPress, no themes are returned. |
885 * |
1058 * |
886 * @since 5.1.0 |
1059 * @since 5.1.0 |
887 * @access private |
1060 * @access private |
888 * |
1061 * |
889 * @global string $pagenow The filename of the current screen. |
1062 * @global string $pagenow The filename of the current screen. |
|
1063 * @global string $wp_stylesheet_path Path to current theme's stylesheet directory. |
|
1064 * @global string $wp_template_path Path to current theme's template directory. |
890 * |
1065 * |
891 * @return string[] Array of absolute paths to theme directories. |
1066 * @return string[] Array of absolute paths to theme directories. |
892 */ |
1067 */ |
893 function wp_get_active_and_valid_themes() { |
1068 function wp_get_active_and_valid_themes() { |
894 global $pagenow; |
1069 global $pagenow, $wp_stylesheet_path, $wp_template_path; |
895 |
1070 |
896 $themes = array(); |
1071 $themes = array(); |
897 |
1072 |
898 if ( wp_installing() && 'wp-activate.php' !== $pagenow ) { |
1073 if ( wp_installing() && 'wp-activate.php' !== $pagenow ) { |
899 return $themes; |
1074 return $themes; |
900 } |
1075 } |
901 |
1076 |
902 if ( TEMPLATEPATH !== STYLESHEETPATH ) { |
1077 if ( is_child_theme() ) { |
903 $themes[] = STYLESHEETPATH; |
1078 $themes[] = $wp_stylesheet_path; |
904 } |
1079 } |
905 |
1080 |
906 $themes[] = TEMPLATEPATH; |
1081 $themes[] = $wp_template_path; |
907 |
1082 |
908 /* |
1083 /* |
909 * Remove themes from the list of active themes when we're on an endpoint |
1084 * Remove themes from the list of active themes when we're on an endpoint |
910 * that should be protected against WSODs and the theme is paused. |
1085 * that should be protected against WSODs and the theme is paused. |
911 */ |
1086 */ |
924 /** |
1099 /** |
925 * Filters a given list of themes, removing any paused themes from it. |
1100 * Filters a given list of themes, removing any paused themes from it. |
926 * |
1101 * |
927 * @since 5.2.0 |
1102 * @since 5.2.0 |
928 * |
1103 * |
|
1104 * @global WP_Paused_Extensions_Storage $_paused_themes |
|
1105 * |
929 * @param string[] $themes Array of absolute theme directory paths. |
1106 * @param string[] $themes Array of absolute theme directory paths. |
930 * @return string[] Filtered array of absolute paths to themes, without any paused themes. |
1107 * @return string[] Filtered array of absolute paths to themes, without any paused themes. |
931 */ |
1108 */ |
932 function wp_skip_paused_themes( array $themes ) { |
1109 function wp_skip_paused_themes( array $themes ) { |
933 $paused_themes = wp_paused_themes()->get_all(); |
1110 $paused_themes = wp_paused_themes()->get_all(); |
1026 'install-theme', // Installing a new theme. |
1203 'install-theme', // Installing a new theme. |
1027 'search-plugins', // Searching in the list of plugins. |
1204 'search-plugins', // Searching in the list of plugins. |
1028 'search-install-plugins', // Searching for a plugin in the plugin install screen. |
1205 'search-install-plugins', // Searching for a plugin in the plugin install screen. |
1029 'update-plugin', // Update an existing plugin. |
1206 'update-plugin', // Update an existing plugin. |
1030 'update-theme', // Update an existing theme. |
1207 'update-theme', // Update an existing theme. |
|
1208 'activate-plugin', // Activating an existing plugin. |
1031 ); |
1209 ); |
1032 |
1210 |
1033 /** |
1211 /** |
1034 * Filters the array of protected Ajax actions. |
1212 * Filters the array of protected Ajax actions. |
1035 * |
1213 * |
1103 |
1281 |
1104 wp_cache_close(); |
1282 wp_cache_close(); |
1105 } |
1283 } |
1106 |
1284 |
1107 /** |
1285 /** |
1108 * Copy an object. |
1286 * Clones an object. |
1109 * |
1287 * |
1110 * @since 2.7.0 |
1288 * @since 2.7.0 |
1111 * @deprecated 3.2.0 |
1289 * @deprecated 3.2.0 |
1112 * |
1290 * |
1113 * @param object $object The object to clone. |
1291 * @param object $input_object The object to clone. |
1114 * @return object The cloned object. |
1292 * @return object The cloned object. |
1115 */ |
1293 */ |
1116 function wp_clone( $object ) { |
1294 function wp_clone( $input_object ) { |
1117 // Use parens for clone to accommodate PHP 4. See #17880. |
1295 // Use parens for clone to accommodate PHP 4. See #17880. |
1118 return clone( $object ); |
1296 return clone( $input_object ); |
|
1297 } |
|
1298 |
|
1299 /** |
|
1300 * Determines whether the current request is for the login screen. |
|
1301 * |
|
1302 * @since 6.1.0 |
|
1303 * |
|
1304 * @see wp_login_url() |
|
1305 * |
|
1306 * @return bool True if inside WordPress login screen, false otherwise. |
|
1307 */ |
|
1308 function is_login() { |
|
1309 return false !== stripos( wp_login_url(), $_SERVER['SCRIPT_NAME'] ); |
1119 } |
1310 } |
1120 |
1311 |
1121 /** |
1312 /** |
1122 * Determines whether the current request is for an administrative interface page. |
1313 * Determines whether the current request is for an administrative interface page. |
1123 * |
1314 * |
1143 |
1334 |
1144 return false; |
1335 return false; |
1145 } |
1336 } |
1146 |
1337 |
1147 /** |
1338 /** |
1148 * Whether the current request is for a site's administrative interface. |
1339 * Determines whether the current request is for a site's administrative interface. |
1149 * |
1340 * |
1150 * e.g. `/wp-admin/` |
1341 * e.g. `/wp-admin/` |
1151 * |
1342 * |
1152 * Does not check if the user is an administrator; use current_user_can() |
1343 * Does not check if the user is an administrator; use current_user_can() |
1153 * for checking roles and capabilities. |
1344 * for checking roles and capabilities. |
1154 * |
1345 * |
1155 * @since 3.1.0 |
1346 * @since 3.1.0 |
1156 * |
1347 * |
1157 * @global WP_Screen $current_screen WordPress current screen object. |
1348 * @global WP_Screen $current_screen WordPress current screen object. |
1158 * |
1349 * |
1159 * @return bool True if inside WordPress blog administration pages. |
1350 * @return bool True if inside WordPress site administration pages. |
1160 */ |
1351 */ |
1161 function is_blog_admin() { |
1352 function is_blog_admin() { |
1162 if ( isset( $GLOBALS['current_screen'] ) ) { |
1353 if ( isset( $GLOBALS['current_screen'] ) ) { |
1163 return $GLOBALS['current_screen']->in_admin( 'site' ); |
1354 return $GLOBALS['current_screen']->in_admin( 'site' ); |
1164 } elseif ( defined( 'WP_BLOG_ADMIN' ) ) { |
1355 } elseif ( defined( 'WP_BLOG_ADMIN' ) ) { |
1304 // We need $wp_local_package. |
1498 // We need $wp_local_package. |
1305 require ABSPATH . WPINC . '/version.php'; |
1499 require ABSPATH . WPINC . '/version.php'; |
1306 |
1500 |
1307 // Translation and localization. |
1501 // Translation and localization. |
1308 require_once ABSPATH . WPINC . '/pomo/mo.php'; |
1502 require_once ABSPATH . WPINC . '/pomo/mo.php'; |
|
1503 require_once ABSPATH . WPINC . '/l10n/class-wp-translation-controller.php'; |
|
1504 require_once ABSPATH . WPINC . '/l10n/class-wp-translations.php'; |
|
1505 require_once ABSPATH . WPINC . '/l10n/class-wp-translation-file.php'; |
|
1506 require_once ABSPATH . WPINC . '/l10n/class-wp-translation-file-mo.php'; |
|
1507 require_once ABSPATH . WPINC . '/l10n/class-wp-translation-file-php.php'; |
1309 require_once ABSPATH . WPINC . '/l10n.php'; |
1508 require_once ABSPATH . WPINC . '/l10n.php'; |
|
1509 require_once ABSPATH . WPINC . '/class-wp-textdomain-registry.php'; |
1310 require_once ABSPATH . WPINC . '/class-wp-locale.php'; |
1510 require_once ABSPATH . WPINC . '/class-wp-locale.php'; |
1311 require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; |
1511 require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; |
1312 |
1512 |
1313 // General libraries. |
1513 // General libraries. |
1314 require_once ABSPATH . WPINC . '/plugin.php'; |
1514 require_once ABSPATH . WPINC . '/plugin.php'; |
1315 |
1515 |
1316 $locales = array(); |
1516 $locales = array(); |
1317 $locations = array(); |
1517 $locations = array(); |
|
1518 |
|
1519 if ( ! $wp_textdomain_registry instanceof WP_Textdomain_Registry ) { |
|
1520 $wp_textdomain_registry = new WP_Textdomain_Registry(); |
|
1521 } |
1318 |
1522 |
1319 while ( true ) { |
1523 while ( true ) { |
1320 if ( defined( 'WPLANG' ) ) { |
1524 if ( defined( 'WPLANG' ) ) { |
1321 if ( '' === WPLANG ) { |
1525 if ( '' === WPLANG ) { |
1322 break; |
1526 break; |
1355 $locations = array_unique( $locations ); |
1559 $locations = array_unique( $locations ); |
1356 |
1560 |
1357 foreach ( $locales as $locale ) { |
1561 foreach ( $locales as $locale ) { |
1358 foreach ( $locations as $location ) { |
1562 foreach ( $locations as $location ) { |
1359 if ( file_exists( $location . '/' . $locale . '.mo' ) ) { |
1563 if ( file_exists( $location . '/' . $locale . '.mo' ) ) { |
1360 load_textdomain( 'default', $location . '/' . $locale . '.mo' ); |
1564 load_textdomain( 'default', $location . '/' . $locale . '.mo', $locale ); |
|
1565 |
1361 if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) { |
1566 if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) { |
1362 load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' ); |
1567 load_textdomain( 'default', $location . '/admin-' . $locale . '.mo', $locale ); |
1363 } |
1568 } |
|
1569 |
1364 break 2; |
1570 break 2; |
1365 } |
1571 } |
1366 } |
1572 } |
1367 } |
1573 } |
1368 |
1574 |
1438 */ |
1646 */ |
1439 function wp_convert_hr_to_bytes( $value ) { |
1647 function wp_convert_hr_to_bytes( $value ) { |
1440 $value = strtolower( trim( $value ) ); |
1648 $value = strtolower( trim( $value ) ); |
1441 $bytes = (int) $value; |
1649 $bytes = (int) $value; |
1442 |
1650 |
1443 if ( false !== strpos( $value, 'g' ) ) { |
1651 if ( str_contains( $value, 'g' ) ) { |
1444 $bytes *= GB_IN_BYTES; |
1652 $bytes *= GB_IN_BYTES; |
1445 } elseif ( false !== strpos( $value, 'm' ) ) { |
1653 } elseif ( str_contains( $value, 'm' ) ) { |
1446 $bytes *= MB_IN_BYTES; |
1654 $bytes *= MB_IN_BYTES; |
1447 } elseif ( false !== strpos( $value, 'k' ) ) { |
1655 } elseif ( str_contains( $value, 'k' ) ) { |
1448 $bytes *= KB_IN_BYTES; |
1656 $bytes *= KB_IN_BYTES; |
1449 } |
1657 } |
1450 |
1658 |
1451 // Deal with large (float) values which run into the maximum integer size. |
1659 // Deal with large (float) values which run into the maximum integer size. |
1452 return min( $bytes, PHP_INT_MAX ); |
1660 return min( $bytes, PHP_INT_MAX ); |
1472 $ini_all = ini_get_all(); |
1680 $ini_all = ini_get_all(); |
1473 } |
1681 } |
1474 } |
1682 } |
1475 |
1683 |
1476 // 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. |
1684 // 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. |
1477 if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) { |
1685 if ( isset( $ini_all[ $setting ]['access'] ) |
|
1686 && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) |
|
1687 ) { |
1478 return true; |
1688 return true; |
1479 } |
1689 } |
1480 |
1690 |
1481 // If we were unable to retrieve the details, fail gracefully to assume it's changeable. |
1691 // If we were unable to retrieve the details, fail gracefully to assume it's changeable. |
1482 if ( ! is_array( $ini_all ) ) { |
1692 if ( ! is_array( $ini_all ) ) { |
1586 */ |
1796 */ |
1587 return apply_filters( 'file_mod_allowed', ! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS, $context ); |
1797 return apply_filters( 'file_mod_allowed', ! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS, $context ); |
1588 } |
1798 } |
1589 |
1799 |
1590 /** |
1800 /** |
1591 * Start scraping edited file errors. |
1801 * Starts scraping edited file errors. |
1592 * |
1802 * |
1593 * @since 4.9.0 |
1803 * @since 4.9.0 |
1594 */ |
1804 */ |
1595 function wp_start_scraping_edited_file_errors() { |
1805 function wp_start_scraping_edited_file_errors() { |
1596 if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) { |
1806 if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) { |
1597 return; |
1807 return; |
1598 } |
1808 } |
|
1809 |
1599 $key = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 ); |
1810 $key = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 ); |
1600 $nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] ); |
1811 $nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] ); |
1601 |
1812 |
1602 if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) { |
1813 if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) { |
1603 echo "###### wp_scraping_result_start:$key ######"; |
1814 echo "###### wp_scraping_result_start:$key ######"; |
1608 ) |
1819 ) |
1609 ); |
1820 ); |
1610 echo "###### wp_scraping_result_end:$key ######"; |
1821 echo "###### wp_scraping_result_end:$key ######"; |
1611 die(); |
1822 die(); |
1612 } |
1823 } |
|
1824 |
1613 if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { |
1825 if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { |
1614 define( 'WP_SANDBOX_SCRAPING', true ); |
1826 define( 'WP_SANDBOX_SCRAPING', true ); |
1615 } |
1827 } |
|
1828 |
1616 register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key ); |
1829 register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key ); |
1617 } |
1830 } |
1618 |
1831 |
1619 /** |
1832 /** |
1620 * Finalize scraping for edited file errors. |
1833 * Finalizes scraping for edited file errors. |
1621 * |
1834 * |
1622 * @since 4.9.0 |
1835 * @since 4.9.0 |
1623 * |
1836 * |
1624 * @param string $scrape_key Scrape key. |
1837 * @param string $scrape_key Scrape key. |
1625 */ |
1838 */ |
1626 function wp_finalize_scraping_edited_file_errors( $scrape_key ) { |
1839 function wp_finalize_scraping_edited_file_errors( $scrape_key ) { |
1627 $error = error_get_last(); |
1840 $error = error_get_last(); |
|
1841 |
1628 echo "\n###### wp_scraping_result_start:$scrape_key ######\n"; |
1842 echo "\n###### wp_scraping_result_start:$scrape_key ######\n"; |
1629 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 ) ) { |
1843 |
|
1844 if ( ! empty( $error ) |
|
1845 && in_array( $error['type'], array( E_CORE_ERROR, E_COMPILE_ERROR, E_ERROR, E_PARSE, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) |
|
1846 ) { |
1630 $error = str_replace( ABSPATH, '', $error ); |
1847 $error = str_replace( ABSPATH, '', $error ); |
1631 echo wp_json_encode( $error ); |
1848 echo wp_json_encode( $error ); |
1632 } else { |
1849 } else { |
1633 echo wp_json_encode( true ); |
1850 echo wp_json_encode( true ); |
1634 } |
1851 } |
|
1852 |
1635 echo "\n###### wp_scraping_result_end:$scrape_key ######\n"; |
1853 echo "\n###### wp_scraping_result_end:$scrape_key ######\n"; |
1636 } |
1854 } |
1637 |
1855 |
1638 /** |
1856 /** |
1639 * Checks whether current request is a JSON request, or is expecting a JSON response. |
1857 * Checks whether current request is a JSON request, or is expecting a JSON response. |