wp filesystem – unzip_file not working with the remote file

Question

I’m trying to use unzip_file to extract the remote archive with no success. It works only with the local path using get_template_directory() but with a remote zip archive URL I’m getting Incompatible Archive. message.

Here is the stripped version of my code:

WP_Filesystem();
global $wp_filesystem;

$source="http://downloads.wordpress.org/theme/ona-creative.1.0.0.zip";
$unzipfile = unzip_file( $source, get_theme_root() );

if ( is_wp_error( $unzipfile ) ) {
    wp_send_json(
        array(
            'done'    => 1,
            'message' => esc_html__( $unzipfile->get_error_message() . ' There was an error unzipping the file.', 'ona' )
        )
    ); 
}

0
Alexander 2 months 2022-05-15T01:11:19-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse