public static function sanitize_domain($domain = '') {
		if (!is_string($domain)) {
			return false;
		}

		$domain = mb::strtolower(trim($domain));

		// Try to parse a full URL.
		$host = wp_parse_url($domain, PHP_URL_HOST);
		if (!$host) {
			// Strip path?
			if (false !== ($start = mb::strpos($domain, '/'))) {
				$domain = mb::substr($domain, 0, $start);
			}

			// Strip query?
			if (false !== ($start = mb::strpos($domain, '?'))) {
				$domain = mb::substr($domain, 0, $start);
			}

			// Strip port?
			if (
				!filter_var($domain, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) &&
				false !== ($start = mb::strpos($domain, ':'))
			) {
				$domain = mb::substr($domain, 0, $start);
			}

			// Bail if invalid characters at this point.
			if (filter_var($domain, FILTER_SANITIZE_URL) !== $domain) {
				return false;
			}
		} else {
			$domain = $host;
		}

		if (is_string($domain)) {
			$domain = preg_replace('/^www\./u', '', $domain);
		}

		return $domain ? $domain : false;
	}