changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
6:490d5cc509ed | 7:cf61fcea0001 |
---|---|
1 <?php |
1 <?php |
2 /** |
2 /** |
3 * These functions are needed to load WordPress. |
3 * These functions are needed to load WordPress. |
4 * |
4 * |
5 * @internal This file must be parsable by PHP4. |
|
6 * |
|
7 * @package WordPress |
5 * @package WordPress |
8 */ |
6 */ |
9 |
7 |
10 /** |
8 /** |
9 * Return the HTTP protocol sent by the server. |
|
10 * |
|
11 * @since 4.4.0 |
|
12 * |
|
13 * @return string The HTTP protocol. Default: HTTP/1.0. |
|
14 */ |
|
15 function wp_get_server_protocol() { |
|
16 $protocol = $_SERVER['SERVER_PROTOCOL']; |
|
17 if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) { |
|
18 $protocol = 'HTTP/1.0'; |
|
19 } |
|
20 return $protocol; |
|
21 } |
|
22 |
|
23 /** |
|
11 * Turn register globals off. |
24 * Turn register globals off. |
12 * |
25 * |
13 * @since 2.1.0 |
26 * @since 2.1.0 |
14 * @access private |
27 * @access private |
15 * |
|
16 * @return null Will return null if register_globals PHP directive was disabled. |
|
17 */ |
28 */ |
18 function wp_unregister_GLOBALS() { |
29 function wp_unregister_GLOBALS() { |
19 if ( !ini_get( 'register_globals' ) ) |
30 if ( !ini_get( 'register_globals' ) ) |
20 return; |
31 return; |
21 |
32 |
111 global $required_php_version, $wp_version; |
122 global $required_php_version, $wp_version; |
112 $php_version = phpversion(); |
123 $php_version = phpversion(); |
113 |
124 |
114 if ( version_compare( $required_php_version, $php_version, '>' ) ) { |
125 if ( version_compare( $required_php_version, $php_version, '>' ) ) { |
115 wp_load_translations_early(); |
126 wp_load_translations_early(); |
127 |
|
128 $protocol = wp_get_server_protocol(); |
|
129 header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); |
|
116 header( 'Content-Type: text/html; charset=utf-8' ); |
130 header( 'Content-Type: text/html; charset=utf-8' ); |
131 /* translators: 1: Current PHP version number, 2: WordPress version number, 3: Minimum required PHP version number */ |
|
117 die( sprintf( __( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.' ), $php_version, $wp_version, $required_php_version ) ); |
132 die( sprintf( __( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.' ), $php_version, $wp_version, $required_php_version ) ); |
118 } |
133 } |
119 |
134 |
120 if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) { |
135 if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) { |
121 wp_load_translations_early(); |
136 wp_load_translations_early(); |
122 header( 'Content-Type: text/html; charset=utf-8' ); |
137 |
138 $protocol = wp_get_server_protocol(); |
|
139 header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); |
|
140 header( 'Content-Type: text/html; charset=utf-8' ); |
|
123 die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) ); |
141 die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) ); |
124 } |
142 } |
125 } |
143 } |
126 |
144 |
127 /** |
145 /** |
132 * @since 3.0.0 |
150 * @since 3.0.0 |
133 */ |
151 */ |
134 function wp_favicon_request() { |
152 function wp_favicon_request() { |
135 if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) { |
153 if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) { |
136 header('Content-Type: image/vnd.microsoft.icon'); |
154 header('Content-Type: image/vnd.microsoft.icon'); |
137 header('Content-Length: 0'); |
|
138 exit; |
155 exit; |
139 } |
156 } |
140 } |
157 } |
141 |
158 |
142 /** |
159 /** |
154 * @access private |
171 * @access private |
155 * |
172 * |
156 * @global int $upgrading the unix timestamp marking when upgrading WordPress began. |
173 * @global int $upgrading the unix timestamp marking when upgrading WordPress began. |
157 */ |
174 */ |
158 function wp_maintenance() { |
175 function wp_maintenance() { |
159 if ( !file_exists( ABSPATH . '.maintenance' ) || defined( 'WP_INSTALLING' ) ) |
176 if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) |
160 return; |
177 return; |
161 |
178 |
162 global $upgrading; |
179 global $upgrading; |
163 |
180 |
164 include( ABSPATH . '.maintenance' ); |
181 include( ABSPATH . '.maintenance' ); |
165 // If the $upgrading timestamp is older than 10 minutes, don't die. |
182 // If the $upgrading timestamp is older than 10 minutes, don't die. |
166 if ( ( time() - $upgrading ) >= 600 ) |
183 if ( ( time() - $upgrading ) >= 600 ) |
167 return; |
184 return; |
168 |
185 |
186 /** |
|
187 * Filters whether to enable maintenance mode. |
|
188 * |
|
189 * This filter runs before it can be used by plugins. It is designed for |
|
190 * non-web runtimes. If this filter returns true, maintenance mode will be |
|
191 * active and the request will end. If false, the request will be allowed to |
|
192 * continue processing even if maintenance mode should be active. |
|
193 * |
|
194 * @since 4.6.0 |
|
195 * |
|
196 * @param bool $enable_checks Whether to enable maintenance mode. Default true. |
|
197 * @param int $upgrading The timestamp set in the .maintenance file. |
|
198 */ |
|
199 if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) { |
|
200 return; |
|
201 } |
|
202 |
|
169 if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { |
203 if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { |
170 require_once( WP_CONTENT_DIR . '/maintenance.php' ); |
204 require_once( WP_CONTENT_DIR . '/maintenance.php' ); |
171 die(); |
205 die(); |
172 } |
206 } |
173 |
207 |
174 wp_load_translations_early(); |
208 wp_load_translations_early(); |
175 |
209 |
176 $protocol = $_SERVER["SERVER_PROTOCOL"]; |
210 $protocol = wp_get_server_protocol(); |
177 if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) |
|
178 $protocol = 'HTTP/1.0'; |
|
179 header( "$protocol 503 Service Unavailable", true, 503 ); |
211 header( "$protocol 503 Service Unavailable", true, 503 ); |
180 header( 'Content-Type: text/html; charset=utf-8' ); |
212 header( 'Content-Type: text/html; charset=utf-8' ); |
181 header( 'Retry-After: 600' ); |
213 header( 'Retry-After: 600' ); |
182 ?> |
214 ?> |
183 <!DOCTYPE html> |
215 <!DOCTYPE html> |
239 |
271 |
240 /** |
272 /** |
241 * Set PHP error reporting based on WordPress debug settings. |
273 * Set PHP error reporting based on WordPress debug settings. |
242 * |
274 * |
243 * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`. |
275 * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`. |
244 * All three can be defined in wp-config.php, and by default are set to false. |
276 * All three can be defined in wp-config.php. By default, `WP_DEBUG` and |
277 * `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true. |
|
245 * |
278 * |
246 * When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also |
279 * When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also |
247 * display internal notices: when a deprecated WordPress function, function |
280 * display internal notices: when a deprecated WordPress function, function |
248 * argument, or file is used. Deprecated code may be removed from a later |
281 * argument, or file is used. Deprecated code may be removed from a later |
249 * version. |
282 * version. |
260 * as false will force errors to be hidden. |
293 * as false will force errors to be hidden. |
261 * |
294 * |
262 * When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content |
295 * When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content |
263 * directory. |
296 * directory. |
264 * |
297 * |
265 * Errors are never displayed for XML-RPC requests. |
298 * Errors are never displayed for XML-RPC, REST, and Ajax requests. |
266 * |
299 * |
267 * @since 3.0.0 |
300 * @since 3.0.0 |
268 * @access private |
301 * @access private |
269 */ |
302 */ |
270 function wp_debug_mode() { |
303 function wp_debug_mode() { |
304 /** |
|
305 * Filters whether to allow the debug mode check to occur. |
|
306 * |
|
307 * This filter runs before it can be used by plugins. It is designed for |
|
308 * non-web run-times. Returning false causes the `WP_DEBUG` and related |
|
309 * constants to not be checked and the default php values for errors |
|
310 * will be used unless you take care to update them yourself. |
|
311 * |
|
312 * @since 4.6.0 |
|
313 * |
|
314 * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true. |
|
315 */ |
|
316 if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ){ |
|
317 return; |
|
318 } |
|
319 |
|
271 if ( WP_DEBUG ) { |
320 if ( WP_DEBUG ) { |
272 error_reporting( E_ALL ); |
321 error_reporting( E_ALL ); |
273 |
322 |
274 if ( WP_DEBUG_DISPLAY ) |
323 if ( WP_DEBUG_DISPLAY ) |
275 ini_set( 'display_errors', 1 ); |
324 ini_set( 'display_errors', 1 ); |
281 ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); |
330 ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); |
282 } |
331 } |
283 } else { |
332 } else { |
284 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 ); |
333 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 ); |
285 } |
334 } |
286 if ( defined( 'XMLRPC_REQUEST' ) ) |
335 |
287 ini_set( 'display_errors', 0 ); |
336 if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) { |
337 @ini_set( 'display_errors', 0 ); |
|
338 } |
|
288 } |
339 } |
289 |
340 |
290 /** |
341 /** |
291 * Set the location of the language directory. |
342 * Set the location of the language directory. |
292 * |
343 * |
310 * |
361 * |
311 * @since 2.1.0 |
362 * @since 2.1.0 |
312 */ |
363 */ |
313 define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); |
364 define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); |
314 if ( !defined( 'LANGDIR' ) ) { |
365 if ( !defined( 'LANGDIR' ) ) { |
315 // Old static relative path maintained for limited backwards compatibility - won't work in some cases |
366 // Old static relative path maintained for limited backward compatibility - won't work in some cases. |
316 define( 'LANGDIR', 'wp-content/languages' ); |
367 define( 'LANGDIR', 'wp-content/languages' ); |
317 } |
368 } |
318 } else { |
369 } else { |
319 /** |
370 /** |
320 * Server path of the language directory. |
371 * Server path of the language directory. |
323 * |
374 * |
324 * @since 2.1.0 |
375 * @since 2.1.0 |
325 */ |
376 */ |
326 define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); |
377 define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); |
327 if ( !defined( 'LANGDIR' ) ) { |
378 if ( !defined( 'LANGDIR' ) ) { |
328 // Old relative path maintained for backwards compatibility |
379 // Old relative path maintained for backward compatibility. |
329 define( 'LANGDIR', WPINC . '/languages' ); |
380 define( 'LANGDIR', WPINC . '/languages' ); |
330 } |
381 } |
331 } |
382 } |
332 } |
383 } |
333 } |
384 } |
344 |
395 |
345 require_once( ABSPATH . WPINC . '/wp-db.php' ); |
396 require_once( ABSPATH . WPINC . '/wp-db.php' ); |
346 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) |
397 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) |
347 require_once( WP_CONTENT_DIR . '/db.php' ); |
398 require_once( WP_CONTENT_DIR . '/db.php' ); |
348 |
399 |
349 if ( isset( $wpdb ) ) |
400 if ( isset( $wpdb ) ) { |
350 return; |
401 return; |
402 } |
|
351 |
403 |
352 $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); |
404 $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); |
353 } |
405 } |
354 |
406 |
355 /** |
407 /** |
379 |
431 |
380 $prefix = $wpdb->set_prefix( $table_prefix ); |
432 $prefix = $wpdb->set_prefix( $table_prefix ); |
381 |
433 |
382 if ( is_wp_error( $prefix ) ) { |
434 if ( is_wp_error( $prefix ) ) { |
383 wp_load_translations_early(); |
435 wp_load_translations_early(); |
384 wp_die( __( '<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.' ) ); |
436 wp_die( |
385 } |
437 /* translators: 1: $table_prefix 2: wp-config.php */ |
386 } |
438 sprintf( __( '<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ), |
387 |
439 '<code>$table_prefix</code>', |
388 /** |
440 '<code>wp-config.php</code>' |
389 * Access/Modify private global variable `$_wp_using_ext_object_cache`. |
441 ) |
390 * |
442 ); |
443 } |
|
444 } |
|
445 |
|
446 /** |
|
391 * Toggle `$_wp_using_ext_object_cache` on and off without directly |
447 * Toggle `$_wp_using_ext_object_cache` on and off without directly |
392 * touching global. |
448 * touching global. |
393 * |
449 * |
394 * @since 3.7.0 |
450 * @since 3.7.0 |
451 * |
|
452 * @global bool $_wp_using_ext_object_cache |
|
395 * |
453 * |
396 * @param bool $using Whether external object cache is being used. |
454 * @param bool $using Whether external object cache is being used. |
397 * @return bool The current 'using' setting. |
455 * @return bool The current 'using' setting. |
398 */ |
456 */ |
399 function wp_using_ext_object_cache( $using = null ) { |
457 function wp_using_ext_object_cache( $using = null ) { |
411 * it uses that drop-in as an external object cache. |
469 * it uses that drop-in as an external object cache. |
412 * |
470 * |
413 * @since 3.0.0 |
471 * @since 3.0.0 |
414 * @access private |
472 * @access private |
415 * |
473 * |
416 * @global int $blog_id Blog ID. |
474 * @global array $wp_filter Stores all of the filters. |
417 */ |
475 */ |
418 function wp_start_object_cache() { |
476 function wp_start_object_cache() { |
419 global $blog_id; |
477 global $wp_filter; |
420 |
478 |
421 $first_init = false; |
479 $first_init = false; |
422 if ( ! function_exists( 'wp_cache_init' ) ) { |
480 if ( ! function_exists( 'wp_cache_init' ) ) { |
423 if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { |
481 if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { |
424 require_once ( WP_CONTENT_DIR . '/object-cache.php' ); |
482 require_once ( WP_CONTENT_DIR . '/object-cache.php' ); |
425 if ( function_exists( 'wp_cache_init' ) ) |
483 if ( function_exists( 'wp_cache_init' ) ) { |
426 wp_using_ext_object_cache( true ); |
484 wp_using_ext_object_cache( true ); |
485 } |
|
486 |
|
487 // Re-initialize any hooks added manually by object-cache.php |
|
488 if ( $wp_filter ) { |
|
489 $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter ); |
|
490 } |
|
427 } |
491 } |
428 |
492 |
429 $first_init = true; |
493 $first_init = true; |
430 } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { |
494 } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { |
431 /* |
495 /* |
435 * incorrectly. Double check if an external cache exists. |
499 * incorrectly. Double check if an external cache exists. |
436 */ |
500 */ |
437 wp_using_ext_object_cache( true ); |
501 wp_using_ext_object_cache( true ); |
438 } |
502 } |
439 |
503 |
440 if ( ! wp_using_ext_object_cache() ) |
504 if ( ! wp_using_ext_object_cache() ) { |
441 require_once ( ABSPATH . WPINC . '/cache.php' ); |
505 require_once ( ABSPATH . WPINC . '/cache.php' ); |
506 } |
|
442 |
507 |
443 /* |
508 /* |
444 * If cache supports reset, reset instead of init if already |
509 * If cache supports reset, reset instead of init if already |
445 * initialized. Reset signals to the cache that global IDs |
510 * initialized. Reset signals to the cache that global IDs |
446 * have changed and it may need to update keys and cleanup caches. |
511 * have changed and it may need to update keys and cleanup caches. |
447 */ |
512 */ |
448 if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) |
513 if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) { |
449 wp_cache_switch_to_blog( $blog_id ); |
514 wp_cache_switch_to_blog( get_current_blog_id() ); |
450 elseif ( function_exists( 'wp_cache_init' ) ) |
515 } elseif ( function_exists( 'wp_cache_init' ) ) { |
451 wp_cache_init(); |
516 wp_cache_init(); |
517 } |
|
452 |
518 |
453 if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
519 if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
454 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) ); |
520 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' ) ); |
455 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); |
521 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); |
456 } |
522 } |
457 } |
523 } |
458 |
524 |
459 /** |
525 /** |
460 * Redirect to the installer if WordPress is not installed. |
526 * Redirect to the installer if WordPress is not installed. |
464 * @since 3.0.0 |
530 * @since 3.0.0 |
465 * @access private |
531 * @access private |
466 */ |
532 */ |
467 function wp_not_installed() { |
533 function wp_not_installed() { |
468 if ( is_multisite() ) { |
534 if ( is_multisite() ) { |
469 if ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) ) { |
535 if ( ! is_blog_installed() && ! wp_installing() ) { |
470 nocache_headers(); |
536 nocache_headers(); |
471 |
537 |
472 wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) ); |
538 wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) ); |
473 } |
539 } |
474 } elseif ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) ) { |
540 } elseif ( ! is_blog_installed() && ! wp_installing() ) { |
475 nocache_headers(); |
541 nocache_headers(); |
476 |
542 |
477 require( ABSPATH . WPINC . '/kses.php' ); |
543 require( ABSPATH . WPINC . '/kses.php' ); |
478 require( ABSPATH . WPINC . '/pluggable.php' ); |
544 require( ABSPATH . WPINC . '/pluggable.php' ); |
479 require( ABSPATH . WPINC . '/formatting.php' ); |
545 require( ABSPATH . WPINC . '/formatting.php' ); |
531 $plugins = array(); |
597 $plugins = array(); |
532 $active_plugins = (array) get_option( 'active_plugins', array() ); |
598 $active_plugins = (array) get_option( 'active_plugins', array() ); |
533 |
599 |
534 // Check for hacks file if the option is enabled |
600 // Check for hacks file if the option is enabled |
535 if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) { |
601 if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) { |
536 _deprecated_file( 'my-hacks.php', '1.5' ); |
602 _deprecated_file( 'my-hacks.php', '1.5.0' ); |
537 array_unshift( $plugins, ABSPATH . 'my-hacks.php' ); |
603 array_unshift( $plugins, ABSPATH . 'my-hacks.php' ); |
538 } |
604 } |
539 |
605 |
540 if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) ) |
606 if ( empty( $active_plugins ) || wp_installing() ) |
541 return $plugins; |
607 return $plugins; |
542 |
608 |
543 $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; |
609 $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; |
544 |
610 |
545 foreach ( $active_plugins as $plugin ) { |
611 foreach ( $active_plugins as $plugin ) { |
630 } |
696 } |
631 |
697 |
632 /** |
698 /** |
633 * Whether the current request is for an administrative interface page. |
699 * Whether the current request is for an administrative interface page. |
634 * |
700 * |
635 * Does not check if the user is an administrator; {@see current_user_can()} |
701 * Does not check if the user is an administrator; current_user_can() |
636 * for checking roles and capabilities. |
702 * for checking roles and capabilities. |
637 * |
703 * |
638 * @since 1.5.1 |
704 * @since 1.5.1 |
705 * |
|
706 * @global WP_Screen $current_screen |
|
639 * |
707 * |
640 * @return bool True if inside WordPress administration interface, false otherwise. |
708 * @return bool True if inside WordPress administration interface, false otherwise. |
641 */ |
709 */ |
642 function is_admin() { |
710 function is_admin() { |
643 if ( isset( $GLOBALS['current_screen'] ) ) |
711 if ( isset( $GLOBALS['current_screen'] ) ) |
651 /** |
719 /** |
652 * Whether the current request is for a site's admininstrative interface. |
720 * Whether the current request is for a site's admininstrative interface. |
653 * |
721 * |
654 * e.g. `/wp-admin/` |
722 * e.g. `/wp-admin/` |
655 * |
723 * |
656 * Does not check if the user is an administrator; {@see current_user_can()} |
724 * Does not check if the user is an administrator; current_user_can() |
657 * for checking roles and capabilities. |
725 * for checking roles and capabilities. |
658 * |
726 * |
659 * @since 3.1.0 |
727 * @since 3.1.0 |
728 * |
|
729 * @global WP_Screen $current_screen |
|
660 * |
730 * |
661 * @return bool True if inside WordPress blog administration pages. |
731 * @return bool True if inside WordPress blog administration pages. |
662 */ |
732 */ |
663 function is_blog_admin() { |
733 function is_blog_admin() { |
664 if ( isset( $GLOBALS['current_screen'] ) ) |
734 if ( isset( $GLOBALS['current_screen'] ) ) |
672 /** |
742 /** |
673 * Whether the current request is for the network administrative interface. |
743 * Whether the current request is for the network administrative interface. |
674 * |
744 * |
675 * e.g. `/wp-admin/network/` |
745 * e.g. `/wp-admin/network/` |
676 * |
746 * |
677 * Does not check if the user is an administrator; {@see current_user_can()} |
747 * Does not check if the user is an administrator; current_user_can() |
678 * for checking roles and capabilities. |
748 * for checking roles and capabilities. |
679 * |
749 * |
680 * @since 3.1.0 |
750 * @since 3.1.0 |
751 * |
|
752 * @global WP_Screen $current_screen |
|
681 * |
753 * |
682 * @return bool True if inside WordPress network administration pages. |
754 * @return bool True if inside WordPress network administration pages. |
683 */ |
755 */ |
684 function is_network_admin() { |
756 function is_network_admin() { |
685 if ( isset( $GLOBALS['current_screen'] ) ) |
757 if ( isset( $GLOBALS['current_screen'] ) ) |
695 * |
767 * |
696 * e.g. `/wp-admin/user/` |
768 * e.g. `/wp-admin/user/` |
697 * |
769 * |
698 * Does not inform on whether the user is an admin! Use capability |
770 * Does not inform on whether the user is an admin! Use capability |
699 * checks to tell if the user should be accessing a section or not |
771 * checks to tell if the user should be accessing a section or not |
700 * {@see current_user_can()}. |
772 * current_user_can(). |
701 * |
773 * |
702 * @since 3.1.0 |
774 * @since 3.1.0 |
775 * |
|
776 * @global WP_Screen $current_screen |
|
703 * |
777 * |
704 * @return bool True if inside WordPress user administration pages. |
778 * @return bool True if inside WordPress user administration pages. |
705 */ |
779 */ |
706 function is_user_admin() { |
780 function is_user_admin() { |
707 if ( isset( $GLOBALS['current_screen'] ) ) |
781 if ( isset( $GLOBALS['current_screen'] ) ) |
728 |
802 |
729 return false; |
803 return false; |
730 } |
804 } |
731 |
805 |
732 /** |
806 /** |
733 * Retrieve the current blog ID. |
807 * Retrieve the current site ID. |
734 * |
808 * |
735 * @since 3.1.0 |
809 * @since 3.1.0 |
736 * |
810 * |
737 * @return int Blog id |
811 * @global int $blog_id |
812 * |
|
813 * @return int Site ID. |
|
738 */ |
814 */ |
739 function get_current_blog_id() { |
815 function get_current_blog_id() { |
740 global $blog_id; |
816 global $blog_id; |
741 return absint($blog_id); |
817 return absint($blog_id); |
742 } |
818 } |
743 |
819 |
744 /** |
820 /** |
821 * Retrieves the current network ID. |
|
822 * |
|
823 * @since 4.6.0 |
|
824 * |
|
825 * @return int The ID of the current network. |
|
826 */ |
|
827 function get_current_network_id() { |
|
828 if ( ! is_multisite() ) { |
|
829 return 1; |
|
830 } |
|
831 |
|
832 $current_network = get_network(); |
|
833 |
|
834 if ( ! isset( $current_network->id ) ) { |
|
835 return get_main_network_id(); |
|
836 } |
|
837 |
|
838 return absint( $current_network->id ); |
|
839 } |
|
840 |
|
841 /** |
|
745 * Attempt an early load of translations. |
842 * Attempt an early load of translations. |
746 * |
843 * |
747 * Used for errors encountered during the initial loading process, before |
844 * Used for errors encountered during the initial loading process, before |
748 * the locale has been properly detected and loaded. |
845 * the locale has been properly detected and loaded. |
749 * |
846 * |
752 * that a file can be double-included. |
849 * that a file can be double-included. |
753 * |
850 * |
754 * @since 3.4.0 |
851 * @since 3.4.0 |
755 * @access private |
852 * @access private |
756 * |
853 * |
757 * @global $wp_locale The WordPress date and time locale object. |
854 * @global WP_Locale $wp_locale The WordPress date and time locale object. |
855 * |
|
856 * @staticvar bool $loaded |
|
758 */ |
857 */ |
759 function wp_load_translations_early() { |
858 function wp_load_translations_early() { |
760 global $text_direction, $wp_locale; |
859 global $wp_locale; |
761 |
860 |
762 static $loaded = false; |
861 static $loaded = false; |
763 if ( $loaded ) |
862 if ( $loaded ) |
764 return; |
863 return; |
765 $loaded = true; |
864 $loaded = true; |
771 require ABSPATH . WPINC . '/version.php'; |
870 require ABSPATH . WPINC . '/version.php'; |
772 |
871 |
773 // Translation and localization |
872 // Translation and localization |
774 require_once ABSPATH . WPINC . '/pomo/mo.php'; |
873 require_once ABSPATH . WPINC . '/pomo/mo.php'; |
775 require_once ABSPATH . WPINC . '/l10n.php'; |
874 require_once ABSPATH . WPINC . '/l10n.php'; |
776 require_once ABSPATH . WPINC . '/locale.php'; |
875 require_once ABSPATH . WPINC . '/class-wp-locale.php'; |
876 require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; |
|
777 |
877 |
778 // General libraries |
878 // General libraries |
779 require_once ABSPATH . WPINC . '/plugin.php'; |
879 require_once ABSPATH . WPINC . '/plugin.php'; |
780 |
880 |
781 $locales = $locations = array(); |
881 $locales = $locations = array(); |
824 break; |
924 break; |
825 } |
925 } |
826 |
926 |
827 $wp_locale = new WP_Locale(); |
927 $wp_locale = new WP_Locale(); |
828 } |
928 } |
929 |
|
930 /** |
|
931 * Check or set whether WordPress is in "installation" mode. |
|
932 * |
|
933 * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`. |
|
934 * |
|
935 * @since 4.4.0 |
|
936 * |
|
937 * @staticvar bool $installing |
|
938 * |
|
939 * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off. |
|
940 * Omit this parameter if you only want to fetch the current status. |
|
941 * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will |
|
942 * report whether WP was in installing mode prior to the change to `$is_installing`. |
|
943 */ |
|
944 function wp_installing( $is_installing = null ) { |
|
945 static $installing = null; |
|
946 |
|
947 // Support for the `WP_INSTALLING` constant, defined before WP is loaded. |
|
948 if ( is_null( $installing ) ) { |
|
949 $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING; |
|
950 } |
|
951 |
|
952 if ( ! is_null( $is_installing ) ) { |
|
953 $old_installing = $installing; |
|
954 $installing = $is_installing; |
|
955 return (bool) $old_installing; |
|
956 } |
|
957 |
|
958 return (bool) $installing; |
|
959 } |
|
960 |
|
961 /** |
|
962 * Determines if SSL is used. |
|
963 * |
|
964 * @since 2.6.0 |
|
965 * @since 4.6.0 Moved from functions.php to load.php. |
|
966 * |
|
967 * @return bool True if SSL, otherwise false. |
|
968 */ |
|
969 function is_ssl() { |
|
970 if ( isset( $_SERVER['HTTPS'] ) ) { |
|
971 if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) { |
|
972 return true; |
|
973 } |
|
974 |
|
975 if ( '1' == $_SERVER['HTTPS'] ) { |
|
976 return true; |
|
977 } |
|
978 } elseif ( isset($_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { |
|
979 return true; |
|
980 } |
|
981 return false; |
|
982 } |
|
983 |
|
984 /** |
|
985 * Converts a shorthand byte value to an integer byte value. |
|
986 * |
|
987 * @since 2.3.0 |
|
988 * @since 4.6.0 Moved from media.php to load.php. |
|
989 * |
|
990 * @link https://secure.php.net/manual/en/function.ini-get.php |
|
991 * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes |
|
992 * |
|
993 * @param string $value A (PHP ini) byte value, either shorthand or ordinary. |
|
994 * @return int An integer byte value. |
|
995 */ |
|
996 function wp_convert_hr_to_bytes( $value ) { |
|
997 $value = strtolower( trim( $value ) ); |
|
998 $bytes = (int) $value; |
|
999 |
|
1000 if ( false !== strpos( $value, 'g' ) ) { |
|
1001 $bytes *= GB_IN_BYTES; |
|
1002 } elseif ( false !== strpos( $value, 'm' ) ) { |
|
1003 $bytes *= MB_IN_BYTES; |
|
1004 } elseif ( false !== strpos( $value, 'k' ) ) { |
|
1005 $bytes *= KB_IN_BYTES; |
|
1006 } |
|
1007 |
|
1008 // Deal with large (float) values which run into the maximum integer size. |
|
1009 return min( $bytes, PHP_INT_MAX ); |
|
1010 } |
|
1011 |
|
1012 /** |
|
1013 * Determines whether a PHP ini value is changeable at runtime. |
|
1014 * |
|
1015 * @since 4.6.0 |
|
1016 * |
|
1017 * @staticvar array $ini_all |
|
1018 * |
|
1019 * @link https://secure.php.net/manual/en/function.ini-get-all.php |
|
1020 * |
|
1021 * @param string $setting The name of the ini setting to check. |
|
1022 * @return bool True if the value is changeable at runtime. False otherwise. |
|
1023 */ |
|
1024 function wp_is_ini_value_changeable( $setting ) { |
|
1025 static $ini_all; |
|
1026 |
|
1027 if ( ! isset( $ini_all ) ) { |
|
1028 $ini_all = false; |
|
1029 // Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes". |
|
1030 if ( function_exists( 'ini_get_all' ) ) { |
|
1031 $ini_all = ini_get_all(); |
|
1032 } |
|
1033 } |
|
1034 |
|
1035 // 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. |
|
1036 if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) { |
|
1037 return true; |
|
1038 } |
|
1039 |
|
1040 // If we were unable to retrieve the details, fail gracefully to assume it's changeable. |
|
1041 if ( ! is_array( $ini_all ) ) { |
|
1042 return true; |
|
1043 } |
|
1044 |
|
1045 return false; |
|
1046 } |
|
1047 |
|
1048 /** |
|
1049 * Determines whether the current request is a WordPress Ajax request. |
|
1050 * |
|
1051 * @since 4.7.0 |
|
1052 * |
|
1053 * @return bool True if it's a WordPress Ajax request, false otherwise. |
|
1054 */ |
|
1055 function wp_doing_ajax() { |
|
1056 /** |
|
1057 * Filters whether the current request is a WordPress Ajax request. |
|
1058 * |
|
1059 * @since 4.7.0 |
|
1060 * |
|
1061 * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request. |
|
1062 */ |
|
1063 return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
1064 } |
|
1065 |
|
1066 /** |
|
1067 * Determines whether the current request is a WordPress cron request. |
|
1068 * |
|
1069 * @since 4.8.0 |
|
1070 * |
|
1071 * @return bool True if it's a WordPress cron request, false otherwise. |
|
1072 */ |
|
1073 function wp_doing_cron() { |
|
1074 /** |
|
1075 * Filters whether the current request is a WordPress cron request. |
|
1076 * |
|
1077 * @since 4.8.0 |
|
1078 * |
|
1079 * @param bool $wp_doing_cron Whether the current request is a WordPress cron request. |
|
1080 */ |
|
1081 return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON ); |
|
1082 } |
|
1083 |
|
1084 /** |
|
1085 * Check whether variable is a WordPress Error. |
|
1086 * |
|
1087 * Returns true if $thing is an object of the WP_Error class. |
|
1088 * |
|
1089 * @since 2.1.0 |
|
1090 * |
|
1091 * @param mixed $thing Check if unknown variable is a WP_Error object. |
|
1092 * @return bool True, if WP_Error. False, if not WP_Error. |
|
1093 */ |
|
1094 function is_wp_error( $thing ) { |
|
1095 return ( $thing instanceof WP_Error ); |
|
1096 } |
|
1097 |
|
1098 /** |
|
1099 * Determines whether file modifications are allowed. |
|
1100 * |
|
1101 * @since 4.8.0 |
|
1102 * |
|
1103 * @param string $context The usage context. |
|
1104 * @return bool True if file modification is allowed, false otherwise. |
|
1105 */ |
|
1106 function wp_is_file_mod_allowed( $context ) { |
|
1107 /** |
|
1108 * Filters whether file modifications are allowed. |
|
1109 * |
|
1110 * @since 4.8.0 |
|
1111 * |
|
1112 * @param bool $file_mod_allowed Whether file modifications are allowed. |
|
1113 * @param string $context The usage context. |
|
1114 */ |
|
1115 return apply_filters( 'file_mod_allowed', ! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS, $context ); |
|
1116 } |
|
1117 |
|
1118 /** |
|
1119 * Start scraping edited file errors. |
|
1120 * |
|
1121 * @since 4.9.0 |
|
1122 */ |
|
1123 function wp_start_scraping_edited_file_errors() { |
|
1124 if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) { |
|
1125 return; |
|
1126 } |
|
1127 $key = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 ); |
|
1128 $nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] ); |
|
1129 |
|
1130 if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) { |
|
1131 echo "###### wp_scraping_result_start:$key ######"; |
|
1132 echo wp_json_encode( array( |
|
1133 'code' => 'scrape_nonce_failure', |
|
1134 'message' => __( 'Scrape nonce check failed. Please try again.' ), |
|
1135 ) ); |
|
1136 echo "###### wp_scraping_result_end:$key ######"; |
|
1137 die(); |
|
1138 } |
|
1139 register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key ); |
|
1140 } |
|
1141 |
|
1142 /** |
|
1143 * Finalize scraping for edited file errors. |
|
1144 * |
|
1145 * @since 4.9.0 |
|
1146 * |
|
1147 * @param string $scrape_key Scrape key. |
|
1148 */ |
|
1149 function wp_finalize_scraping_edited_file_errors( $scrape_key ) { |
|
1150 $error = error_get_last(); |
|
1151 echo "\n###### wp_scraping_result_start:$scrape_key ######\n"; |
|
1152 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 ) ) { |
|
1153 $error = str_replace( ABSPATH, '', $error ); |
|
1154 echo wp_json_encode( $error ); |
|
1155 } else { |
|
1156 echo wp_json_encode( true ); |
|
1157 } |
|
1158 echo "\n###### wp_scraping_result_end:$scrape_key ######\n"; |
|
1159 } |