WC_Download_Handler::parse_file_path PHP Méthode

parse_file_path() public static méthode

Parse file path and see if its remote or local.
public static parse_file_path ( string $file_path ) : array
$file_path string
Résultat array
    public static function parse_file_path($file_path)
    {
        $wp_uploads = wp_upload_dir();
        $wp_uploads_dir = $wp_uploads['basedir'];
        $wp_uploads_url = $wp_uploads['baseurl'];
        // Replace uploads dir, site url etc with absolute counterparts if we can
        $replacements = array($wp_uploads_url => $wp_uploads_dir, network_site_url('/', 'https') => ABSPATH, network_site_url('/', 'http') => ABSPATH, site_url('/', 'https') => ABSPATH, site_url('/', 'http') => ABSPATH);
        $file_path = str_replace(array_keys($replacements), array_values($replacements), $file_path);
        $parsed_file_path = parse_url($file_path);
        $remote_file = true;
        // See if path needs an abspath prepended to work
        if (file_exists(ABSPATH . $file_path)) {
            $remote_file = false;
            $file_path = ABSPATH . $file_path;
            // Check if we have an absolute path
        } elseif ((!isset($parsed_file_path['scheme']) || !in_array($parsed_file_path['scheme'], array('http', 'https', 'ftp'))) && isset($parsed_file_path['path']) && file_exists($parsed_file_path['path'])) {
            $remote_file = false;
            $file_path = $parsed_file_path['path'];
        }
        return array('remote_file' => $remote_file, 'file_path' => $file_path);
    }