Make WordPress Core


Ignore:
Timestamp:
07/07/2020 05:47:37 PM (4 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-plugin-upgrader.php

    r47814 r48390  
    4040
    4141    /**
     42     * New plugin info.
     43     *
     44     * @since 5.5.0
     45     * @var array $new_plugin_data
     46     *
     47     * @see check_package()
     48     */
     49    public $new_plugin_data = array();
     50
     51    /**
    4252     * Initialize the upgrade strings.
    4353     *
     
    5565        $this->strings['process_success']      = __( 'Plugin updated successfully.' );
    5666        $this->strings['process_bulk_success'] = __( 'Plugins updated successfully.' );
     67
     68        /* translators: 1: Plugin name, 2: Plugin version. */
     69        $this->strings['process_success_specific'] = __( 'Successfully installed the plugin <strong>%1$s %2$s</strong>.' );
    5770    }
    5871
     
    6881        $this->strings['unpack_package']      = __( 'Unpacking the package&#8230;' );
    6982        $this->strings['installing_package']  = __( 'Installing the plugin&#8230;' );
     83        $this->strings['remove_old']          = __( 'Removing the current plugin&#8230;' );
     84        $this->strings['remove_old_failed']   = __( 'Could not remove the current plugin.' );
    7085        $this->strings['no_files']            = __( 'The plugin contains no files.' );
    7186        $this->strings['process_failed']      = __( 'Plugin installation failed.' );
    7287        $this->strings['process_success']     = __( 'Plugin installed successfully.' );
     88
     89        if ( ! empty( $this->skin->overwrite ) ) {
     90            if ( 'update-plugin' === $this->skin->overwrite ) {
     91                $this->strings['installing_package'] = __( 'Updating the plugin&#8230;' );
     92                $this->strings['process_failed']     = __( 'Plugin update failed.' );
     93                $this->strings['process_success']    = __( 'Plugin updated successfully.' );
     94            }
     95
     96            if ( 'downgrade-plugin' === $this->skin->overwrite ) {
     97                $this->strings['installing_package'] = __( 'Downgrading the plugin&#8230;' );
     98                $this->strings['process_failed']     = __( 'Plugin downgrade failed.' );
     99                $this->strings['process_success']    = __( 'Plugin downgraded successfully.' );
     100            }
     101        }
    73102    }
    74103
     
    89118     */
    90119    public function install( $package, $args = array() ) {
    91 
    92120        $defaults    = array(
    93121            'clear_update_cache' => true,
     122            'overwrite_package'  => false, // Do not overwrite files.
    94123        );
    95124        $parsed_args = wp_parse_args( $args, $defaults );
     
    108137                'package'           => $package,
    109138                'destination'       => WP_PLUGIN_DIR,
    110                 'clear_destination' => false, // Do not overwrite files.
     139                'clear_destination' => $parsed_args['overwrite_package'],
    111140                'clear_working'     => true,
    112141                'hook_extra'        => array(
     
    127156        wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
    128157
     158        if ( $parsed_args['overwrite_package'] ) {
     159            /**
     160             * Fires when the upgrader has successfully overwritten a currently installed
     161             * plugin or theme with an uploaded zip package.
     162             *
     163             * @since 5.5.0
     164             *
     165             * @param string  $package          The package file.
     166             * @param array   $new_plugin_data  The new plugin data.
     167             * @param string  $package_type     The package type (plugin or theme).
     168             */
     169            do_action( 'upgrader_overwrote_package', $package, $this->new_plugin_data, 'plugin' );
     170        }
     171
    129172        return true;
    130173    }
     
    146189     */
    147190    public function upgrade( $plugin, $args = array() ) {
    148 
    149191        $defaults    = array(
    150192            'clear_update_cache' => true,
     
    224266     */
    225267    public function bulk_upgrade( $plugins, $args = array() ) {
    226 
    227268        $defaults    = array(
    228269            'clear_update_cache' => true,
     
    350391        global $wp_filesystem;
    351392
     393        $this->new_plugin_data = array();
     394
    352395        if ( is_wp_error( $source ) ) {
    353396            return $source;
     
    360403
    361404        // Check that the folder contains at least 1 valid plugin.
    362         $plugins_found = false;
    363         $files         = glob( $working_directory . '*.php' );
     405        $files = glob( $working_directory . '*.php' );
    364406        if ( $files ) {
    365407            foreach ( $files as $file ) {
    366408                $info = get_plugin_data( $file, false, false );
    367409                if ( ! empty( $info['Name'] ) ) {
    368                     $plugins_found = true;
     410                    $this->new_plugin_data = $info;
    369411                    break;
    370412                }
     
    372414        }
    373415
    374         if ( ! $plugins_found ) {
     416        if ( empty( $this->new_plugin_data ) ) {
    375417            return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
    376418        }
Note: See TracChangeset for help on using the changeset viewer.