Ticket #14999: 14999.diff

File 14999.diff, 2.5 KB (added by dd32, 21 months ago)

initial draft

  • wp-admin/includes/class-wp-upgrader.php

     
    4848                /* translators: %s: directory name */ 
    4949                $this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).'); 
    5050 
     51                $this->strings['incompatible_archive'] = __('The package is corrupt or not compatible with the system. Please try again.'); 
     52 
    5153                $this->strings['download_failed'] = __('Download failed.'); 
    5254                $this->strings['installing_package'] = __('Installing the latest version…'); 
    5355                $this->strings['folder_exists'] = __('Destination folder already exists.'); 
     
    153155 
    154156                if ( is_wp_error($result) ) { 
    155157                        $wp_filesystem->delete($working_dir, true); 
     158                        if ( 'incompatible_archive' == $result->get_error_code() ) { 
     159                                return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() ); 
     160                        } 
    156161                        return $result; 
    157162                } 
    158163 
     
    624629                $this->strings['installing_package'] = __('Installing the theme…'); 
    625630                $this->strings['process_failed'] = __('Theme install failed.'); 
    626631                $this->strings['process_success'] = __('Theme installed successfully.'); 
     632                $this->strings['wrong_format'] = __('The provided package is not in the required format.'); 
    627633        } 
    628634 
     635        function unpack_package($package, $delete_package = true) { 
     636                global $wp_filesystem; 
     637                $working_dir = parent::unpack_package($package, $delete_package); 
     638 
     639                if ( is_wp_error($working_dir) ) 
     640                        return $working_dir; 
     641 
     642                $problem = false; 
     643                $dirlist = $wp_filesystem->dirlist( $working_dir ); 
     644                unset( $dirlist[ '__MAC_OSX' ] ); // Some mac archives have a meta directory we need to exclude fromthis check 
     645                 
     646                if ( !$dirlist || count($dirlist) > 1 ) { // A proper archive should have a single directory entry 
     647                        $problem = true; 
     648                } else { 
     649                        $folder = array_shift( array_keys($dirlist) ); 
     650                        $dirlist = $wp_filesystem->dirlist( $working_dir . '/' . $folder ); 
     651 
     652                        if ( ! isset($dirlist[ 'style.css' ]) ) // A proper archive should have a style.css file in the single subdirectory 
     653                                $problem = true; 
     654                        // Check file header meta too? 
     655                } 
     656 
     657                // Check the extracted files are in the correct format. 
     658                if ( $problem ) { 
     659                        $wp_filesystem->delete($working_dir, true); 
     660                        return new WP_Error('wrong_format', $this->strings['wrong_format']); 
     661                } 
     662                 
     663                return $working_dir; 
     664        } 
     665 
    629666        function install($package) { 
    630667 
    631668                $this->init();