Use `wp_installing()` instead of `WP_INSTALLING` constant.

The `WP_INSTALLING` constant is a flag that WordPress sets in a number of
places, telling the system that options should be fetched directly from the
database instead of from the cache, that WP should not ping wordpress.org for
updates, that the normal "not installed" checks should be bypassed, and so on.

A constant is generally necessary for this purpose, because the flag is
typically set before the WP bootstrap, meaning that WP functions are not yet
available.  However, it is possible - notably, during `wpmu_create_blog()` -
for the "installing" flag to be set after WP has already loaded. In these
cases, `WP_INSTALLING` would be set for the remainder of the process, since
there's no way to change a constant once it's defined. This, in turn, polluted
later function calls that ought to have been outside the scope of site
creation, particularly the non-caching of option data. The problem was
particularly evident in the case of the automated tests, where `WP_INSTALLING`
was set the first time a site was created, and remained set for the rest of the
suite.

The new `wp_installing()` function allows developers to fetch the current
installation status (when called without any arguments) or to set the
installation status (when called with a boolean `true` or `false`). Use of
the `WP_INSTALLING` constant is still supported; `wp_installing()` will default
to `true` if the constant is defined during the bootstrap.

Props boonebgorges, jeremyfelt.
See #31130.
Built from https://develop.svn.wordpress.org/trunk@34828


git-svn-id: http://core.svn.wordpress.org/trunk@34793 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-10-05 15:06:28 +00:00
parent aa6fbdaa92
commit 0e7c1d3b14
16 changed files with 68 additions and 36 deletions

View File

@ -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();

View File

@ -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.

View File

@ -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;

View File

@ -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() ) {

View File

@ -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;
}

View File

@ -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.

View File

@ -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" );
}

View File

@ -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;

View File

@ -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');
}

View File

@ -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;
}

View File

@ -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] ) ) {

View File

@ -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 ) {

View File

@ -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') ) {

View File

@ -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();

View File

@ -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.

View File

@ -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' ) )