Make WordPress Core


Ignore:
Timestamp:
10/05/2015 03:05:26 PM (8 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r34779 r34828  
    5454        return false;
    5555
    56     if ( ! defined( 'WP_INSTALLING' ) ) {
     56    if ( ! wp_installing() ) {
    5757        // prevent non-existent options from triggering multiple queries
    5858        $notoptions = wp_cache_get( 'notoptions', 'options' );
     
    172172    global $wpdb;
    173173
    174     if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
     174    if ( ! wp_installing() || ! is_multisite() )
    175175        $alloptions = wp_cache_get( 'alloptions', 'options' );
    176176    else
     
    186186            $alloptions[$o->option_name] = $o->option_value;
    187187        }
    188         if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
     188        if ( ! wp_installing() || ! is_multisite() )
    189189            wp_cache_add( 'alloptions', $alloptions, 'options' );
    190190    }
     
    205205    global $wpdb;
    206206
    207     if ( !is_multisite() || wp_using_ext_object_cache() || defined( 'WP_INSTALLING' ) )
     207    if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() )
    208208        return;
    209209
     
    333333    }
    334334
    335     if ( ! defined( 'WP_INSTALLING' ) ) {
     335    if ( ! wp_installing() ) {
    336336        $alloptions = wp_load_alloptions();
    337337        if ( isset( $alloptions[$option] ) ) {
     
    434434        return false;
    435435
    436     if ( ! defined( 'WP_INSTALLING' ) ) {
     436    if ( ! wp_installing() ) {
    437437        if ( 'yes' == $autoload ) {
    438438            $alloptions = wp_load_alloptions();
     
    510510
    511511    $result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) );
    512     if ( ! defined( 'WP_INSTALLING' ) ) {
     512    if ( ! wp_installing() ) {
    513513        if ( 'yes' == $row->autoload ) {
    514514            $alloptions = wp_load_alloptions();
     
    630630    } else {
    631631        $transient_option = '_transient_' . $transient;
    632         if ( ! defined( 'WP_INSTALLING' ) ) {
     632        if ( ! wp_installing() ) {
    633633            // If option is not in alloptions, it is not autoloaded and thus has a timeout
    634634            $alloptions = wp_load_alloptions();
Note: See TracChangeset for help on using the changeset viewer.