update_sitemeta_cache()
云策文档标注
概述
update_sitemeta_cache() 函数用于更新指定站点ID列表的元数据缓存,通过SQL查询获取元数据并存储,以提高后续get_site_meta()调用的性能。
关键要点
- 函数执行SQL查询以检索匹配$site_ids的站点元数据,并将其缓存
- 参数$site_ids为必需数组,包含站点ID列表
- 成功时返回元数据数组,若无内容可更新则返回false
- 内部调用update_meta_cache(),并确保相关过滤器已挂钩
- 自WordPress 5.1.0版本引入
代码示例
function update_sitemeta_cache( $site_ids ) {
// Ensure this filter is hooked in even if the function is called early.
if ( ! has_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' ) ) {
add_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' );
}
return update_meta_cache( 'blog', $site_ids );
}注意事项
- 函数确保在早期调用时也挂钩update_blog_metadata_cache过滤器
- 与update_meta_cache()函数紧密相关,用于处理博客元数据缓存
原文内容
Updates metadata cache for list of site IDs.
Description
Performs SQL query to retrieve all metadata for the sites matching $site_ids and stores them in the cache.
Subsequent calls to get_site_meta() will not need to query the database.
Parameters
$site_idsarrayrequired-
List of site IDs.
Source
function update_sitemeta_cache( $site_ids ) {
// Ensure this filter is hooked in even if the function is called early.
if ( ! has_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' ) ) {
add_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' );
}
return update_meta_cache( 'blog', $site_ids );
}
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |