wp_is_development_mode()
Checks if the site is in the specified development mode: core
, plugin
, theme
, all
.
The development mode is set in the wp-config.php file via the constant WP_DEVELOPMENT_MODE
. For example:
define( 'WP_DEVELOPMENT_MODE', 'all' )
The development mode in WordPress is different from debug mode (WP_DEBUG) or the development environment wp_get_environment_type(). It does not affect error handling or debugging, but is needed to execute or not execute something in development mode. For example, a plugin can check if the plugin development mode is enabled and NOT use caching for a specific section of code.
Use wp_get_development_mode() when you need to get the name of the current development mode.
No Hooks.
Returns
true|false
. True if the current development mode is equal to the specified one, false otherwise.
Usage
wp_is_development_mode( $mode );
- $mode(string) (required)
The development mode to check. One of:
core
plugin
theme
all
- whether all three development modes (core, plugin, and theme) are enabled.
Examples
#1 Disabling caching in development mode
Example from the core function code wp_get_global_global_styles_custom_css():
/* * Ignore cache when development mode is set to 'theme' so as not to interfere with the theme developer's work. */ $can_use_cached = ! wp_is_development_mode( 'theme' ); $cache_key = 'wp_get_global_styles_custom_css'; $cache_group = 'theme_json'; if ( $can_use_cached ) { $cached = wp_cache_get( $cache_key, $cache_group ); if ( $cached ) { return $cached; } } $tree = WP_Theme_JSON_Resolver::get_merged_data(); $stylesheet = $tree->get_custom_css(); if ( $can_use_cached ) { wp_cache_set( $cache_key, $stylesheet, $cache_group ); }
#2 Disabling cache for plugin developers.
Suppose we write a plugin and want to make it so that in plugin development mode our plugin does not use caching, but in any other mode it does.
// some code /* * Ignoring transit cache in 'core' development mode. * This is to avoid interfering with the plugin developer's workflow. */ if ( ! wp_is_development_mode( 'plugin' ) ) { $transient_name = 'wp_core_block_css_files'; $files = get_transient( $transient_name ); if ( ! $files ) { $files = glob( wp_normalize_path( __DIR__ . '/**/**.css' ) ); set_transient( $transient_name, $files ); } } else { $files = glob( wp_normalize_path( __DIR__ . '/**/**.css' ) ); } // some code
Changelog
Since 6.3.0 | Introduced. |
wp_is_development_mode() wp is development mode code WP 6.8.1
function wp_is_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; }