get_broken_themes()
云策文档标注
概述
get_broken_themes() 函数用于检索损坏主题的列表,但自 WordPress 3.4.0 起已弃用,建议使用 wp_get_themes() 替代。
关键要点
- 函数返回一个数组,包含损坏主题的名称和错误信息。
- 自 WordPress 3.4.0 起,该函数被标记为弃用,推荐使用 wp_get_themes( array( 'errors' => true ) ) 来获取损坏主题。
- 函数内部通过 wp_get_themes() 获取主题,并筛选出有错误的主题来构建返回数组。
代码示例
function get_broken_themes() {
_deprecated_function( __FUNCTION__, '3.4.0', "wp_get_themes( array( 'errors' => true )" );
$themes = wp_get_themes( array( 'errors' => true ) );
$broken = array();
foreach ( $themes as $theme ) {
$name = $theme->get('Name');
$broken[ $name ] = array(
'Name' => $name,
'Title' => $name,
'Description' => $theme->errors()->get_error_message(),
);
}
return $broken;
}注意事项
- 使用此函数时,WordPress 会触发弃用警告,建议更新代码以避免兼容性问题。
- 函数返回的数组键为主题名称,值为包含 Name、Title 和 Description 的关联数组,其中 Description 存储错误消息。
原文内容
Retrieves a list of broken themes.
Description
See also
Source
function get_broken_themes() {
_deprecated_function( __FUNCTION__, '3.4.0', "wp_get_themes( array( 'errors' => true )" );
$themes = wp_get_themes( array( 'errors' => true ) );
$broken = array();
foreach ( $themes as $theme ) {
$name = $theme->get('Name');
$broken[ $name ] = array(
'Name' => $name,
'Title' => $name,
'Description' => $theme->errors()->get_error_message(),
);
}
return $broken;
}
Changelog
| Version | Description |
|---|---|
| 3.4.0 | Deprecated. Use wp_get_themes() |
| 1.5.0 | Introduced. |