pre_get_blogs_of_user
云策文档标注
概述
pre_get_blogs_of_user 是一个 WordPress 过滤器钩子,用于在 get_blogs_of_user() 函数填充用户站点列表之前进行过滤。通过此钩子,开发者可以自定义或拦截用户站点的获取过程。
关键要点
- 过滤器名称:pre_get_blogs_of_user
- 作用时机:在 get_blogs_of_user() 函数执行前触发,允许修改或替换返回的站点列表
- 参数:$sites(站点数组,初始为 null)、$user_id(用户 ID)、$all(布尔值,控制是否包含已删除、归档或垃圾站点)
- 返回值:如果过滤器返回非 null 值,将直接作为 get_blogs_of_user() 的结果,跳过默认逻辑
- 相关函数:get_blogs_of_user(),用于获取用户所属站点
- 引入版本:WordPress 4.6.0
原文内容
Filters the list of a user’s sites before it is populated.
Description
Returning a non-null value from the filter will effectively short circuit get_blogs_of_user() , returning that value instead.
Parameters
$sitesnull|object[]-
An array of site objects of which the user is a member.
$user_idint-
User ID.
$allbool-
Whether the returned array should contain all sites, including those marked
'deleted','archived', or'spam'. Default false.
Source
$sites = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all );
Changelog
| Version | Description |
|---|---|
| 4.6.0 | Introduced. |