diff --git a/wp-admin/admin.php b/wp-admin/admin.php index d3e58d2549..184d5c2731 100644 --- a/wp-admin/admin.php +++ b/wp-admin/admin.php @@ -84,7 +84,7 @@ require_once(ABSPATH . 'wp-admin/includes/admin.php'); auth_redirect(); // Schedule trash collection -if ( !wp_next_scheduled('wp_scheduled_delete') && !defined('WP_INSTALLING') ) +if ( ! wp_next_scheduled( 'wp_scheduled_delete' ) && ! wp_installing() ) wp_schedule_event(time(), 'daily', 'wp_scheduled_delete'); set_screen_options(); diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 5b005ec30c..3ca66b8908 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -2604,7 +2604,7 @@ class WP_Automatic_Updater { if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) return true; - if ( defined( 'WP_INSTALLING' ) ) + if ( wp_installing() ) return true; // More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters. diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index a11bc95851..6fa47806db 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -1081,7 +1081,7 @@ function request_filesystem_credentials($form_post, $type = '', $error = false, $stored_credentials['hostname'] .= ':' . $stored_credentials['port']; unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']); - if ( ! defined( 'WP_INSTALLING' ) ) { + if ( ! wp_installing() ) { update_option( 'ftp_credentials', $stored_credentials ); } return $credentials; diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index e2cf976d28..776f04c968 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -261,7 +261,7 @@ function update_recently_edited( $file ) { * @param string $value */ function update_home_siteurl( $old_value, $value ) { - if ( defined( "WP_INSTALLING" ) ) + if ( wp_installing() ) return; if ( is_multisite() && ms_is_switched() ) { diff --git a/wp-admin/includes/translation-install.php b/wp-admin/includes/translation-install.php index 8e1b827c47..2056838f00 100644 --- a/wp-admin/includes/translation-install.php +++ b/wp-admin/includes/translation-install.php @@ -94,7 +94,7 @@ function translations_api( $type, $args = null ) { * in an error, an empty array will be returned. */ function wp_get_available_translations() { - if ( ! defined( 'WP_INSTALLING' ) && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) { + if ( ! wp_installing() && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) { return $translations; } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index a643d7ccb3..b6158ed261 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1259,6 +1259,37 @@ function do_robots() { echo apply_filters( 'robots_txt', $output, $public ); } +/** + * Check or set whether WordPress is in "installation" mode. + * + * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`. + * + * @since 4.4.0 + * + * @staticvar bool $installing + * + * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off. + * Omit this parameter if you only want to fetch the current status. + * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will + * report whether WP was in installing mode prior to the change to `$is_installing`. + */ +function wp_installing( $is_installing = null ) { + static $installing = null; + + // Support for the `WP_INSTALLING` constant, defined before WP is loaded. + if ( is_null( $installing ) ) { + $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING; + } + + if ( ! is_null( $is_installing ) ) { + $old_installing = $installing; + $installing = $is_installing; + return (bool) $old_installing; + } + + return (bool) $installing; +} + /** * Test whether blog is already installed. * @@ -1285,7 +1316,7 @@ function is_blog_installed() { return true; $suppress = $wpdb->suppress_errors(); - if ( ! defined( 'WP_INSTALLING' ) ) { + if ( ! wp_installing() ) { $alloptions = wp_load_alloptions(); } // If siteurl is not set to autoload, check it specifically @@ -3337,7 +3368,7 @@ function dead_db() { } // If installing or in the admin, provide the verbose message. - if ( defined('WP_INSTALLING') || defined('WP_ADMIN') ) + if ( wp_installing() || defined( 'WP_ADMIN' ) ) wp_die($wpdb->error); // Otherwise, be terse. diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index b30fa417aa..2af07f17a0 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -53,7 +53,7 @@ function get_locale() { // If multisite, check options. if ( is_multisite() ) { // Don't check blog option when installing. - if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) { + if ( wp_installing() || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) { $ms_locale = get_network_option( 'WPLANG' ); } @@ -635,7 +635,7 @@ function load_default_textdomain( $locale = null ) { return $return; } - if ( is_admin() || defined( 'WP_INSTALLING' ) || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) { + if ( is_admin() || wp_installing() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) { load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" ); } diff --git a/wp-includes/load.php b/wp-includes/load.php index 560511a953..90db8290db 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -165,7 +165,7 @@ function wp_favicon_request() { * @global int $upgrading the unix timestamp marking when upgrading WordPress began. */ function wp_maintenance() { - if ( !file_exists( ABSPATH . '.maintenance' ) || defined( 'WP_INSTALLING' ) ) + if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) return; global $upgrading; @@ -475,12 +475,12 @@ function wp_start_object_cache() { */ function wp_not_installed() { if ( is_multisite() ) { - if ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) ) { + if ( ! is_blog_installed() && ! wp_installing() ) { nocache_headers(); wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) ); } - } elseif ( ! is_blog_installed() && ! defined( 'WP_INSTALLING' ) ) { + } elseif ( ! is_blog_installed() && ! wp_installing() ) { nocache_headers(); require( ABSPATH . WPINC . '/kses.php' ); @@ -539,7 +539,7 @@ function wp_get_mu_plugins() { function wp_get_active_and_valid_plugins() { $plugins = array(); $active_plugins = (array) get_option( 'active_plugins', array() ); - if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) ) + if ( empty( $active_plugins ) || wp_installing() ) return $plugins; $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php index 2aeda64fdf..ae5a242afa 100644 --- a/wp-includes/ms-functions.php +++ b/wp-includes/ms-functions.php @@ -1116,8 +1116,9 @@ function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $s if ( domain_exists($domain, $path, $site_id) ) return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) ); - if ( !defined('WP_INSTALLING') ) - define( 'WP_INSTALLING', true ); + if ( ! wp_installing() ) { + wp_installing( true ); + } if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) return new WP_Error('insert_blog', __('Could not create site.')); @@ -2172,7 +2173,7 @@ function wp_schedule_update_network_counts() { if ( !is_main_site() ) return; - if ( !wp_next_scheduled('update_network_counts') && !defined('WP_INSTALLING') ) + if ( ! wp_next_scheduled('update_network_counts') && ! wp_installing() ) wp_schedule_event(time(), 'twicedaily', 'update_network_counts'); } diff --git a/wp-includes/ms-settings.php b/wp-includes/ms-settings.php index 861ee14abf..a490c22248 100644 --- a/wp-includes/ms-settings.php +++ b/wp-includes/ms-settings.php @@ -136,7 +136,7 @@ if ( !isset( $current_site ) || !isset( $current_blog ) ) { } // @todo Investigate when exactly this can occur. - if ( empty( $current_blog ) && defined( 'WP_INSTALLING' ) ) { + if ( empty( $current_blog ) && wp_installing() ) { $current_blog = new stdClass; $current_blog->blog_id = $blog_id = 1; } diff --git a/wp-includes/option.php b/wp-includes/option.php index 2931c37fd1..701e485cf9 100644 --- a/wp-includes/option.php +++ b/wp-includes/option.php @@ -53,7 +53,7 @@ function get_option( $option, $default = false ) { if ( defined( 'WP_SETUP_CONFIG' ) ) return false; - if ( ! defined( 'WP_INSTALLING' ) ) { + if ( ! wp_installing() ) { // prevent non-existent options from triggering multiple queries $notoptions = wp_cache_get( 'notoptions', 'options' ); if ( isset( $notoptions[ $option ] ) ) { @@ -171,7 +171,7 @@ function form_option( $option ) { function wp_load_alloptions() { global $wpdb; - if ( !defined( 'WP_INSTALLING' ) || !is_multisite() ) + if ( ! wp_installing() || ! is_multisite() ) $alloptions = wp_cache_get( 'alloptions', 'options' ); else $alloptions = false; @@ -185,7 +185,7 @@ function wp_load_alloptions() { foreach ( (array) $alloptions_db as $o ) { $alloptions[$o->option_name] = $o->option_value; } - if ( !defined( 'WP_INSTALLING' ) || !is_multisite() ) + if ( ! wp_installing() || ! is_multisite() ) wp_cache_add( 'alloptions', $alloptions, 'options' ); } @@ -204,7 +204,7 @@ function wp_load_alloptions() { function wp_load_core_site_options( $site_id = null ) { global $wpdb; - if ( !is_multisite() || wp_using_ext_object_cache() || defined( 'WP_INSTALLING' ) ) + if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) return; if ( empty($site_id) ) @@ -332,7 +332,7 @@ function update_option( $option, $value, $autoload = null ) { wp_cache_set( 'notoptions', $notoptions, 'options' ); } - if ( ! defined( 'WP_INSTALLING' ) ) { + if ( ! wp_installing() ) { $alloptions = wp_load_alloptions(); if ( isset( $alloptions[$option] ) ) { $alloptions[ $option ] = $serialized_value; @@ -433,7 +433,7 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) if ( ! $result ) return false; - if ( ! defined( 'WP_INSTALLING' ) ) { + if ( ! wp_installing() ) { if ( 'yes' == $autoload ) { $alloptions = wp_load_alloptions(); $alloptions[ $option ] = $serialized_value; @@ -509,7 +509,7 @@ function delete_option( $option ) { do_action( 'delete_option', $option ); $result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) ); - if ( ! defined( 'WP_INSTALLING' ) ) { + if ( ! wp_installing() ) { if ( 'yes' == $row->autoload ) { $alloptions = wp_load_alloptions(); if ( is_array( $alloptions ) && isset( $alloptions[$option] ) ) { @@ -629,7 +629,7 @@ function get_transient( $transient ) { $value = wp_cache_get( $transient, 'transient' ); } else { $transient_option = '_transient_' . $transient; - if ( ! defined( 'WP_INSTALLING' ) ) { + if ( ! wp_installing() ) { // If option is not in alloptions, it is not autoloaded and thus has a timeout $alloptions = wp_load_alloptions(); if ( !isset( $alloptions[$transient_option] ) ) { diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 1b28da52f1..a812ffe248 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -829,7 +829,7 @@ function wp_just_in_time_script_localization() { function wp_style_loader_src( $src, $handle ) { global $_wp_admin_css_colors; - if ( defined('WP_INSTALLING') ) + if ( wp_installing() ) return preg_replace( '#^wp-admin/#', './', $src ); if ( 'colors' == $handle ) { diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 906da5176f..e1a0334ed9 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -771,7 +771,7 @@ function validate_current_theme() { * * @param bool true Validation flag to check the current theme. */ - if ( defined('WP_INSTALLING') || ! apply_filters( 'validate_current_theme', true ) ) + if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) return true; if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) { diff --git a/wp-includes/update.php b/wp-includes/update.php index c39322ee46..1def316be0 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -22,7 +22,7 @@ * @param bool $force_check Whether to bypass the transient cache and force a fresh update check. Defaults to false, true if $extra_stats is set. */ function wp_version_check( $extra_stats = array(), $force_check = false ) { - if ( defined( 'WP_INSTALLING' ) ) { + if ( wp_installing() ) { return; } @@ -187,7 +187,7 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) { * @param array $extra_stats Extra statistics to report to the WordPress.org API. */ function wp_update_plugins( $extra_stats = array() ) { - if ( defined( 'WP_INSTALLING' ) ) { + if ( wp_installing() ) { return; } @@ -344,7 +344,7 @@ function wp_update_plugins( $extra_stats = array() ) { * @param array $extra_stats Extra statistics to report to the WordPress.org API. */ function wp_update_themes( $extra_stats = array() ) { - if ( defined( 'WP_INSTALLING' ) ) { + if ( wp_installing() ) { return; } global $wp_version; @@ -636,16 +636,16 @@ function _maybe_update_themes() { * @since 3.1.0 */ function wp_schedule_update_checks() { - if ( !wp_next_scheduled('wp_version_check') && !defined('WP_INSTALLING') ) + if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) wp_schedule_event(time(), 'twicedaily', 'wp_version_check'); - if ( !wp_next_scheduled('wp_update_plugins') && !defined('WP_INSTALLING') ) + if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins'); - if ( !wp_next_scheduled('wp_update_themes') && !defined('WP_INSTALLING') ) + if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) wp_schedule_event(time(), 'twicedaily', 'wp_update_themes'); - if ( ! wp_next_scheduled( 'wp_maybe_auto_update' ) && ! defined( 'WP_INSTALLING' ) ) { + if ( ! wp_next_scheduled( 'wp_maybe_auto_update' ) && ! wp_installing() ) { // Schedule auto updates for 7 a.m. and 7 p.m. in the timezone of the site. $next = strtotime( 'today 7am' ); $now = time(); diff --git a/wp-includes/version.php b/wp-includes/version.php index bed17306dd..d47bfd3bcf 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34827'; +$wp_version = '4.4-alpha-34828'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-settings.php b/wp-settings.php index 993a12096e..9a3afd840f 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -321,7 +321,7 @@ require_once( ABSPATH . WPINC . '/locale.php' ); $GLOBALS['wp_locale'] = new WP_Locale(); // Load the functions for the active theme, for both parent and child theme if applicable. -if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) { +if ( ! wp_installing() || 'wp-activate.php' === $pagenow ) { if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) ) include( STYLESHEETPATH . '/functions.php' ); if ( file_exists( TEMPLATEPATH . '/functions.php' ) )