pre_get_network_by_path
云策文档标注
概述
pre_get_network_by_path 是一个 WordPress 过滤器钩子,用于根据域名和路径确定网络,允许开发者自定义网络检索逻辑以优化性能。
关键要点
- 此钩子位于 wp_get_network() 函数中,用于在默认网络查找逻辑之前进行干预。
- 返回 null 可避免短路,继续执行默认逻辑;返回 false 表示未找到网络;返回 WP_Network 对象则直接使用。
- 参数包括 $network(默认 null)、$domain(请求的域名)、$path(请求的完整路径)、$segments(建议的路径段数,默认 null)和 $paths(基于 $path 和 $segments 的路径数组)。
- 首次引入于 WordPress 3.9.0 版本。
代码示例
$pre = apply_filters( 'pre_get_network_by_path', null, $domain, $path, $segments, $paths );注意事项
此钩子主要用于多站点网络环境,允许开发者实现更高效的网络匹配算法,例如基于缓存或自定义数据库查询。
原文内容
Determines a network by its domain and path.
Description
This allows one to short-circuit the default logic, perhaps by replacing it with a routine that is more optimal for your setup.
Return null to avoid the short-circuit. Return false if no network can be found at the requested domain and path. Otherwise, return an object from wp_get_network() .
Parameters
$networknull|false|WP_Network-
Network value to return by path. Default null to continue retrieving the network.
$domainstring-
The requested domain.
$pathstring-
The requested path, in full.
$segmentsint|null-
The suggested number of paths to consult.
Default null, meaning the entire path was to be consulted. $pathsstring[]-
Array of paths to search for, based on
$pathand$segments.
Source
$pre = apply_filters( 'pre_get_network_by_path', null, $domain, $path, $segments, $paths );
Changelog
| Version | Description |
|---|---|
| 3.9.0 | Introduced. |