Make WordPress Core


Ignore:
Timestamp:
06/26/2023 07:55:28 PM (2 years ago)
Author:
flixos90
Message:

General: Introduce WP_DEVELOPMENT_MODE constant to signify context-specific development mode.

In recent releases, WordPress core added several instances of cache usage around specific files. While those caches are safe to use in a production context, in development certain nuances apply for whether or not those caches make sense to use. Initially, WP_DEBUG was used as a temporary workaround, but it was clear that a more granular method to signify a specific development mode was required: For example, caches around theme.json should be disabled when working on a theme as otherwise it would disrupt the theme developer's workflow, but when working on a plugin or WordPress core, this consideration does not apply.

This changeset introduces a WP_DEVELOPMENT_MODE constant which, for now, can be set to either "core", "plugin", "theme", or an empty string, the latter of which means no development mode, which is also the default. A new function wp_get_development_mode() is the recommended way to retrieve that configuration value.

With the new function available, this changeset replaces all existing instances of the aforementioned WP_DEBUG workaround to use wp_get_development_mode() with a more specific check.

Props azaozz, sergeybiryukov, peterwilsoncc, spacedmonkey.
Fixes #57487.

File:
1 edited

Legend:

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

    r56032 r56042  
    260260
    261261    return $current_env;
     262}
     263
     264/**
     265 * Retrieves the current development mode.
     266 *
     267 * The development mode affects how certain parts of the WordPress application behave, which is relevant when
     268 * developing for WordPress.
     269 *
     270 * Valid developer modes are 'core', 'plugin', 'theme', or an empty string to disable developer mode.
     271 *
     272 * Developer mode is considered separately from `WP_DEBUG` and {@see wp_get_environment_type()}. It does not affect
     273 * debugging output, but rather functional nuances in WordPress.
     274 *
     275 * @since 6.3.0
     276 *
     277 * @return string The current development mode.
     278 */
     279function wp_get_development_mode() {
     280    static $current_mode = null;
     281
     282    if ( ! defined( 'WP_RUN_CORE_TESTS' ) && null !== $current_mode ) {
     283        return $current_mode;
     284    }
     285
     286    $development_mode = WP_DEVELOPMENT_MODE;
     287
     288    // Exclusively for core tests, rely on a global `$_wp_tests_development_mode`.
     289    if ( defined( 'WP_RUN_CORE_TESTS' ) && isset( $GLOBALS['_wp_tests_development_mode'] ) ) {
     290        $development_mode = $GLOBALS['_wp_tests_development_mode'];
     291    }
     292
     293    $valid_modes = array(
     294        'core',
     295        'plugin',
     296        'theme',
     297        '',
     298    );
     299    if ( ! in_array( $development_mode, $valid_modes, true ) ) {
     300        $development_mode = '';
     301    }
     302
     303    $current_mode = $development_mode;
     304
     305    return $current_mode;
    262306}
    263307
Note: See TracChangeset for help on using the changeset viewer.