get_theme_updates()
云策文档标注
概述
get_theme_updates() 函数用于检索有可用更新的主题,返回一个包含 WP_Theme 对象的数组,每个对象附加了更新数据。
关键要点
- 函数返回类型为 WP_Theme[],表示一个 WP_Theme 对象数组。
- 通过 get_site_transient('update_themes') 获取更新信息,若无响应则返回空数组。
- 遍历更新数据,为每个主题创建 WP_Theme 对象并附加更新信息。
代码示例
function get_theme_updates() {
$current = get_site_transient( 'update_themes' );
if ( ! isset( $current->response ) ) {
return array();
}
$update_themes = array();
foreach ( $current->response as $stylesheet => $data ) {
$update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );
$update_themes[ $stylesheet ]->update = $data;
}
return $update_themes;
}注意事项
- 函数依赖于 get_site_transient() 获取的更新数据,确保站点瞬态已正确设置。
- 返回的 WP_Theme 对象包含 update 属性,存储了更新详情,便于进一步处理。
原文内容
Retrieves themes with updates available.
Source
function get_theme_updates() {
$current = get_site_transient( 'update_themes' );
if ( ! isset( $current->response ) ) {
return array();
}
$update_themes = array();
foreach ( $current->response as $stylesheet => $data ) {
$update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );
$update_themes[ $stylesheet ]->update = $data;
}
return $update_themes;
}
Changelog
| Version | Description |
|---|---|
| 2.9.0 | Introduced. |