3 * These functions are needed to load WordPress.
9 * Return the HTTP protocol sent by the server.
13 * @return string The HTTP protocol. Default: HTTP/1.0.
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';
24 * Turn register globals off.
29 function wp_unregister_GLOBALS() {
30 if ( !ini_get( 'register_globals' ) )
33 if ( isset( $_REQUEST['GLOBALS'] ) )
34 die( 'GLOBALS overwrite attempt detected' );
36 // Variables that shouldn't be unset
37 $no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix' );
39 $input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() );
40 foreach ( $input as $k => $v )
41 if ( !in_array( $k, $no_unset ) && isset( $GLOBALS[$k] ) ) {
42 unset( $GLOBALS[$k] );
47 * Fix `$_SERVER` variables for various setups.
52 * @global string $PHP_SELF The filename of the currently executing script,
53 * relative to the document root.
55 function wp_fix_server_vars() {
58 $default_server_values = array(
59 'SERVER_SOFTWARE' => '',
63 $_SERVER = array_merge( $default_server_values, $_SERVER );
65 // Fix for IIS when running with PHP ISAPI
66 if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
69 if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
70 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
73 elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
74 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
76 // Use ORIG_PATH_INFO if there is no PATH_INFO
77 if ( !isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) )
78 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
80 // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
81 if ( isset( $_SERVER['PATH_INFO'] ) ) {
82 if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
83 $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
85 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
88 // Append the query string if it exists and isn't null
89 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
90 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
95 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
96 if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) )
97 $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
99 // Fix for Dreamhost and other PHP as CGI hosts
100 if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false )
101 unset( $_SERVER['PATH_INFO'] );
103 // Fix empty PHP_SELF
104 $PHP_SELF = $_SERVER['PHP_SELF'];
105 if ( empty( $PHP_SELF ) )
106 $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );
110 * Check for the required PHP version, and the MySQL extension or
111 * a database drop-in.
113 * Dies if requirements are not met.
118 * @global string $required_php_version The required PHP version string.
119 * @global string $wp_version The WordPress version string.
121 function wp_check_php_mysql_versions() {
122 global $required_php_version, $wp_version;
123 $php_version = phpversion();
125 if ( version_compare( $required_php_version, $php_version, '>' ) ) {
126 wp_load_translations_early();
128 $protocol = wp_get_server_protocol();
129 header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
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 */
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 ) );
135 if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
136 wp_load_translations_early();
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' );
141 die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) );
146 * Don't load all of WordPress when handling a favicon.ico request.
148 * Instead, send the headers for a zero-length favicon and bail.
152 function wp_favicon_request() {
153 if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
154 header('Content-Type: image/vnd.microsoft.icon');
160 * Die with a maintenance message when conditions are met.
162 * Checks for a file in the WordPress root directory named ".maintenance".
163 * This file will contain the variable $upgrading, set to the time the file
164 * was created. If the file was created less than 10 minutes ago, WordPress
165 * enters maintenance mode and displays a message.
167 * The default message can be replaced by using a drop-in (maintenance.php in
168 * the wp-content directory).
173 * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
175 function wp_maintenance() {
176 if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() )
181 include( ABSPATH . '.maintenance' );
182 // If the $upgrading timestamp is older than 10 minutes, don't die.
183 if ( ( time() - $upgrading ) >= 600 )
187 * Filters whether to enable maintenance mode.
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.
196 * @param bool $enable_checks Whether to enable maintenance mode. Default true.
197 * @param int $upgrading The timestamp set in the .maintenance file.
199 if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
203 if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
204 require_once( WP_CONTENT_DIR . '/maintenance.php' );
208 wp_load_translations_early();
210 $protocol = wp_get_server_protocol();
211 header( "$protocol 503 Service Unavailable", true, 503 );
212 header( 'Content-Type: text/html; charset=utf-8' );
213 header( 'Retry-After: 600' );
216 <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
218 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
219 <title><?php _e( 'Maintenance' ); ?></title>
223 <h1><?php _e( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ); ?></h1>
231 * Start the WordPress micro-timer.
236 * @global float $timestart Unix timestamp set at the beginning of the page load.
239 * @return bool Always returns true.
241 function timer_start() {
243 $timestart = microtime( true );
248 * Retrieve or display the time from the page start to when function is called.
252 * @global float $timestart Seconds from when timer_start() is called.
253 * @global float $timeend Seconds from when function is called.
255 * @param int|bool $display Whether to echo or return the results. Accepts 0|false for return,
256 * 1|true for echo. Default 0|false.
257 * @param int $precision The number of digits from the right of the decimal to display.
259 * @return string The "second.microsecond" finished time calculation. The number is formatted
260 * for human consumption, both localized and rounded.
262 function timer_stop( $display = 0, $precision = 3 ) {
263 global $timestart, $timeend;
264 $timeend = microtime( true );
265 $timetotal = $timeend - $timestart;
266 $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
273 * Set PHP error reporting based on WordPress debug settings.
275 * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`.
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.
279 * When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also
280 * display internal notices: when a deprecated WordPress function, function
281 * argument, or file is used. Deprecated code may be removed from a later
284 * It is strongly recommended that plugin and theme developers use `WP_DEBUG`
285 * in their development environments.
287 * `WP_DEBUG_DISPLAY` and `WP_DEBUG_LOG` perform no function unless `WP_DEBUG`
290 * When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed.
291 * `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress
292 * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY`
293 * as false will force errors to be hidden.
295 * When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content
298 * Errors are never displayed for XML-RPC, REST, and Ajax requests.
303 function wp_debug_mode() {
305 * Filters whether to allow the debug mode check to occur.
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.
314 * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true.
316 if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ){
321 error_reporting( E_ALL );
323 if ( WP_DEBUG_DISPLAY )
324 ini_set( 'display_errors', 1 );
325 elseif ( null !== WP_DEBUG_DISPLAY )
326 ini_set( 'display_errors', 0 );
328 if ( WP_DEBUG_LOG ) {
329 ini_set( 'log_errors', 1 );
330 ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
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 );
336 if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
337 @ini_set( 'display_errors', 0 );
342 * Set the location of the language directory.
344 * To set directory manually, define the `WP_LANG_DIR` constant
347 * If the language directory exists within `WP_CONTENT_DIR`, it
348 * is used. Otherwise the language directory is assumed to live
354 function wp_set_lang_dir() {
355 if ( !defined( 'WP_LANG_DIR' ) ) {
356 if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || !@is_dir(ABSPATH . WPINC . '/languages') ) {
358 * Server path of the language directory.
360 * No leading slash, no trailing slash, full path, not relative to ABSPATH
364 define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
365 if ( !defined( 'LANGDIR' ) ) {
366 // Old static relative path maintained for limited backward compatibility - won't work in some cases.
367 define( 'LANGDIR', 'wp-content/languages' );
371 * Server path of the language directory.
373 * No leading slash, no trailing slash, full path, not relative to `ABSPATH`.
377 define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' );
378 if ( !defined( 'LANGDIR' ) ) {
379 // Old relative path maintained for backward compatibility.
380 define( 'LANGDIR', WPINC . '/languages' );
387 * Load the database class file and instantiate the `$wpdb` global.
391 * @global wpdb $wpdb The WordPress database class.
393 function require_wp_db() {
396 require_once( ABSPATH . WPINC . '/wp-db.php' );
397 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
398 require_once( WP_CONTENT_DIR . '/db.php' );
400 if ( isset( $wpdb ) ) {
404 $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
408 * Set the database table prefix and the format specifiers for database
411 * Columns not listed here default to `%s`.
416 * @global wpdb $wpdb The WordPress database class.
417 * @global string $table_prefix The database table prefix.
419 function wp_set_wpdb_vars() {
420 global $wpdb, $table_prefix;
421 if ( !empty( $wpdb->error ) )
424 $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
425 'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'comment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
426 'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
427 'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d',
429 'active' => '%d', 'cat_id' => '%d', 'deleted' => '%d', 'lang_id' => '%d', 'mature' => '%d', 'public' => '%d', 'site_id' => '%d', 'spam' => '%d',
432 $prefix = $wpdb->set_prefix( $table_prefix );
434 if ( is_wp_error( $prefix ) ) {
435 wp_load_translations_early();
437 /* translators: 1: $table_prefix 2: wp-config.php */
438 sprintf( __( '<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ),
439 '<code>$table_prefix</code>',
440 '<code>wp-config.php</code>'
447 * Toggle `$_wp_using_ext_object_cache` on and off without directly
452 * @global bool $_wp_using_ext_object_cache
454 * @param bool $using Whether external object cache is being used.
455 * @return bool The current 'using' setting.
457 function wp_using_ext_object_cache( $using = null ) {
458 global $_wp_using_ext_object_cache;
459 $current_using = $_wp_using_ext_object_cache;
460 if ( null !== $using )
461 $_wp_using_ext_object_cache = $using;
462 return $current_using;
466 * Start the WordPress object cache.
468 * If an object-cache.php file exists in the wp-content directory,
469 * it uses that drop-in as an external object cache.
474 function wp_start_object_cache() {
478 if ( ! function_exists( 'wp_cache_init' ) ) {
479 if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
480 require_once ( WP_CONTENT_DIR . '/object-cache.php' );
481 if ( function_exists( 'wp_cache_init' ) ) {
482 wp_using_ext_object_cache( true );
485 // Re-initialize any hooks added manually by object-cache.php
487 $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
492 } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
494 * Sometimes advanced-cache.php can load object-cache.php before
495 * it is loaded here. This breaks the function_exists check above
496 * and can result in `$_wp_using_ext_object_cache` being set
497 * incorrectly. Double check if an external cache exists.
499 wp_using_ext_object_cache( true );
502 if ( ! wp_using_ext_object_cache() ) {
503 require_once ( ABSPATH . WPINC . '/cache.php' );
507 * If cache supports reset, reset instead of init if already
508 * initialized. Reset signals to the cache that global IDs
509 * have changed and it may need to update keys and cleanup caches.
511 if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) {
512 wp_cache_switch_to_blog( get_current_blog_id() );
513 } elseif ( function_exists( 'wp_cache_init' ) ) {
517 if ( function_exists( 'wp_cache_add_global_groups' ) ) {
518 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
519 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
524 * Redirect to the installer if WordPress is not installed.
526 * Dies with an error message when Multisite is enabled.
531 function wp_not_installed() {
532 if ( is_multisite() ) {
533 if ( ! is_blog_installed() && ! wp_installing() ) {
536 wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
538 } elseif ( ! is_blog_installed() && ! wp_installing() ) {
541 require( ABSPATH . WPINC . '/kses.php' );
542 require( ABSPATH . WPINC . '/pluggable.php' );
543 require( ABSPATH . WPINC . '/formatting.php' );
545 $link = wp_guess_url() . '/wp-admin/install.php';
547 wp_redirect( $link );
553 * Retrieve an array of must-use plugin files.
555 * The default directory is wp-content/mu-plugins. To change the default
556 * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL`
562 * @return array Files to include.
564 function wp_get_mu_plugins() {
565 $mu_plugins = array();
566 if ( !is_dir( WPMU_PLUGIN_DIR ) )
568 if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) )
570 while ( ( $plugin = readdir( $dh ) ) !== false ) {
571 if ( substr( $plugin, -4 ) == '.php' )
572 $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
581 * Retrieve an array of active and valid plugin files.
583 * While upgrading or installing WordPress, no plugins are returned.
585 * The default directory is wp-content/plugins. To change the default
586 * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL`
592 * @return array Files.
594 function wp_get_active_and_valid_plugins() {
596 $active_plugins = (array) get_option( 'active_plugins', array() );
598 // Check for hacks file if the option is enabled
599 if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
600 _deprecated_file( 'my-hacks.php', '1.5.0' );
601 array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
604 if ( empty( $active_plugins ) || wp_installing() )
607 $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
609 foreach ( $active_plugins as $plugin ) {
610 if ( ! validate_file( $plugin ) // $plugin must validate as file
611 && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
612 && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
613 // not already included as a network plugin
614 && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
616 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
622 * Set internal encoding.
624 * In most cases the default internal encoding is latin1, which is
625 * of no use, since we want to use the `mb_` functions for `utf-8` strings.
630 function wp_set_internal_encoding() {
631 if ( function_exists( 'mb_internal_encoding' ) ) {
632 $charset = get_option( 'blog_charset' );
633 if ( ! $charset || ! @mb_internal_encoding( $charset ) )
634 mb_internal_encoding( 'UTF-8' );
639 * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`.
641 * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`,
642 * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly.
647 function wp_magic_quotes() {
648 // If already slashed, strip.
649 if ( get_magic_quotes_gpc() ) {
650 $_GET = stripslashes_deep( $_GET );
651 $_POST = stripslashes_deep( $_POST );
652 $_COOKIE = stripslashes_deep( $_COOKIE );
656 $_GET = add_magic_quotes( $_GET );
657 $_POST = add_magic_quotes( $_POST );
658 $_COOKIE = add_magic_quotes( $_COOKIE );
659 $_SERVER = add_magic_quotes( $_SERVER );
661 // Force REQUEST to be GET + POST.
662 $_REQUEST = array_merge( $_GET, $_POST );
666 * Runs just before PHP shuts down execution.
671 function shutdown_action_hook() {
673 * Fires just before PHP shuts down execution.
677 do_action( 'shutdown' );
688 * @param object $object The object to clone.
689 * @return object The cloned object.
691 function wp_clone( $object ) {
692 // Use parens for clone to accommodate PHP 4. See #17880
693 return clone( $object );
697 * Whether the current request is for an administrative interface page.
699 * Does not check if the user is an administrator; current_user_can()
700 * for checking roles and capabilities.
704 * @global WP_Screen $current_screen
706 * @return bool True if inside WordPress administration interface, false otherwise.
708 function is_admin() {
709 if ( isset( $GLOBALS['current_screen'] ) )
710 return $GLOBALS['current_screen']->in_admin();
711 elseif ( defined( 'WP_ADMIN' ) )
718 * Whether the current request is for a site's admininstrative interface.
722 * Does not check if the user is an administrator; current_user_can()
723 * for checking roles and capabilities.
727 * @global WP_Screen $current_screen
729 * @return bool True if inside WordPress blog administration pages.
731 function is_blog_admin() {
732 if ( isset( $GLOBALS['current_screen'] ) )
733 return $GLOBALS['current_screen']->in_admin( 'site' );
734 elseif ( defined( 'WP_BLOG_ADMIN' ) )
735 return WP_BLOG_ADMIN;
741 * Whether the current request is for the network administrative interface.
743 * e.g. `/wp-admin/network/`
745 * Does not check if the user is an administrator; current_user_can()
746 * for checking roles and capabilities.
750 * @global WP_Screen $current_screen
752 * @return bool True if inside WordPress network administration pages.
754 function is_network_admin() {
755 if ( isset( $GLOBALS['current_screen'] ) )
756 return $GLOBALS['current_screen']->in_admin( 'network' );
757 elseif ( defined( 'WP_NETWORK_ADMIN' ) )
758 return WP_NETWORK_ADMIN;
764 * Whether the current request is for a user admin screen.
766 * e.g. `/wp-admin/user/`
768 * Does not inform on whether the user is an admin! Use capability
769 * checks to tell if the user should be accessing a section or not
770 * current_user_can().
774 * @global WP_Screen $current_screen
776 * @return bool True if inside WordPress user administration pages.
778 function is_user_admin() {
779 if ( isset( $GLOBALS['current_screen'] ) )
780 return $GLOBALS['current_screen']->in_admin( 'user' );
781 elseif ( defined( 'WP_USER_ADMIN' ) )
782 return WP_USER_ADMIN;
788 * If Multisite is enabled.
792 * @return bool True if Multisite is enabled, false otherwise.
794 function is_multisite() {
795 if ( defined( 'MULTISITE' ) )
798 if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) )
805 * Retrieve the current site ID.
809 * @global int $blog_id
811 * @return int Site ID.
813 function get_current_blog_id() {
815 return absint($blog_id);
819 * Retrieves the current network ID.
823 * @return int The ID of the current network.
825 function get_current_network_id() {
826 if ( ! is_multisite() ) {
830 $current_network = get_network();
832 if ( ! isset( $current_network->id ) ) {
833 return get_main_network_id();
836 return absint( $current_network->id );
840 * Attempt an early load of translations.
842 * Used for errors encountered during the initial loading process, before
843 * the locale has been properly detected and loaded.
845 * Designed for unusual load sequences (like setup-config.php) or for when
846 * the script will then terminate with an error, otherwise there is a risk
847 * that a file can be double-included.
852 * @global WP_Locale $wp_locale The WordPress date and time locale object.
854 * @staticvar bool $loaded
856 function wp_load_translations_early() {
859 static $loaded = false;
864 if ( function_exists( 'did_action' ) && did_action( 'init' ) )
867 // We need $wp_local_package
868 require ABSPATH . WPINC . '/version.php';
870 // Translation and localization
871 require_once ABSPATH . WPINC . '/pomo/mo.php';
872 require_once ABSPATH . WPINC . '/l10n.php';
873 require_once ABSPATH . WPINC . '/class-wp-locale.php';
874 require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php';
877 require_once ABSPATH . WPINC . '/plugin.php';
879 $locales = $locations = array();
882 if ( defined( 'WPLANG' ) ) {
888 if ( isset( $wp_local_package ) )
889 $locales[] = $wp_local_package;
894 if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) )
895 $locations[] = WP_LANG_DIR;
897 if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) )
898 $locations[] = WP_CONTENT_DIR . '/languages';
900 if ( @is_dir( ABSPATH . 'wp-content/languages' ) )
901 $locations[] = ABSPATH . 'wp-content/languages';
903 if ( @is_dir( ABSPATH . WPINC . '/languages' ) )
904 $locations[] = ABSPATH . WPINC . '/languages';
909 $locations = array_unique( $locations );
911 foreach ( $locales as $locale ) {
912 foreach ( $locations as $location ) {
913 if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
914 load_textdomain( 'default', $location . '/' . $locale . '.mo' );
915 if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) )
916 load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' );
925 $wp_locale = new WP_Locale();
929 * Check or set whether WordPress is in "installation" mode.
931 * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`.
935 * @staticvar bool $installing
937 * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off.
938 * Omit this parameter if you only want to fetch the current status.
939 * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will
940 * report whether WP was in installing mode prior to the change to `$is_installing`.
942 function wp_installing( $is_installing = null ) {
943 static $installing = null;
945 // Support for the `WP_INSTALLING` constant, defined before WP is loaded.
946 if ( is_null( $installing ) ) {
947 $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING;
950 if ( ! is_null( $is_installing ) ) {
951 $old_installing = $installing;
952 $installing = $is_installing;
953 return (bool) $old_installing;
956 return (bool) $installing;
960 * Determines if SSL is used.
963 * @since 4.6.0 Moved from functions.php to load.php.
965 * @return bool True if SSL, otherwise false.
968 if ( isset( $_SERVER['HTTPS'] ) ) {
969 if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
973 if ( '1' == $_SERVER['HTTPS'] ) {
976 } elseif ( isset($_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
983 * Converts a shorthand byte value to an integer byte value.
986 * @since 4.6.0 Moved from media.php to load.php.
988 * @link https://secure.php.net/manual/en/function.ini-get.php
989 * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
991 * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
992 * @return int An integer byte value.
994 function wp_convert_hr_to_bytes( $value ) {
995 $value = strtolower( trim( $value ) );
996 $bytes = (int) $value;
998 if ( false !== strpos( $value, 'g' ) ) {
999 $bytes *= GB_IN_BYTES;
1000 } elseif ( false !== strpos( $value, 'm' ) ) {
1001 $bytes *= MB_IN_BYTES;
1002 } elseif ( false !== strpos( $value, 'k' ) ) {
1003 $bytes *= KB_IN_BYTES;
1006 // Deal with large (float) values which run into the maximum integer size.
1007 return min( $bytes, PHP_INT_MAX );
1011 * Determines whether a PHP ini value is changeable at runtime.
1015 * @link https://secure.php.net/manual/en/function.ini-get-all.php
1017 * @param string $setting The name of the ini setting to check.
1018 * @return bool True if the value is changeable at runtime. False otherwise.
1020 function wp_is_ini_value_changeable( $setting ) {
1023 if ( ! isset( $ini_all ) ) {
1025 // Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes".
1026 if ( function_exists( 'ini_get_all' ) ) {
1027 $ini_all = ini_get_all();
1031 // 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.
1032 if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) {
1036 // If we were unable to retrieve the details, fail gracefully to assume it's changeable.
1037 if ( ! is_array( $ini_all ) ) {
1045 * Determines whether the current request is a WordPress Ajax request.
1049 * @return bool True if it's a WordPress Ajax request, false otherwise.
1051 function wp_doing_ajax() {
1053 * Filters whether the current request is a WordPress Ajax request.
1057 * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
1059 return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
1063 * Check whether variable is a WordPress Error.
1065 * Returns true if $thing is an object of the WP_Error class.
1069 * @param mixed $thing Check if unknown variable is a WP_Error object.
1070 * @return bool True, if WP_Error. False, if not WP_Error.
1072 function is_wp_error( $thing ) {
1073 return ( $thing instanceof WP_Error );