Make WordPress Core


Ignore:
Timestamp:
06/26/2023 07:55:28 PM (17 months 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/global-styles-and-settings.php

    r56038 r56042  
    6767
    6868    /*
    69      * Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme
     69     * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
    7070     * developer's workflow.
    71      *
    72      * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
    73      */
    74     $can_use_cached = ! WP_DEBUG;
     71     */
     72    $can_use_cached = wp_get_development_mode() !== 'theme';
    7573
    7674    $settings = false;
     
    152150function wp_get_global_stylesheet( $types = array() ) {
    153151    /*
    154      * Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme
     152     * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
    155153     * developer's workflow.
    156      *
    157      * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
    158      */
    159     $can_use_cached = empty( $types ) && ! WP_DEBUG;
     154     */
     155    $can_use_cached = empty( $types ) && wp_get_development_mode() !== 'theme';
    160156
    161157    /*
     
    253249    }
    254250    /*
    255      * Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme
     251     * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
    256252     * developer's workflow.
    257      *
    258      * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
    259      */
    260     $can_use_cached = ! WP_DEBUG;
     253     */
     254    $can_use_cached = wp_get_development_mode() !== 'theme';
    261255
    262256    /*
     
    304298function wp_get_global_styles_svg_filters() {
    305299    /*
    306      * Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme
     300     * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
    307301     * developer's workflow.
    308      *
    309      * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
    310      */
    311     $can_use_cached = ! WP_DEBUG;
     302     */
     303    $can_use_cached = wp_get_development_mode() !== 'theme';
    312304    $cache_group    = 'theme_json';
    313305    $cache_key      = 'wp_get_global_styles_svg_filters';
     
    403395        null !== $theme_has_support &&
    404396        /*
    405          * Ignore static cache when `WP_DEBUG` is enabled. Why? To avoid interfering with
     397         * Ignore static cache when the development mode is set to 'theme', to avoid interfering with
    406398         * the theme developer's workflow.
    407          *
    408          * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
    409399         */
    410         ! WP_DEBUG &&
     400        wp_get_development_mode() !== 'theme' &&
    411401        /*
    412402         * Ignore cache when automated test suites are running. Why? To ensure
Note: See TracChangeset for help on using the changeset viewer.