wp_get_development_mode()WP 6.3.0

Gets the current 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' )

This function returns the value of the constant WP_DEVELOPMENT_MODE. The value is checked beforehand; if it does not meet the standard, an empty string will be returned.

The development mode in WordPress is separate 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 may check if the plugin development mode is enabled and NOT use caching for a specific section of code in this case.

Use wp_is_development_mode( $mode ) when you need to check if the site is in the specified development mode.

No Hooks.

Returns

String. The current development mode. One of:

  • core
  • plugin
  • theme
  • all - a special value indicating that all three development modes (core, plugin, and theme) are enabled.
  • '' (empty string) - development mode is disabled or the value of the constant WP_DEVELOPMENT_MODE is incorrectly set.

Usage

wp_get_development_mode();

Examples

0

#1 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_get_development_mode() code WP 6.8.1

function wp_get_development_mode() {
	static $current_mode = null;

	if ( ! defined( 'WP_RUN_CORE_TESTS' ) && null !== $current_mode ) {
		return $current_mode;
	}

	$development_mode = WP_DEVELOPMENT_MODE;

	// Exclusively for core tests, rely on the `$_wp_tests_development_mode` global.
	if ( defined( 'WP_RUN_CORE_TESTS' ) && isset( $GLOBALS['_wp_tests_development_mode'] ) ) {
		$development_mode = $GLOBALS['_wp_tests_development_mode'];
	}

	$valid_modes = array(
		'core',
		'plugin',
		'theme',
		'all',
		'',
	);

	if ( ! in_array( $development_mode, $valid_modes, true ) ) {
		$development_mode = '';
	}

	$current_mode = $development_mode;

	return $current_mode;
}