wp_get_theme_error()
云策文档标注
概述
wp_get_theme_error() 函数用于获取已暂停主题的错误信息。它检查全局变量 $_paused_themes 中是否存在指定主题的错误记录,并返回错误数组或 false。
关键要点
- 函数参数:$theme(字符串,必需),表示主题目录相对于 themes 目录的路径。
- 返回值:返回 error_get_last() 返回的错误信息数组,如果未记录错误则返回 false。
- 依赖全局变量:$_paused_themes,用于存储暂停主题的错误信息。
代码示例
function wp_get_theme_error( $theme ) {
if ( ! isset( $GLOBALS['_paused_themes'] ) ) {
return false;
}
if ( ! array_key_exists( $theme, $GLOBALS['_paused_themes'] ) ) {
return false;
}
return $GLOBALS['_paused_themes'][ $theme ];
}注意事项
- 函数在 WordPress 5.2.0 版本中引入。
- 需要确保 $_paused_themes 全局变量已正确设置,否则可能返回 false。
原文内容
Gets the error that was recorded for a paused theme.
Parameters
$themestringrequired-
Path to the theme directory relative to the themes directory.
Source
function wp_get_theme_error( $theme ) {
if ( ! isset( $GLOBALS['_paused_themes'] ) ) {
return false;
}
if ( ! array_key_exists( $theme, $GLOBALS['_paused_themes'] ) ) {
return false;
}
return $GLOBALS['_paused_themes'][ $theme ];
}
Changelog
| Version | Description |
|---|---|
| 5.2.0 | Introduced. |