install_theme_information()
云策文档标注
概述
install_theme_information() 函数用于在对话框中显示主题信息,通常用于主题安装界面。它通过 themes_api() 获取主题数据,并利用 WP_List_Table 类来渲染单主题安装视图。
关键要点
- 函数通过 themes_api() 从 WordPress.org Themes API 获取指定 slug 的主题信息。
- 使用 iframe_header() 和 iframe_footer() 包装输出,适用于 Thickbox 对话框。
- 依赖 _get_list_table() 获取 WP_Theme_Install_List_Table 实例来显示主题安装界面。
- 包含错误处理,如 is_wp_error() 检查并调用 wp_die() 在出错时终止执行。
- 函数自 WordPress 2.8.0 版本引入,位于 wp-admin/includes/theme.php 文件中。
代码示例
function install_theme_information() {
global $wp_list_table;
$theme = themes_api( 'theme_information', array( 'slug' => wp_unslash( $_REQUEST['theme'] ) ) );
if ( is_wp_error( $theme ) ) {
wp_die( $theme );
}
iframe_header( __( 'Theme Installation' ) );
if ( ! isset( $wp_list_table ) ) {
$wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
}
$wp_list_table->theme_installer_single( $theme );
iframe_footer();
exit;
}注意事项
- 函数依赖于 $_REQUEST['theme'] 参数来指定主题 slug,需确保请求中包含此参数。
- 使用 wp_unslash() 处理输入以防止斜杠转义问题。
- 函数执行后会调用 exit 终止脚本,因此不应在需要后续代码执行的上下文中直接调用。
- 相关函数如 themes_api() 和 _get_list_table() 需在正确上下文中可用,通常位于管理后台。
原文内容
Displays theme information in dialog box form.
Source
function install_theme_information() {
global $wp_list_table;
$theme = themes_api( 'theme_information', array( 'slug' => wp_unslash( $_REQUEST['theme'] ) ) );
if ( is_wp_error( $theme ) ) {
wp_die( $theme );
}
iframe_header( __( 'Theme Installation' ) );
if ( ! isset( $wp_list_table ) ) {
$wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
}
$wp_list_table->theme_installer_single( $theme );
iframe_footer();
exit;
}
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |