pre_count_users
云策文档标注
概述
pre_count_users 是一个 WordPress 过滤器钩子,用于在 count_users() 函数执行查询前过滤用户计数结果。开发者可以通过此钩子提前返回自定义值,从而跳过默认的用户计数查询。
关键要点
- pre_count_users 钩子允许在运行 count_users() 查询前修改或覆盖用户计数结果。
- 返回非空值(如数组)将导致 count_users() 函数提前返回该值,而不执行后续查询。
- 钩子接受三个参数:$result(默认 null)、$strategy(计算策略,可选 'time' 或 'memory')和 $site_id(站点 ID)。
- 此钩子自 WordPress 5.1.0 版本引入,主要用于优化用户计数性能或自定义计数逻辑。
代码示例
$pre = apply_filters( 'pre_count_users', null, $strategy, $site_id );
原文内容
Filters the user count before queries are run.
Description
Return a non-null value to cause count_users() to return early.
Parameters
$resultnull|array-
The value to return instead. Default null to continue with the query.
$strategystring-
The computational strategy to use when counting the users.
Accepts either'time'or'memory'. Default'time'. $site_idint-
The site ID to count users for.
Source
$pre = apply_filters( 'pre_count_users', null, $strategy, $site_id );
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |