Make WordPress Core

Changeset 31897


Ignore:
Timestamp:
03/26/2015 02:29:52 AM (10 years ago)
Author:
jorbin
Message:

Remove Shiny Plugin Installs

See #31773, #29820

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r31829 r31897  
    28772877}
    28782878
    2879 /**
    2880  * AJAX handler for installing a plugin.
    2881  *
    2882  * @since 4.2.0
    2883  */
    2884 function wp_ajax_install_plugin() {
    2885     $status = array(
    2886         'install' => 'plugin',
    2887         'slug'    => sanitize_key( $_POST['slug'] ),
    2888     );
    2889 
    2890     if ( ! current_user_can( 'install_plugins' ) ) {
    2891         $status['error'] = __( 'You do not have sufficient permissions to install plugins on this site.' );
    2892         wp_send_json_error( $status );
    2893     }
    2894 
    2895     check_ajax_referer( 'updates' );
    2896 
    2897     include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    2898     include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    2899 
    2900     $api = plugins_api( 'plugin_information', array(
    2901         'slug'   => sanitize_key( $_POST['slug'] ),
    2902         'fields' => array( 'sections' => false )
    2903     ) );
    2904 
    2905     if ( is_wp_error( $api ) ) {
    2906         $status['error'] = $api->get_error_message();
    2907         wp_send_json_error( $status );
    2908     }
    2909 
    2910     $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
    2911     $result = $upgrader->install( $api->download_link );
    2912 
    2913     if ( is_wp_error( $result ) ) {
    2914         $status['error'] = $result->get_error_message();
    2915         wp_send_json_error( $status );
    2916     } else if ( is_null( $result ) ) {
    2917         $status['errorCode'] = 'unable_to_connect_to_filesystem';
    2918         $status['error'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
    2919         wp_send_json_error( $status );
    2920     }
    2921 
    2922     $plugin_status = install_plugin_install_status( $api );
    2923 
    2924     if ( ! is_multisite() ) {
    2925         activate_plugin( $plugin_status['file'] );
    2926     }
    2927 
    2928     wp_send_json_success( $status );
    2929 }
    29302879
    29312880/**
  • trunk/src/wp-admin/js/updates.js

    r31831 r31897  
    5252
    5353    /**
    54      * Flag if we're waiting for an install/update to complete.
     54     * Flag if we're waiting for an update to complete.
    5555     *
    5656     * @since 4.2.0
     
    6161
    6262    /**
    63      * * Flag if we've done an install or update successfully.
     63     * * Flag if we've done an update successfully.
    6464     *
    6565     * @since 4.2.0
     
    7070
    7171    /**
    72      * If the user tries to install/update a plugin while an install/update is
     72     * If the user tries to update a plugin while an update is
    7373     * already happening, it can be placed in this queue to perform later.
    7474     *
     
    254254
    255255        $notificationDialog.find( 'h3' ).after( '<div class="error">' + message + '</div>' );
    256     };
    257 
    258     /**
    259      * Send an Ajax request to the server to install a plugin.
    260      *
    261      * @since 4.2.0
    262      *
    263      * @param {string} slug
    264      */
    265     wp.updates.installPlugin = function( slug ) {
    266         var $message = $( '.plugin-card-' + slug ).find( '.install-now' );
    267 
    268         $message.addClass( 'updating-message' );
    269         $message.text( wp.updates.l10n.installing );
    270         wp.a11y.speak( wp.updates.l10n.installingMsg );
    271 
    272         if ( wp.updates.updateLock ) {
    273             wp.updates.updateQueue.push( {
    274                 type: 'install-plugin',
    275                 data: {
    276                     slug: slug
    277                 }
    278             } );
    279             return;
    280         }
    281 
    282         wp.updates.updateLock = true;
    283 
    284         var data = {
    285             _ajax_nonce:     wp.updates.ajaxNonce,
    286             slug:            slug,
    287             username:        wp.updates.filesystemCredentials.ftp.username,
    288             password:        wp.updates.filesystemCredentials.ftp.password,
    289             hostname:        wp.updates.filesystemCredentials.ftp.hostname,
    290             connection_type: wp.updates.filesystemCredentials.ftp.connectionType,
    291             public_key:      wp.updates.filesystemCredentials.ssh.publicKey,
    292             private_key:     wp.updates.filesystemCredentials.ssh.privateKey
    293         };
    294 
    295         wp.ajax.post( 'install-plugin', data )
    296             .done( wp.updates.installSuccess )
    297             .fail( wp.updates.installError );
    298     };
    299 
    300     /**
    301      * On plugin install success, update the UI with the result.
    302      *
    303      * @since 4.2.0
    304      *
    305      * @param {object} response
    306      */
    307     wp.updates.installSuccess = function( response ) {
    308         var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' );
    309 
    310         $message.removeClass( 'updating-message' ).addClass( 'updated-message button-disabled' );
    311         $message.text( wp.updates.l10n.installed );
    312         wp.a11y.speak( wp.updates.l10n.installedMsg );
    313         wp.updates.updateDoneSuccessfully = true;
    314 
    315         /*
    316          * The lock can be released since the update was successful,
    317          * and any other updates can commence.
    318          */
    319         wp.updates.updateLock = false;
    320         wp.updates.queueChecker();
    321     };
    322 
    323     /**
    324      * On plugin install failure, update the UI appropriately.
    325      *
    326      * @since 4.2.0
    327      *
    328      * @param {object} response
    329      */
    330     wp.updates.installError = function( response ) {
    331         var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' );
    332         wp.updates.updateDoneSuccessfully = false;
    333         if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' ) {
    334             wp.updates.credentialError( response, 'install-plugin' );
    335             return;
    336         }
    337 
    338         $message.removeClass( 'updating-message' );
    339         $message.text( wp.updates.l10n.installNow );
    340 
    341         wp.updates.updateLock = false;
    342256    };
    343257
     
    362276
    363277    /**
    364      * If an install/update job has been placed in the queue, queueChecker pulls it out and runs it.
     278     * If an update job has been placed in the queue, queueChecker pulls it out and runs it.
    365279     *
    366280     * @since 4.2.0
     
    373287        var job = wp.updates.updateQueue.shift();
    374288
     289        /* This normally wouldn't be a switch, but is there since updates and installs
     290           originally were developed together. Kept as a switch to help with bringing
     291           installs back in and to preserve commit history. */
    375292        switch ( job.type ) {
    376293            case 'update-plugin':
    377294                wp.updates.updatePlugin( job.data.plugin, job.data.slug );
    378                 break;
    379             case 'install-plugin':
    380                 wp.updates.installPlugin( job.data.slug );
    381295                break;
    382296            default:
     
    464378        } );
    465379
    466         $( '.plugin-card .install-now' ).on( 'click', function( e ) {
    467             e.preventDefault();
    468             if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.updateLock ) {
    469                 wp.updates.requestFilesystemCredentials();
    470             }
    471             var $button = $( e.target );
    472             if ( $button.hasClass( 'button-disabled' ) ) {
    473                 return;
    474             }
    475             wp.updates.installPlugin( $button.data( 'slug' ) );
    476         } );
    477380    } );
    478381
Note: See TracChangeset for help on using the changeset viewer.