Make WordPress Core

Changeset 56223


Ignore:
Timestamp:
07/13/2023 12:27:06 AM (10 months ago)
Author:
peterwilsoncc
Message:

General: Introduce all development mode.

Introduce the development mode all as a a cover-all mode for the existing theme, plugin and core development modes. Developers can use the all mode if they are developing both themes and plugins, for example.

Introduce the utility function wp_in_development_mode() allowing developers to detect the mode via a parameter. If the development mode is set to all this function will always return true. If the development mode is specific then only the chosen mode will return true.

Follow up to [56079,56042].

Props flixos90.
Fixes #57487.

Location:
trunk
Files:
6 edited

Legend:

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

    r56136 r56223  
    4545     * the core developer's workflow.
    4646     */
    47     if ( 'core' !== wp_get_development_mode() ) {
     47    if ( ! wp_in_development_mode( 'core' ) ) {
    4848        $transient_name = 'wp_core_block_css_files';
    4949        $files          = get_transient( $transient_name );
  • trunk/src/wp-includes/default-constants.php

    r56180 r56223  
    8080    /*
    8181     * Add define( 'WP_DEVELOPMENT_MODE', 'core' ) or define( 'WP_DEVELOPMENT_MODE', 'plugin' ) or
    82      * define( 'WP_DEVELOPMENT_MODE', 'theme' ) to wp-config.php to signify development mode for WordPress core, a
    83      * plugin, or a theme respectively.
     82     * define( 'WP_DEVELOPMENT_MODE', 'theme' ) or define( 'WP_DEVELOPMENT_MODE', 'all' ) to wp-config.php
     83     * to signify development mode for WordPress core, a plugin, a theme, or all three types respectively.
    8484     */
    8585    if ( ! defined( 'WP_DEVELOPMENT_MODE' ) ) {
  • trunk/src/wp-includes/deprecated.php

    r56126 r56223  
    52345234     * developer's workflow.
    52355235     */
    5236     $can_use_cached = wp_get_development_mode() !== 'theme';
     5236    $can_use_cached = ! wp_in_development_mode( 'theme' );
    52375237    $cache_group    = 'theme_json';
    52385238    $cache_key      = 'wp_get_global_styles_svg_filters';
  • trunk/src/wp-includes/global-styles-and-settings.php

    r56185 r56223  
    7070     * developer's workflow.
    7171     */
    72     $can_use_cached = wp_get_development_mode() !== 'theme';
     72    $can_use_cached = ! wp_in_development_mode( 'theme' );
    7373
    7474    $settings = false;
     
    153153     * developer's workflow.
    154154     */
    155     $can_use_cached = empty( $types ) && wp_get_development_mode() !== 'theme';
     155    $can_use_cached = empty( $types ) && ! wp_in_development_mode( 'theme' );
    156156
    157157    /*
     
    252252     * developer's workflow.
    253253     */
    254     $can_use_cached = wp_get_development_mode() !== 'theme';
     254    $can_use_cached = ! wp_in_development_mode( 'theme' );
    255255
    256256    /*
     
    361361         * the theme developer's workflow.
    362362         */
    363         wp_get_development_mode() !== 'theme'
     363        ! wp_in_development_mode( 'theme' )
    364364    ) {
    365365        return $theme_has_support[ $stylesheet ];
  • trunk/src/wp-includes/load.php

    r56153 r56223  
    272272 * developing for WordPress.
    273273 *
    274  * Valid developer modes are 'core', 'plugin', 'theme', or an empty string to disable developer mode.
     274 * Valid development modes are 'core', 'plugin', 'theme', 'all', or an empty string to disable development mode.
     275 * 'all' is a special value to signify that all three development modes 'core', 'plugin', and 'theme' are enabled.
    275276 *
    276277 * Developer mode is considered separately from `WP_DEBUG` and {@see wp_get_environment_type()}. It does not affect
    277278 * debugging output, but rather functional nuances in WordPress.
     279 *
     280 * This function controls the currently set development mode value. To check for whether a specific development mode is
     281 * enabled, use wp_in_development_mode().
    278282 *
    279283 * @since 6.3.0
     
    299303        'plugin',
    300304        'theme',
     305        'all',
    301306        '',
    302307    );
     
    308313
    309314    return $current_mode;
     315}
     316
     317/**
     318 * Checks whether the site is in the given development mode.
     319 *
     320 * @since 6.3.0
     321 *
     322 * @param string $mode Development mode to check for. Either 'core', 'plugin', 'theme', or 'all'.
     323 * @return bool True if the given mode is covered by the current development mode, false otherwise.
     324 */
     325function wp_in_development_mode( $mode ) {
     326    $current_mode = wp_get_development_mode();
     327    if ( empty( $current_mode ) ) {
     328        return false;
     329    }
     330
     331    // Return true if the current mode encompasses all modes.
     332    if ( 'all' === $current_mode ) {
     333        return true;
     334    }
     335
     336    // Return true if the current mode is the given mode.
     337    return $mode === $current_mode;
    310338}
    311339
  • trunk/tests/phpunit/tests/load/wpGetDevelopmentMode.php

    r56042 r56223  
    99 * @group load.php
    1010 * @covers ::wp_get_development_mode
     11 * @covers ::wp_in_development_mode
    1112 */
    1213class Test_WP_Get_Development_Mode extends WP_UnitTestCase {
     
    4445        $this->assertSame( '', wp_get_development_mode() );
    4546    }
     47
     48    /**
     49     * Tests that `wp_in_development_mode()` returns expected results.
     50     *
     51     * @ticket 57487
     52     * @dataProvider data_wp_in_development_mode
     53     */
     54    public function test_wp_in_development_mode( $current, $given, $expected ) {
     55        global $_wp_tests_development_mode;
     56
     57        $_wp_tests_development_mode = $current;
     58
     59        if ( $expected ) {
     60            $this->assertTrue( wp_in_development_mode( $given ), "{$given} is expected to pass in {$current} mode" );
     61        } else {
     62            $this->assertFalse( wp_in_development_mode( $given ), "{$given} is expected to fail in {$current} mode" );
     63        }
     64    }
     65
     66    /**
     67     * Data provider that returns test scenarios for the `test_wp_in_development_mode()` method.
     68     *
     69     * @return array[]
     70     */
     71    public function data_wp_in_development_mode() {
     72        return array(
     73            'core mode, testing for core'              => array(
     74                'core',
     75                'core',
     76                true,
     77            ),
     78            'plugin mode, testing for plugin'          => array(
     79                'plugin',
     80                'plugin',
     81                true,
     82            ),
     83            'theme mode, testing for theme'            => array(
     84                'theme',
     85                'theme',
     86                true,
     87            ),
     88            'core mode, testing for plugin'            => array(
     89                'core',
     90                'plugin',
     91                false,
     92            ),
     93            'core mode, testing for theme'             => array(
     94                'core',
     95                'theme',
     96                false,
     97            ),
     98            'plugin mode, testing for core'            => array(
     99                'plugin',
     100                'core',
     101                false,
     102            ),
     103            'plugin mode, testing for theme'           => array(
     104                'plugin',
     105                'theme',
     106                false,
     107            ),
     108            'theme mode, testing for core'             => array(
     109                'theme',
     110                'core',
     111                false,
     112            ),
     113            'theme mode, testing for plugin'           => array(
     114                'theme',
     115                'plugin',
     116                false,
     117            ),
     118            'all mode, testing for core'               => array(
     119                'all',
     120                'core',
     121                true,
     122            ),
     123            'all mode, testing for plugin'             => array(
     124                'all',
     125                'plugin',
     126                true,
     127            ),
     128            'all mode, testing for theme'              => array(
     129                'all',
     130                'theme',
     131                true,
     132            ),
     133            'all mode, testing for all'                => array(
     134                'all',
     135                'all',
     136                true,
     137            ),
     138            'all mode, testing for non-standard value' => array(
     139                'all',
     140                'random',
     141                true,
     142            ),
     143            'invalid mode, testing for core'           => array(
     144                'invalid',
     145                'core',
     146                false,
     147            ),
     148            'invalid mode, testing for plugin'         => array(
     149                'invalid',
     150                'plugin',
     151                false,
     152            ),
     153            'invalid mode, testing for theme'          => array(
     154                'invalid',
     155                'theme',
     156                false,
     157            ),
     158        );
     159    }
    46160}
Note: See TracChangeset for help on using the changeset viewer.