wp_is_development_mode()
云策文档标注
概述
wp_is_development_mode() 函数用于检查站点是否处于指定的开发模式。它接受一个模式参数,返回布尔值表示当前开发模式是否覆盖该指定模式。
关键要点
- 参数 $mode 是必需的,必须是 'core'、'plugin'、'theme' 或 'all' 之一。
- 返回 true 如果给定模式被当前开发模式覆盖,否则返回 false。
- 函数内部调用 wp_get_development_mode() 获取当前模式,并处理 'all' 特殊值。
- 该函数在 WordPress 6.3.0 版本中引入。
代码示例
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;
}注意事项
- 开发模式用于控制特定功能(如核心、插件、主题)的调试或开发行为。
- 相关函数 wp_get_development_mode() 可用于获取当前开发模式。
- 该函数被多个全局样式和主题相关函数使用,如 wp_get_theme_data_template_parts() 和 WP_Theme::get_block_patterns()。
原文内容
Checks whether the site is in the given development mode.
Parameters
$modestringrequired-
Development mode to check for. Either
'core','plugin','theme', or'all'.
Source
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;
}
Changelog
| Version | Description |
|---|---|
| 6.3.0 | Introduced. |