WordPress.org

Make WordPress Core

Ticket #12230: 12230.diff

File 12230.diff, 1.8 KB (added by dd32, 8 years ago)
  • wp-admin/includes/file.php

     
    528528                }
    529529        }
    530530
    531         if ( class_exists('ZipArchive') && apply_filters('unzip_file_use_ziparchive', true ) )
    532                 return _unzip_file_ziparchive($file, $to, $needed_dirs);
    533         else
    534                 return _unzip_file_pclzip($file, $to, $needed_dirs);
     531        if ( class_exists('ZipArchive') && apply_filters('unzip_file_use_ziparchive', true ) ) {
     532                $result = _unzip_file_ziparchive($file, $to, $needed_dirs);
     533                if ( $result ) // true || WP_Error
     534                        return $result;
     535        }
     536        // Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.
     537        return _unzip_file_pclzip($file, $to, $needed_dirs);
    535538}
    536539
    537540/**
     
    545548 * @param string $file Full path and filename of zip archive
    546549 * @param string $to Full path on the filesystem to extract archive to
    547550 * @param array $needed_dirs A partial list of required folders needed to be created.
    548  * @return mixed WP_Error on failure, True on success
     551 * @return mixed WP_Error|false}true WP_Error for failure codes, false if the archive could not be read, true for success.
    549552 */
    550553function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) {
    551554        global $wp_filesystem;
     
    554557
    555558        // PHP4-compat - php4 classes can't contain constants
    556559        if ( true !== $z->open($file, /* ZIPARCHIVE::CHECKCONS */ 4) )
    557                 return new WP_Error('incompatible_archive', __('Incompatible Archive.'));
     560                return false;
    558561
    559562        for ( $i = 0; $i < $z->numFiles; $i++ ) {
    560563                if ( ! $info = $z->statIndex($i) )
     
    591594                        return new WP_Error('copy_failed', __('Could not copy file.'), $to . $file['filename']);
    592595        }
    593596
     597        $z->close();
     598
    594599        return true;
    595600}
    596601