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.

git-svn-id: https://develop.svn.wordpress.org/trunk@34828 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-10-05 15:05:26 +00:00
parent d67c6d2ade
commit 578134d4ff
25 changed files with 77 additions and 137 deletions
+33 -2
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.