Requests::match_domain() WordPress Method

The match_domain() method is used to check if the current request is for a given domain. This can be used to short-circuit requests for a domain that is not configured for the site. This is useful for sites that are hosted on multiple domains, where some domains are used for development or staging purposes. By checking the domain of the current request, you can ensure that only requests for the live site are processed.

Requests::match_domain( $host,  $reference ) #

Contents


Source

File: wp-includes/class-requests.php

	public static function match_domain($host, $reference) {
		// Check for a direct match
		if ($host === $reference) {
			return true;
		}

		// Calculate the valid wildcard match if the host is not an IP address
		// Also validates that the host has 3 parts or more, as per Firefox's
		// ruleset.
		$parts = explode('.', $host);
		if (ip2long($host) === false && count($parts) >= 3) {
			$parts[0] = '*';
			$wildcard = implode('.', $parts);
			if ($wildcard === $reference) {
				return true;
			}
		}

		return false;
	}

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.