wp_theme_update_rows()
云策文档标注
概述
wp_theme_update_rows() 函数用于为有可用更新的主题添加回调,以显示更新信息。它检查用户权限并基于主题更新数据动态添加动作钩子。
关键要点
- 函数仅在当前用户具有 'update_themes' 权限时执行,否则直接返回。
- 通过 get_site_transient('update_themes') 获取主题更新数据,并检查 $themes->response 是否为数组。
- 遍历有更新的主题,为每个主题添加 after_theme_row_{$theme} 钩子的回调函数 wp_theme_update_row。
代码示例
function wp_theme_update_rows() {
if ( ! current_user_can( 'update_themes' ) ) {
return;
}
$themes = get_site_transient( 'update_themes' );
if ( isset( $themes->response ) && is_array( $themes->response ) ) {
$themes = array_keys( $themes->response );
foreach ( $themes as $theme ) {
add_action( "after_theme_row_{$theme}", 'wp_theme_update_row', 10, 2 );
}
}
}
原文内容
Adds a callback to display update information for themes with updates available.
Source
function wp_theme_update_rows() {
if ( ! current_user_can( 'update_themes' ) ) {
return;
}
$themes = get_site_transient( 'update_themes' );
if ( isset( $themes->response ) && is_array( $themes->response ) ) {
$themes = array_keys( $themes->response );
foreach ( $themes as $theme ) {
add_action( "after_theme_row_{$theme}", 'wp_theme_update_row', 10, 2 );
}
}
}
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |