normalize_url( $url ); $compare = $url_normalizer->normalize_url( $compare ); return $url === $compare; } /** * Compares two domains for whether they qualify for a Site Verification or Search Console domain match. * * The value to compare may be either a domain or a full URL. If the latter, its scheme and a potential trailing * slash will be stripped out before the comparison. * * In order for the comparison to be considered a match then, the domains have to fully match, except for a * potential "www." prefix, which will be ignored. If the value to compare is a full URL and includes a path other * than just a trailing slash, it will not be a match. * * @since 1.6.0 * * @param string $domain A domain. * @param string $compare The domain or URL to compare. * @return bool True if the URLs/domains are considered a match, false otherwise. */ protected function is_domain_match( $domain, $compare ) { $domain = $this->strip_domain_www( $domain ); $compare = $this->strip_domain_www( $this->strip_url_scheme( untrailingslashit( $compare ) ) ); $url_normalizer = new Google_URL_Normalizer(); $domain = $url_normalizer->normalize_url( $domain ); $compare = $url_normalizer->normalize_url( $compare ); return $domain === $compare; } /** * Strips the scheme from a URL. * * @since 1.6.0 * * @param string $url URL with or without scheme. * @return string The passed $url without its scheme. */ protected function strip_url_scheme( $url ) { return preg_replace( '#^(\w+:)?//#', '', $url ); } /** * Strips the "www." prefix from a domain. * * @since 1.6.0 * * @param string $domain Domain with or without "www." prefix. * @return string The passed $domain without "www." prefix. */ protected function strip_domain_www( $domain ) { return preg_replace( '/^www\./', '', $domain ); } }