钩子文档

http_request_host_is_external

💡 云策文档标注

概述

该文档介绍了 WordPress 中的 http_request_host_is_external 过滤器,用于检查 HTTP 请求是否为外部请求,并允许开发者修改此判断逻辑。

关键要点

  • http_request_host_is_external 是一个过滤器,用于控制 HTTP 请求是否被视为外部请求。
  • 该过滤器接受三个参数:$external(布尔值,表示请求是否为外部)、$host(字符串,请求的主机名)和 $url(字符串,请求的 URL)。
  • 默认情况下,过滤器返回 false,但开发者可以通过 apply_filters 修改返回值以允许或阻止外部请求。
  • 该过滤器在 WordPress 3.6.0 版本中引入,常用于 wp_http_validate_url() 函数中验证 URL 的安全性。

代码示例

if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) {
    // 代码逻辑
}

📄 原文内容

Checks if HTTP request is external or not.

Description

Allows to change and allow external requests for the HTTP request.

Parameters

$externalbool
Whether HTTP request is external or not.
$hoststring
Host name of the requested URL.
$urlstring
Requested URL.

Source

if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) ) {

Changelog

Version Description
3.6.0 Introduced.