The http_request_host_is_external WordPress PHP Filter allows you to change and control if external requests for the HTTP request are permitted.
Usage
add_filter('http_request_host_is_external', 'your_custom_function', 10, 3);
function your_custom_function($external, $host, $url) {
// your custom code here
return $external;
}
Parameters
$external(bool): Whether the HTTP request is external or not.$host(string): Hostname of the requested URL.$url(string): The requested URL.
More information
See WordPress Developer Resources: http_request_host_is_external
Examples
Allow all external requests
This example allows all external requests to be processed.
add_filter('http_request_host_is_external', '__return_true');
Block all external requests
This example blocks all external requests from being processed.
add_filter('http_request_host_is_external', '__return_false');
Allow specific domain for external requests
This example allows external requests only from the specified domain.
add_filter('http_request_host_is_external', 'allow_specific_domain', 10, 3);
function allow_specific_domain($external, $host, $url) {
if ('example.com' === $host) {
return true;
}
return $external;
}
Allow external requests only for specific URL patterns
This example allows external requests only for specific URL patterns.
add_filter('http_request_host_is_external', 'allow_specific_url_pattern', 10, 3);
function allow_specific_url_pattern($external, $host, $url) {
if (preg_match('/^https:\/\/(www\.)?example\.com\/\w+/', $url)) {
return true;
}
return $external;
}
Block external requests for specific URL patterns
This example blocks external requests for specific URL patterns.
add_filter('http_request_host_is_external', 'block_specific_url_pattern', 10, 3);
function block_specific_url_pattern($external, $host, $url) {
if (preg_match('/^https:\/\/(www\.)?example\.com\/blocked\//', $url)) {
return false;
}
return $external;
}