Jetpack_Photon::validate_image_url PHP Méthode

validate_image_url() protected static méthode

Though Photon functions address some of the URL issues, we should avoid unnecessary processing if we know early on that the image isn't supported.
protected static validate_image_url ( string $url ) : boolean
$url string
Résultat boolean
    protected static function validate_image_url($url)
    {
        $parsed_url = @parse_url($url);
        if (!$parsed_url) {
            return false;
        }
        // Parse URL and ensure needed keys exist, since the array returned by `parse_url` only includes the URL components it finds.
        $url_info = wp_parse_args($parsed_url, array('scheme' => null, 'host' => null, 'port' => null, 'path' => null));
        // Bail if scheme isn't http or port is set that isn't port 80
        if (('http' != $url_info['scheme'] || !in_array($url_info['port'], array(80, null))) && apply_filters('jetpack_photon_reject_https', false)) {
            return false;
        }
        // Bail if no host is found
        if (is_null($url_info['host'])) {
            return false;
        }
        // Bail if the image alredy went through Photon
        if (preg_match('#^i[\\d]{1}.wp.com$#i', $url_info['host'])) {
            return false;
        }
        // Bail if no path is found
        if (is_null($url_info['path'])) {
            return false;
        }
        // Ensure image extension is acceptable
        if (!in_array(strtolower(pathinfo($url_info['path'], PATHINFO_EXTENSION)), self::$extensions)) {
            return false;
        }
        // If we got this far, we should have an acceptable image URL
        // But let folks filter to decline if they prefer.
        /**
         * Overwrite the results of the validation steps an image goes through before to be considered valid to be used by Photon.
         *
         * @module photon
         *
         * @since 3.0.0
         *
         * @param bool true Is the image URL valid and can it be used by Photon. Default to true.
         * @param string $url Image URL.
         * @param array $parsed_url Array of information about the image.
         */
        return apply_filters('photon_validate_image_url', true, $url, $parsed_url);
    }