ms_allowed_http_request_hosts() WordPress Function

The ms_allowed_http_request_hosts() function allows you to specify which domains can make HTTP requests to your WordPress site. This is useful if you want to restrict access to your site to only certain domains. By default, this function allows requests from any domain.

ms_allowed_http_request_hosts( bool $is_external, string $host ) #

Adds any domain in a multisite installation for safe HTTP requests to the allowed list.


Description

Attached to the ‘http_request_host_is_external’ filter.


Top ↑

Parameters

$is_external

(bool)(Required)

$host

(string)(Required)


Top ↑

Return

(bool)


Top ↑

Source

File: wp-includes/http.php

function ms_allowed_http_request_hosts( $is_external, $host ) {
	global $wpdb;
	static $queried = array();
	if ( $is_external ) {
		return $is_external;
	}
	if ( get_network()->domain === $host ) {
		return true;
	}
	if ( isset( $queried[ $host ] ) ) {
		return $queried[ $host ];
	}
	$queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) );
	return $queried[ $host ];
}


Top ↑

Changelog

Changelog
VersionDescription
3.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.