Make WordPress Core


Ignore:
Timestamp:
07/07/2020 05:47:37 PM (6 years ago)
Author:
azaozz
Message:

Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.

Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.

Fixes #9757.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-theme-upgrader.php

    r47814 r48390  
    3939
    4040        /**
     41         * New theme info.
     42         *
     43         * @since 5.5.0
     44         * @var array $new_theme_data
     45         *
     46         * @see check_package()
     47         */
     48        public $new_theme_data = array();
     49
     50        /**
    4151         * Initialize the upgrade strings.
    4252         *
     
    6676                $this->strings['unpack_package']      = __( 'Unpacking the package…' );
    6777                $this->strings['installing_package']  = __( 'Installing the theme…' );
     78                $this->strings['remove_old']          = __( 'Removing the old version of the theme…' );
     79                $this->strings['remove_old_failed']   = __( 'Could not remove the old theme.' );
    6880                $this->strings['no_files']            = __( 'The theme contains no files.' );
    6981                $this->strings['process_failed']      = __( 'Theme installation failed.' );
     
    8092                /* translators: %s: Theme name. */
    8193                $this->strings['parent_theme_not_found'] = sprintf( __( '<strong>The parent theme could not be found.</strong> You will need to install the parent theme, %s, before you can use this child theme.' ), '<strong>%s</strong>' );
     94                /* translators: %s: Theme error. */
     95                $this->strings['current_theme_has_errors'] = __( 'The current theme has the following error: "%s".' );
     96
     97                if ( 'update-theme' === $this->skin->overwrite ) {
     98                        $this->strings['installing_package'] = __( 'Updating the theme&#8230;' );
     99                        $this->strings['process_failed']     = __( 'Theme update failed.' );
     100                        $this->strings['process_success']    = __( 'Theme updated successfully.' );
     101                }
     102
     103                if ( 'downgrade-theme' === $this->skin->overwrite ) {
     104                        $this->strings['installing_package'] = __( 'Downgrading the theme&#8230;' );
     105                        $this->strings['process_failed']     = __( 'Theme downgrade failed.' );
     106                        $this->strings['process_success']    = __( 'Theme downgraded successfully.' );
     107                }
    82108        }
    83109
     
    201227         */
    202228        public function install( $package, $args = array() ) {
    203 
    204229                $defaults    = array(
    205230                        'clear_update_cache' => true,
     231                        'overwrite_package'  => false, // Do not overwrite files.
    206232                );
    207233                $parsed_args = wp_parse_args( $args, $defaults );
     
    221247                                'package'           => $package,
    222248                                'destination'       => get_theme_root(),
    223                                 'clear_destination' => false, // Do not overwrite files.
     249                                'clear_destination' => $args['overwrite_package'],
    224250                                'clear_working'     => true,
    225251                                'hook_extra'        => array(
     
    241267                wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
    242268
     269                if ( $parsed_args['overwrite_package'] ) {
     270                        /**
     271                         * Fires when the upgrader has successfully overwritten a currently installed
     272                         * plugin or theme with an uploaded zip package.
     273                         *
     274                         * @since 5.5.0
     275                         *
     276                         * @param string  $package          The package file.
     277                         * @param array   $new_plugin_data  The new theme data.
     278                         * @param string  $package_type     The package type (plugin or theme).
     279                         */
     280                        do_action( 'upgrader_overwrote_package', $package, $this->new_theme_data, 'theme' );
     281                }
     282
    243283                return true;
    244284        }
     
    260300         */
    261301        public function upgrade( $theme, $args = array() ) {
    262 
    263302                $defaults    = array(
    264303                        'clear_update_cache' => true,
     
    333372         */
    334373        public function bulk_upgrade( $themes, $args = array() ) {
    335 
    336374                $defaults    = array(
    337375                        'clear_update_cache' => true,
     
    462500                global $wp_filesystem;
    463501
     502                $this->new_theme_data = array();
     503
    464504                if ( is_wp_error( $source ) ) {
    465505                        return $source;
     
    485525                }
    486526
     527                // All these headers are needed on Theme_Installer_Skin::do_overwrite().
    487528                $info = get_file_data(
    488529                        $working_directory . 'style.css',
    489530                        array(
    490                                 'Name'     => 'Theme Name',
    491                                 'Template' => 'Template',
     531                                'Name'        => 'Theme Name',
     532                                'Version'     => 'Version',
     533                                'Author'      => 'Author',
     534                                'Template'    => 'Template',
     535                                'RequiresWP'  => 'Requires at least',
     536                                'RequiresPHP' => 'Requires PHP',
    492537                        )
    493538                );
     
    518563                }
    519564
     565                $this->new_theme_data = $info;
    520566                return $source;
    521567        }
     
    641687         */
    642688        public function theme_info( $theme = null ) {
    643 
    644689                if ( empty( $theme ) ) {
    645690                        if ( ! empty( $this->result['destination_name'] ) ) {
     
    649694                        }
    650695                }
    651                 return wp_get_theme( $theme );
     696
     697                $theme = wp_get_theme( $theme );
     698                $theme->cache_delete();
     699
     700                return $theme;
    652701        }
    653702
Note: See TracChangeset for help on using the changeset viewer.