wp_is_large_user_count()
云策文档标注
概述
wp_is_large_user_count() 函数用于判断站点是否拥有大量用户,默认标准为超过 10,000 个用户。它支持多站点环境,并可接受网络 ID 参数。
关键要点
- 函数返回布尔值,表示站点用户数是否超过默认阈值(10,000)。
- 参数 $network_id 可选,用于指定网络 ID,默认为当前网络;在非多站点环境中传递此参数会触发 _doing_it_wrong() 警告。
- 通过 wp_is_large_user_count 过滤器可自定义判断逻辑,允许开发者调整阈值或禁用功能。
- 函数内部调用 get_user_count() 获取用户数,并应用过滤器返回结果。
代码示例
// 禁用 wp_is_large_user_count() 功能
add_filter( 'wp_is_large_user_count', '__return_false' );注意事项
- 在非多站点环境中,不应传递 $network_id 参数,否则会触发警告。
- 默认阈值 10,000 可通过过滤器修改,以适应不同站点规模。
- 函数自 WordPress 6.0.0 版本引入,相关功能如 wp_maybe_update_user_counts() 依赖此判断。
原文内容
Determines whether the site has a large number of users.
Description
The default criteria for a large site is more than 10,000 users.
Parameters
$network_idint|nulloptional-
ID of the network. Defaults to the current network.
Default:
null
Source
function wp_is_large_user_count( $network_id = null ) {
if ( ! is_multisite() && null !== $network_id ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: %s: $network_id */
__( 'Unable to pass %s if not using multisite.' ),
'<code>$network_id</code>'
),
'6.0.0'
);
}
$count = get_user_count( $network_id );
/**
* Filters whether the site is considered large, based on its number of users.
*
* @since 6.0.0
*
* @param bool $is_large_user_count Whether the site has a large number of users.
* @param int $count The total number of users.
* @param int|null $network_id ID of the network. `null` represents the current network.
*/
return apply_filters( 'wp_is_large_user_count', $count > 10000, $count, $network_id );
}
Hooks
- apply_filters( ‘wp_is_large_user_count’, bool $is_large_user_count, int $count, int|null $network_id )
-
Filters whether the site is considered large, based on its number of users.
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |
Skip to note 2 content
Anton Proskurin
// if you would like to disable it add_filter( 'wp_is_large_user_count', '__return_false' );