unzip_file not working with the remote file

As @Buttered_Toast and @Sébastien Serre mentioned I first need to save file to a local directory before unzipping. So here is my final code: $source=”http://downloads.wordpress.org/theme/ona-creative.1.0.0.zip”; $file = get_theme_root() . “https://wordpress.stackexchange.com/” . $slug . ‘.zip’; file_put_contents( $file, file_get_contents( $source )); $unzipfile = unzip_file( $file, get_theme_root() );

What should I pass for $needed_dirs when calling _unzip_file_pclzip (aka PclZip)?

@Scott B I have not tested this script, taken from inlcudes/file.php -> line 559 _unzip_file_pclzip assumes WP_Filesystem() has already been called, so you need to set up global $wp_filesystem global $wp_filesystem; $needed_dirs = array(); $target = trailingslashit($target); // Determine any parent dir’s needed (of the upgrade directory) if ( ! $wp_filesystem->is_dir($target) ) { //Only do … Read more

How can I fix my server so core/plugins/theme update don’t silently fail?

There is a bug in some versions of PHP itself, unzip hangs. PHP 5.2.17 hangs, PHP 5.3.24 works as expected. PHP Change Log http://www.php.net/ChangeLog-5.php#5.3.4 says PHP Version 5.3.4 released 09-Dec-2010 – “Fixed crash in zip extract method (possible CWE-170)”. (Note: 5.3.24 released 11-April-2013, and is no longer the latest version.) http://lcblog.lernerconsult.com/2013-php-unzip-bug-makes-wordpress-updates-hang/ has the PHP program … Read more

Can a manually uploaded plugin be made to track updates from the WordPress.org plugin directory?

As long as everything was made according to WP best practices all your manually installed versions will update the same as the ones installed from wordpress.org. The updater looks at many things to identify your plugin. However, the most important is the plugin URI (you can change the directory of many plugins and they will … Read more

How do you use unzip_file()?

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.