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.


Built from https://develop.svn.wordpress.org/trunk@56223


git-svn-id: http://core.svn.wordpress.org/trunk@55735 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2023-07-13 00:29:26 +00:00
parent 724d2c9950
commit 94f92497ce
6 changed files with 38 additions and 10 deletions

View File

@ -44,7 +44,7 @@ function register_core_block_style_handles() {
* Ignore transient cache when the development mode is set to 'core'. Why? To avoid interfering with * Ignore transient cache when the development mode is set to 'core'. Why? To avoid interfering with
* the core developer's workflow. * the core developer's workflow.
*/ */
if ( 'core' !== wp_get_development_mode() ) { if ( ! wp_in_development_mode( 'core' ) ) {
$transient_name = 'wp_core_block_css_files'; $transient_name = 'wp_core_block_css_files';
$files = get_transient( $transient_name ); $files = get_transient( $transient_name );
if ( ! $files ) { if ( ! $files ) {

View File

@ -79,8 +79,8 @@ function wp_initial_constants() {
/* /*
* Add define( 'WP_DEVELOPMENT_MODE', 'core' ) or define( 'WP_DEVELOPMENT_MODE', 'plugin' ) or * Add define( 'WP_DEVELOPMENT_MODE', 'core' ) or define( 'WP_DEVELOPMENT_MODE', 'plugin' ) or
* define( 'WP_DEVELOPMENT_MODE', 'theme' ) to wp-config.php to signify development mode for WordPress core, a * define( 'WP_DEVELOPMENT_MODE', 'theme' ) or define( 'WP_DEVELOPMENT_MODE', 'all' ) to wp-config.php
* plugin, or a theme respectively. * to signify development mode for WordPress core, a plugin, a theme, or all three types respectively.
*/ */
if ( ! defined( 'WP_DEVELOPMENT_MODE' ) ) { if ( ! defined( 'WP_DEVELOPMENT_MODE' ) ) {
define( 'WP_DEVELOPMENT_MODE', '' ); define( 'WP_DEVELOPMENT_MODE', '' );

View File

@ -5233,7 +5233,7 @@ function wp_get_global_styles_svg_filters() {
* Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
* developer's workflow. * developer's workflow.
*/ */
$can_use_cached = wp_get_development_mode() !== 'theme'; $can_use_cached = ! wp_in_development_mode( 'theme' );
$cache_group = 'theme_json'; $cache_group = 'theme_json';
$cache_key = 'wp_get_global_styles_svg_filters'; $cache_key = 'wp_get_global_styles_svg_filters';
if ( $can_use_cached ) { if ( $can_use_cached ) {

View File

@ -69,7 +69,7 @@ function wp_get_global_settings( $path = array(), $context = array() ) {
* Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
* developer's workflow. * developer's workflow.
*/ */
$can_use_cached = wp_get_development_mode() !== 'theme'; $can_use_cached = ! wp_in_development_mode( 'theme' );
$settings = false; $settings = false;
if ( $can_use_cached ) { if ( $can_use_cached ) {
@ -152,7 +152,7 @@ function wp_get_global_stylesheet( $types = array() ) {
* Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
* developer's workflow. * developer's workflow.
*/ */
$can_use_cached = empty( $types ) && wp_get_development_mode() !== 'theme'; $can_use_cached = empty( $types ) && ! wp_in_development_mode( 'theme' );
/* /*
* By using the 'theme_json' group, this data is marked to be non-persistent across requests. * By using the 'theme_json' group, this data is marked to be non-persistent across requests.
@ -251,7 +251,7 @@ function wp_get_global_styles_custom_css() {
* Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
* developer's workflow. * developer's workflow.
*/ */
$can_use_cached = wp_get_development_mode() !== 'theme'; $can_use_cached = ! wp_in_development_mode( 'theme' );
/* /*
* By using the 'theme_json' group, this data is marked to be non-persistent across requests. * By using the 'theme_json' group, this data is marked to be non-persistent across requests.
@ -360,7 +360,7 @@ function wp_theme_has_theme_json() {
* Ignore static cache when the development mode is set to 'theme', to avoid interfering with * Ignore static cache when the development mode is set to 'theme', to avoid interfering with
* the theme developer's workflow. * the theme developer's workflow.
*/ */
wp_get_development_mode() !== 'theme' ! wp_in_development_mode( 'theme' )
) { ) {
return $theme_has_support[ $stylesheet ]; return $theme_has_support[ $stylesheet ];
} }

View File

@ -271,11 +271,15 @@ function wp_get_environment_type() {
* The development mode affects how certain parts of the WordPress application behave, which is relevant when * The development mode affects how certain parts of the WordPress application behave, which is relevant when
* developing for WordPress. * developing for WordPress.
* *
* Valid developer modes are 'core', 'plugin', 'theme', or an empty string to disable developer mode. * Valid development modes are 'core', 'plugin', 'theme', 'all', or an empty string to disable development mode.
* 'all' is a special value to signify that all three development modes 'core', 'plugin', and 'theme' are enabled.
* *
* Developer mode is considered separately from `WP_DEBUG` and {@see wp_get_environment_type()}. It does not affect * Developer mode is considered separately from `WP_DEBUG` and {@see wp_get_environment_type()}. It does not affect
* debugging output, but rather functional nuances in WordPress. * debugging output, but rather functional nuances in WordPress.
* *
* This function controls the currently set development mode value. To check for whether a specific development mode is
* enabled, use wp_in_development_mode().
*
* @since 6.3.0 * @since 6.3.0
* *
* @return string The current development mode. * @return string The current development mode.
@ -298,6 +302,7 @@ function wp_get_development_mode() {
'core', 'core',
'plugin', 'plugin',
'theme', 'theme',
'all',
'', '',
); );
if ( ! in_array( $development_mode, $valid_modes, true ) ) { if ( ! in_array( $development_mode, $valid_modes, true ) ) {
@ -309,6 +314,29 @@ function wp_get_development_mode() {
return $current_mode; return $current_mode;
} }
/**
* Checks whether the site is in the given development mode.
*
* @since 6.3.0
*
* @param string $mode Development mode to check for. Either 'core', 'plugin', 'theme', or 'all'.
* @return bool True if the given mode is covered by the current development mode, false otherwise.
*/
function wp_in_development_mode( $mode ) {
$current_mode = wp_get_development_mode();
if ( empty( $current_mode ) ) {
return false;
}
// Return true if the current mode encompasses all modes.
if ( 'all' === $current_mode ) {
return true;
}
// Return true if the current mode is the given mode.
return $mode === $current_mode;
}
/** /**
* Ensures all of WordPress is not loaded when handling a favicon.ico request. * Ensures all of WordPress is not loaded when handling a favicon.ico request.
* *

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.3-beta4-56222'; $wp_version = '6.3-beta4-56223';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.