install_themes_feature_list()
云策文档标注
概述
install_themes_feature_list() 是一个已弃用的 WordPress 函数,用于从 WordPress.org 主题 API 检索主题功能(即主题标签)列表。该函数已被 get_theme_feature_list() 替代,并利用 transient 缓存机制优化性能。
关键要点
- 函数已弃用:自 WordPress 3.1.0 起,应使用 get_theme_feature_list() 替代。
- 功能:检索主题功能列表,通过 themes_api() 从 WordPress.org API 获取数据。
- 缓存机制:使用 get_transient() 和 set_transient() 缓存数据,默认过期时间为 3 小时。
- 错误处理:使用 is_wp_error() 检查 API 调用错误,返回空数组作为后备。
代码示例
function install_themes_feature_list() {
_deprecated_function( __FUNCTION__, '3.1.0', 'get_theme_feature_list()' );
$cache = get_transient( 'wporg_theme_feature_list' );
if ( ! $cache ) {
set_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
}
if ( $cache ) {
return $cache;
}
$feature_list = themes_api( 'feature_list', array() );
if ( is_wp_error( $feature_list ) ) {
return array();
}
set_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
return $feature_list;
}注意事项
- 此函数已弃用,新代码中不应使用,以避免兼容性问题。
- 缓存键为 'wporg_theme_feature_list',确保在相关操作中正确管理 transient。
- 函数返回数组格式的主题功能列表,错误时返回空数组。
原文内容
Retrieves the list of WordPress theme features (aka theme tags).
Source
function install_themes_feature_list() {
_deprecated_function( __FUNCTION__, '3.1.0', 'get_theme_feature_list()' );
$cache = get_transient( 'wporg_theme_feature_list' );
if ( ! $cache ) {
set_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
}
if ( $cache ) {
return $cache;
}
$feature_list = themes_api( 'feature_list', array() );
if ( is_wp_error( $feature_list ) ) {
return array();
}
set_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
return $feature_list;
}
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Deprecated. Use get_theme_feature_list() instead. |
| 2.8.0 | Introduced. |