How do you use unzip_file()?

I have been trying to use the unzip_file() function. It says undefined so I looked into it and the WP_Filesystem() must be called and set up. So easy, right?

require_once(ABSPATH .'/wp-admin/includes/file.php');

WP_Filesystem();

unzip_file( $zip, $dest  );

Even this shows as undefined, and I don’t see any documentation on it. I am trying to use the unzip feature to unpack a separate plugin during theme install.

2 Answers
2

require_once(ABSPATH .'/wp-admin/includes/file.php');

global $wp_filesystem;
if ( ! $filesystem ) {
  WP_Filesystem();
    if ( ! $wp_filesystem )
      nuke_the_world_because_wpfs_cannot_be_initialized_in_case_of_missing_arguments('!');
}

$result = unzip_file( $zip, $dest );
if ( is_wp_error( $result ) )
   nuke_the_world();

Maybe some error handling make it easier.

Leave a Comment