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/update.php

    r47808 r48390  
    158158
    159159        /* translators: %s: File name. */
    160         $title = sprintf( __( 'Installing Plugin from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
     160        $title = sprintf( __( 'Installing plugin from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
    161161        $nonce = 'plugin-upload';
    162162        $url   = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-plugin' );
    163163        $type  = 'upload'; // Install plugin type, From Web or an Upload.
    164164
    165         $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
    166         $result   = $upgrader->install( $file_upload->package );
     165        $overwrite = isset( $_GET['overwrite'] ) ? sanitize_text_field( $_GET['overwrite'] ) : '';
     166        $overwrite = in_array( $overwrite, array( 'update-plugin', 'downgrade-plugin' ), true ) ? $overwrite : '';
     167
     168        $upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url', 'overwrite' ) ) );
     169        $result   = $upgrader->install( $file_upload->package, array( 'overwrite_package' => $overwrite ) );
    167170
    168171        if ( $result || is_wp_error( $result ) ) {
     
    278281
    279282        /* translators: %s: File name. */
    280         $title = sprintf( __( 'Installing Theme from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
     283        $title = sprintf( __( 'Installing theme from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
    281284        $nonce = 'theme-upload';
    282285        $url   = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-theme' );
    283286        $type  = 'upload'; // Install theme type, From Web or an Upload.
    284287
    285         $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
    286         $result   = $upgrader->install( $file_upload->package );
     288        $overwrite = isset( $_GET['overwrite'] ) ? sanitize_text_field( $_GET['overwrite'] ) : '';
     289        $overwrite = in_array( $overwrite, array( 'update-theme', 'downgrade-theme' ), true ) ? $overwrite : '';
     290
     291        $upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url', 'overwrite' ) ) );
     292        $result   = $upgrader->install( $file_upload->package, array( 'overwrite_package' => $overwrite ) );
    287293
    288294        if ( $result || is_wp_error( $result ) ) {
Note: See TracChangeset for help on using the changeset viewer.