Make WordPress Core


Ignore:
Timestamp:
06/26/2023 07:55:28 PM (21 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/tests/phpunit/tests/theme/wpGetGlobalStylesSvgFilters.php

    r55185 r56042  
    3535        $this->assertNotSame( $svg_for_default_theme, $svg_for_block_theme, 'Cache value should have changed' );
    3636    }
     37
     38    /**
     39     * Tests that the function relies on the development mode for whether to use caching.
     40     *
     41     * @ticket 57487
     42     *
     43     * @covers ::wp_get_global_styles_svg_filters
     44     */
     45    public function test_caching_is_used_when_developing_theme() {
     46        global $_wp_tests_development_mode;
     47
     48        switch_theme( 'block-theme' );
     49
     50        // Store SVG in cache.
     51        $svg = '<svg></svg>';
     52        wp_cache_set( 'wp_get_global_styles_svg_filters', $svg, 'theme_json' );
     53
     54        // By default, caching should be used, so the above value will be returned.
     55        $_wp_tests_development_mode = '';
     56        $this->assertSame( $svg, wp_get_global_styles_svg_filters(), 'Caching was not used despite development mode disabled' );
     57
     58        // When the development mode is set to 'theme', caching should not be used.
     59        $_wp_tests_development_mode = 'theme';
     60        $this->assertNotSame( $svg, wp_get_global_styles_svg_filters(), 'Caching was used despite theme development mode' );
     61    }
    3762}
Note: See TracChangeset for help on using the changeset viewer.