函数文档

wp_get_development_mode()

💡 云策文档标注

概述

wp_get_development_mode() 函数用于检索当前设置的 WordPress 开发模式值,该模式通过 WP_DEVELOPMENT_MODE 常量定义,影响 WordPress 应用在开发时的行为。

关键要点

  • 开发模式通过 WP_DEVELOPMENT_MODE 常量在 wp-config.php 中设置,可选值包括 'core'、'plugin'、'theme'、'all' 或空字符串(禁用)。
  • 开发模式独立于 WP_DEBUG 和 wp_get_environment_type(),主要影响功能细节而非调试输出。
  • 函数返回当前开发模式字符串,要检查特定模式是否启用,应使用 wp_is_development_mode()。
  • 在核心测试环境中,函数会优先使用全局变量 $_wp_tests_development_mode 的值。

代码示例

/* Get current development mode */
$development_mode = wp_get_development_mode();

if ( $development_mode ) {
    esc_html_e( 'Development Mode is active!', 'textdomain' );
} else {
    esc_html_e( 'Development Mode is not active.', 'textdomain' );
}

📄 原文内容

Retrieves the current development mode.

Description

The development mode affects how certain parts of the WordPress application behave, which is relevant when developing for WordPress.

Development mode can be set via the WP_DEVELOPMENT_MODE constant in wp-config.php.
Possible values 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.

Development mode is considered separately from WP_DEBUG and wp_get_environment_type() .
It does not affect debugging output, but rather functional nuances in WordPress.

This function retrieves the currently set development mode value. To check whether a specific development mode is enabled, use wp_is_development_mode() .

Return

string The current development mode.

Source

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;
}

Changelog

Version Description
6.3.0 Introduced.

User Contributed Notes