get_blog_count()
云策文档标注
概述
get_blog_count() 函数用于获取 WordPress 安装中活跃站点的数量。该计数被缓存,每日更新两次,非实时数据。
关键要点
- 函数返回指定网络中活跃站点的数量,以整数形式表示。
- 参数 $network_id 可选,用于指定网络 ID,默认为当前网络。
- 计数基于缓存机制,通过 get_network_option() 获取,更新频率为每日两次。
- 该函数在 WordPress 多站点环境中使用,相关函数包括 wp_is_large_network() 和 get_sitestats()。
代码示例
function get_blog_count( $network_id = null ) {
return get_network_option( $network_id, 'blog_count' );
}注意事项
- 由于缓存机制,返回的计数可能不是最新的实时数据,适用于非精确统计场景。
- 在 WordPress 4.8.0 版本中引入了 $network_id 参数的使用,允许指定特定网络。
- 该函数自 WordPress 3.7.0 版本引入,是多站点功能的一部分。
原文内容
Gets the number of active sites on the installation.
Description
The count is cached and updated twice daily. This is not a live count.
Parameters
$network_idint|nulloptional-
ID of the network. Default is the current network.
Default:
null
Source
function get_blog_count( $network_id = null ) {
return get_network_option( $network_id, 'blog_count' );
}
Changelog
| Version | Description |
|---|---|
| MU (3.0.0) | MU (3.0.0) |
| 4.8.0 | The $network_id parameter is now being used. |
| 3.7.0 | Introduced. |