WordPress.org

Make WordPress Core

Changeset 37626


Ignore:
Timestamp:
06/02/2016 06:46:51 PM (3 years ago)
Author:
jorbin
Message:

Introduce filters for skipping parts of the bootstrap process

Non web interfaces with WordPress (such as wp-cli) need to be able to bypass certain checks in the bootstrap process. This introduces three new filters to allow for those checks to be skipped.

  1. Provides a way of forcefully bypassing wp_maintenance().
  2. Provides a way of forcefully bypassing wp_debug_mode(). See https://github.com/wp-cli/wp-cli/issues/177
  3. Provide a way of forcefully skipping loading wp-content/advance-cache.php. See https://github.com/wp-cli/wp-cli/pull/164

These filters should not be used by plugins (in fact, they run before plugins are loaded, so they can't be used by plugins). In general, they should only be used in non-web interactions with WordPress.

See #34936.
Props jorbin, DrewAPicture.

Location:
trunk/src
Files:
2 edited

Legend:

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

    r37613 r37626  
    184184    if ( ( time() - $upgrading ) >= 600 )
    185185        return;
     186   
     187    /**
     188     * Bypass the maintenance mode check
     189     *
     190     * This filter should *NOT* be used by plugins. It is designed for non-web
     191     * runtimes. If this filter returns true, maintenance mode will not be 
     192     * active which can cause problems during updates for web site views.
     193     *
     194     * @since 4.6.0
     195     *
     196     * @param bool True to bypass maintenance
     197     */
     198    if ( apply_filters( 'bypass_maintenance_mode', false ) ){
     199        return;
     200    }
    186201
    187202    if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
     
    286301 */
    287302function wp_debug_mode() {
     303    /**
     304     * Bypass the debug mode check
     305     *
     306     * This filter should *NOT* be used by plugins. It is designed for non-web
     307     * runtimes. Returning true causes the WP_DEBUG and related constants to
     308     * not be checked and the default php values for errors will be used unless
     309     * you take care to update them yourself.
     310     *
     311     * @since 4.6.0
     312     *
     313     * @param bool True to bypass debug mode
     314     */
     315    if ( apply_filters( 'bypass_debug_mode', false ) ){
     316        return;
     317    }
     318
    288319    if ( WP_DEBUG ) {
    289320        error_reporting( E_ALL );
  • trunk/src/wp-settings.php

    r37588 r37626  
    7171wp_debug_mode();
    7272
     73/**
     74 * Bypass the loading of advanced-cache.php
     75 *
     76 * This filter should *NOT* be used by plugins. It is designed for non-web
     77 * runtimes. If true is returned, advance-cache.php will never be loaded.
     78 *
     79 * @since 4.6.0
     80 *
     81 * @param bool True to bypass advanced-cache.php
     82 */
     83if ( WP_CACHE && ! apply_filters( 'bypass_advanced_cache', false )  ) {
    7384// For an advanced caching plugin to use. Uses a static drop-in because you would only want one.
    74 if ( WP_CACHE ) {
    7585    _backup_plugin_globals();
    7686    WP_DEBUG ? include( WP_CONTENT_DIR . '/advanced-cache.php' ) : @include( WP_CONTENT_DIR . '/advanced-cache.php' );
Note: See TracChangeset for help on using the changeset viewer.