wp_is_large_network()
云策文档标注
概述
wp_is_large_network() 函数用于判断网络是否被视为大型网络,基于用户或站点数量。默认标准为超过10,000个用户或站点,可通过 'wp_is_large_network' 过滤器自定义。
关键要点
- 函数接受两个参数:$using(可选 'sites' 或 'users',默认为 'sites')和 $network_id(可选网络ID,默认为当前网络)。
- 返回布尔值:true 表示网络符合大型标准,false 表示不符合。
- 内部使用 get_user_count() 或 get_blog_count() 获取数量,并应用过滤器 wp_is_large_network 允许插件修改判断逻辑。
- 相关函数包括 wp_is_large_user_count()、get_current_network_id() 等,用于辅助计算。
代码示例
function custom_large_network( $is_large_network, $component, $count, $network_id ) {
return ( $count > 5000);
}
add_filter( 'wp_is_large_network', 'custom_large_network', 10, 4 );注意事项
- 从版本4.8.0开始,添加了 $network_id 参数,支持指定网络ID。
- 过滤器 wp_is_large_network 允许开发者根据自定义条件调整大型网络的定义,例如降低阈值至5,000。
原文内容
Determines whether or not we have a large network.
Description
The default criteria for a large network is either more than 10,000 users or more than 10,000 sites.
Plugins can alter this criteria using the ‘wp_is_large_network’ filter.
Parameters
$usingstringrequired-
'sites'or'users'. Default is'sites'. $network_idint|nulloptional-
ID of the network. Default is the current network.
Default:
null
Source
function wp_is_large_network( $using = 'sites', $network_id = null ) {
$network_id = (int) $network_id;
if ( ! $network_id ) {
$network_id = get_current_network_id();
}
if ( 'users' === $using ) {
$count = get_user_count( $network_id );
$is_large_network = wp_is_large_user_count( $network_id );
/**
* Filters whether the network is considered large.
*
* @since 3.3.0
* @since 4.8.0 The `$network_id` parameter has been added.
*
* @param bool $is_large_network Whether the network has more than 10000 users or sites.
* @param string $component The component to count. Accepts 'users', or 'sites'.
* @param int $count The count of items for the component.
* @param int $network_id The ID of the network being checked.
*/
return apply_filters( 'wp_is_large_network', $is_large_network, 'users', $count, $network_id );
}
$count = get_blog_count( $network_id );
/** This filter is documented in wp-includes/ms-functions.php */
return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count, $network_id );
}
Hooks
- apply_filters( ‘wp_is_large_network’, bool $is_large_network, string $component, int $count, int $network_id )
-
Filters whether the network is considered large.
Skip to note 3 content
Rami Yushuvaev
Whether the network has more than 5,000 users/sites instead of 10,000:
function custom_large_network( $is_large_network, $component, $count, $network_id ) { return ( $count > 5000); } add_filter( 'wp_is_large_network', 'custom_large_network', 10, 4 );Source: https://generatewp.com/snippet/9XaNVan/
Skip to note 4 content
Rami Yushuvaev
Whether the network has more than 5,000 users/sites instead of 10,000:
function custom_large_network( $is_large_network, $component, $count, $network_id ) { return 5; } add_filter( 'wp_is_large_network', 'custom_large_network', 10, 4 );Source: https://generatewp.com/snippet/9XaNVan/