allowed_http_request_hosts()
云策文档标注
概述
allowed_http_request_hosts() 是一个 WordPress 函数,用于通过 'http_request_host_is_external' 过滤器标记允许的 HTTP 请求重定向主机为安全。它检查主机是否被 wp_validate_redirect() 验证为有效,从而影响外部主机判断。
关键要点
- 函数附加到 'http_request_host_is_external' 过滤器,用于控制 HTTP 请求中主机的外部性判断。
- 接受两个参数:$is_external(布尔值,必需)和 $host(字符串,必需),返回布尔值。
- 内部逻辑:如果 $is_external 为 false 且主机通过 wp_validate_redirect() 验证,则将 $is_external 设置为 true。
- 相关函数:wp_validate_redirect(),用于验证重定向 URL 的有效性。
- 自 WordPress 3.6.0 版本引入。
代码示例
function allowed_http_request_hosts( $is_external, $host ) {
if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) {
$is_external = true;
}
return $is_external;
}
原文内容
Marks allowed redirect hosts safe for HTTP requests as well.
Description
Attached to the ‘http_request_host_is_external’ filter.
Parameters
$is_externalboolrequired$hoststringrequired
Source
function allowed_http_request_hosts( $is_external, $host ) {
if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) ) {
$is_external = true;
}
return $is_external;
}
Changelog
| Version | Description |
|---|---|
| 3.6.0 | Introduced. |