WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/05/2015 03:05:26 PM (4 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/tests/phpunit/includes/testcase.php

    r34810 r34828  
    1414    protected static $hooks_saved = array();
    1515    protected static $ignore_files;
    16 
    17     protected $db_version;
    1816
    1917    /**
     
    5957
    6058        add_filter( 'wp_mail', array( $this, 'set_wp_mail_globals' ) );
    61 
    62         /*
    63          * During multisite tests, WP_INSTALLING forces `get_option()` to miss the cache, which causes problems
    64          * with our query-counting cache tests. As a workaround in the case of tests that require checking
    65          * 'db_version' (such as any test that uses the Term Meta API), we filter 'pre_option_db_version' and
    66          * avoid hitting the database.
    67          *
    68          * See #31130.
    69          */
    70         $this->db_version = get_option( 'db_version' );
    71         if ( is_multisite() ) {
    72             add_filter( 'pre_option_db_version', array( $this, 'db_version' ) );
    73         }
    7459    }
    7560
     
    636621
    637622    /**
    638      * Return the current database version without hitting the database.
    639      *
    640      * This is used to bypass cache problems with some multisite tests. See #31130.
    641      *
    642      * @todo Don't do this anymore once #31130 is fixed.
    643      *
    644      * @since 4.4.0
    645      */
    646     public function db_version() {
    647         return $this->db_version;
    648     }
    649 
    650     /**
    651623     * Utility method that resets permalinks and flushes rewrites.
    652624     *
Note: See TracChangeset for help on using the changeset viewer.