WordPress.org

Make WordPress Core

Ticket #14999: 14999.2.diff

File 14999.2.diff, 2.7 KB (added by SergeyBiryukov, 7 years ago)
  • 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['multiple_directories'] = __('A proper theme archive should have a single directory entry.');
     633                $this->strings['missing_style'] = __('A proper theme archive should have a style.css file in a single subdirectory.');
    627634        }
    628635
     636        function unpack_package($package, $delete_package = true) {
     637                global $wp_filesystem;
     638                $working_dir = parent::unpack_package($package, $delete_package);
     639
     640                if ( is_wp_error($working_dir) )
     641                        return $working_dir;
     642
     643                $problem = false;
     644                $dirlist = $wp_filesystem->dirlist( $working_dir );
     645                unset( $dirlist[ '__MAC_OSX' ] ); // Some mac archives have a meta directory we need to exclude fromthis check
     646               
     647                if ( !$dirlist || count($dirlist) > 1 ) { // A proper archive should have a single directory entry
     648                        $problem = $this->strings['multiple_directories'];
     649                } else {
     650                        $folder = array_shift( array_keys($dirlist) );
     651                        $dirlist = $wp_filesystem->dirlist( $working_dir . '/' . $folder );
     652
     653                        if ( ! isset($dirlist[ 'style.css' ]) ) // A proper archive should have a style.css file in the single subdirectory
     654                                $problem = $this->strings['missing_style'];
     655                        // Check file header meta too?
     656                }
     657
     658                // Check the extracted files are in the correct format.
     659                if ( $problem ) {
     660                        $wp_filesystem->delete($working_dir, true);
     661                        return new WP_Error('wrong_format', $problem);
     662                }
     663               
     664                return $working_dir;
     665        }
     666
    629667        function install($package) {
    630668
    631669                $this->init();