pre_get_main_site_id
云策文档标注
概述
pre_get_main_site_id 是一个 WordPress 过滤器,用于在获取网络主站点 ID 时进行干预。开发者可以通过此过滤器返回一个正整数来直接指定主站点 ID,从而跳过默认的检测逻辑。
关键要点
- 过滤器名称:pre_get_main_site_id
- 作用:过滤主站点 ID,允许开发者自定义返回结果
- 参数:$main_site_id(整数或 null,用于接收过滤后的值),$network(WP_Network 对象,表示检测主站点的网络)
- 返回值:返回正整数将直接作为主站点 ID,否则继续执行默认逻辑
- 相关函数:WP_Network::get_main_site_id() 使用此过滤器
- 引入版本:WordPress 4.9.0
原文内容
Filters the main site ID.
Description
Returning a positive integer will effectively short-circuit the function.
Parameters
$main_site_idint|null-
If a positive integer is returned, it is interpreted as the main site ID.
$networkWP_Network-
The network object for which the main site was detected.
Source
$main_site_id = (int) apply_filters( 'pre_get_main_site_id', null, $this );
Changelog
| Version | Description |
|---|---|
| 4.9.0 | Introduced. |