From b6058e2231639e99b446165b697e835cefce0690 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Fri, 17 Jul 2015 03:59:28 +0000 Subject: [PATCH] Updates: Correctly identify more failed update cases. This checks for a WP_Error being raised during an individual update, in addition to just the bootstrap error cases. When a error occurs during the connection phase, pass the error message back as the ajax failure message. Merges [32571] & [32778] to the 4.2 branch See #32473, #32435 Built from https://develop.svn.wordpress.org/branches/4.2@33302 git-svn-id: http://core.svn.wordpress.org/branches/4.2@33274 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ajax-actions.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index cfb3ccce3e..423a159f78 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -2883,6 +2883,8 @@ function wp_ajax_destroy_sessions() { * @see Plugin_Upgrader */ function wp_ajax_update_plugin() { + global $wp_filesystem; + $plugin = urldecode( $_POST['plugin'] ); $status = array( @@ -2909,10 +2911,15 @@ function wp_ajax_update_plugin() { wp_update_plugins(); - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); + $skin = new Automatic_Upgrader_Skin(); + $upgrader = new Plugin_Upgrader( $skin ); $result = $upgrader->bulk_upgrade( array( $plugin ) ); - if ( is_array( $result ) ) { + if ( is_array( $result ) && empty( $result[$plugin] ) && is_wp_error( $skin->result ) ) { + $result = $skin->result; + } + + if ( is_array( $result ) && !empty( $result[ $plugin ] ) ) { $plugin_update_data = current( $result ); /* @@ -2938,10 +2945,18 @@ function wp_ajax_update_plugin() { } else if ( is_wp_error( $result ) ) { $status['error'] = $result->get_error_message(); wp_send_json_error( $status ); - } else if ( is_bool( $result ) && ! $result ) { + + } else if ( is_bool( $result ) && ! $result ) { $status['errorCode'] = 'unable_to_connect_to_filesystem'; $status['error'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); + + // Pass through the error from WP_Filesystem if one was raised + if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { + $status['error'] = $wp_filesystem->errors->get_error_message(); + } + wp_send_json_error( $status ); + } }