Make WordPress Core

Ticket #31532: 31532.3.diff

File 31532.3.diff, 4.9 KB (added by jorbin, 11 years ago)
  • src/wp-admin/admin-ajax.php

     
    6161        'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
    6262        'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
    6363        'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail',
    64         'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post',
    65         'press-this-add-category',
     64        'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'activate-plugin', 'update-plugin',
     65        'press-this-save-post', 'press-this-add-category',
    6666);
    6767
    6868// Register core Ajax calls.
  • src/wp-admin/css/common.css

     
    13631363        margin-left: 2em;
    13641364}
    13651365
     1366.plugin-card div.error {
     1367        margin: 5px 10px;
     1368}
     1369
    13661370/* @todo: this does not need its own section anymore */
    13671371/*------------------------------------------------------------------------------
    13681372  6.0 - Admin Header
  • src/wp-admin/includes/ajax-actions.php

     
    29192919                wp_send_json_error( $status );
    29202920        }
    29212921
     2922        if ( is_multisite() ) {
     2923                wp_send_json_success( $status );
     2924        }
     2925
    29222926        $plugin_status = install_plugin_install_status( $api );
     2927        $plugin = $plugin_status['file'];
    29232928
    2924         if ( ! is_multisite() ) {
    2925                 activate_plugin( $plugin_status['file'] );
     2929        $url  = admin_url( 'admin-ajax.php' );
     2930        $args = array(
     2931                /** This filter is documented in wp-includes/class-http.php */
     2932                'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
     2933                'body'      => array(
     2934                        'action'  => 'activate-plugin',
     2935                        'nonce'   => wp_create_nonce( 'ajax-activate-plugin_' . $plugin ),
     2936                        'plugin'  => $plugin,
     2937                ),
     2938                'cookies'   => array(
     2939                        LOGGED_IN_COOKIE => $_COOKIE[ LOGGED_IN_COOKIE ],
     2940                ),
     2941        );
     2942
     2943        $response = wp_remote_post( $url, $args );
     2944
     2945        if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
     2946                $status['error'] = __( 'Could not activate plugin.' );
     2947                $status['errorCode'] = 'unable_to_activate_plugin';
     2948                wp_send_json_error( $status );
    29262949        }
    29272950
     2951        $body = wp_remote_retrieve_body( $response );
     2952        $activate_result = json_decode( $body );
     2953
     2954        if ( null === $activate_result ) {
     2955                $status['error'] = __( 'Could not activate plugin.' );
     2956                $status['errorCode'] = 'unable_to_activate_plugin';
     2957                wp_send_json_error( $status );
     2958        }
     2959
     2960        if ( false === $activate_result->success ) {
     2961                $status['error'] = $activate_result->data;
     2962                wp_send_json_error( $status );
     2963        }
     2964
    29282965        wp_send_json_success( $status );
    29292966}
    29302967
    29312968/**
     2969 * AJAX handler for activating a plugin.
     2970 *
     2971 * @since 4.2.0
     2972 */
     2973function wp_ajax_activate_plugin() {
     2974        $plugin = $_POST['plugin'];
     2975
     2976        $verify = wp_verify_nonce( $_POST['nonce'], 'ajax-activate-plugin_' . $plugin );
     2977
     2978        if ( ! $verify ) {
     2979                wp_send_json_error( __( 'Could not activate plugin.' ) );
     2980        }
     2981
     2982        include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
     2983
     2984        $result = activate_plugin( $plugin );
     2985
     2986        if ( is_wp_error( $result ) ) {
     2987                wp_send_json_error( $result->get_error_message() );
     2988        }
     2989
     2990        wp_send_json_success( true );
     2991}
     2992
     2993/**
    29322994 * AJAX handler for updating a plugin.
    29332995 *
    29342996 * @since 4.2.0
  • src/wp-admin/js/updates.js

     
    333333                        wp.updates.credentialError( response, 'install-plugin' );
    334334                        return;
    335335                }
     336                if ( response.errorCode && response.errorCode == 'unable_to_activate_plugin' ) {
     337                        $( '.plugin-card-' + response.slug ).prepend( '<div class="error"><p>' + response.error + '</p></div>' );       
     338                        $message.removeClass( 'updating-message' ).addClass( 'button-disabled' );
     339                        $message.text( wp.updates.l10n.installFailed );
     340                        wp.a11y.speak( wp.updates.l10n.noInstallMsg );
     341                        return;
     342                }
    336343
    337344                $message.removeClass( 'updating-message' );
    338345                $message.text( wp.updates.l10n.installNow );
  • src/wp-includes/script-loader.php

     
    556556                                'installingMsg' => __( 'Installing... please wait.' ),
    557557                                'updatedMsg'    => __( 'Update completed successfully.' ),
    558558                                'installedMsg'  => __( 'Installation completed successfully.' ),
     559                                'noInstallMsg'  => __( 'Installation Failed.' ),
     560                                'noUpdateMsg'   => __( 'Update Failed.' ),
    559561                        )
    560562                ) );
    561563