Administration: Handle the result of Plugin_Upgrader::bulk_upgrade() for a plugin that is already at the latest version in the same way it is handled for themes.

This corrects a fragile check of the result in `wp_ajax_update_plugin()` that depended on the internal array pointer, and brings some consistency with `wp_ajax_update_theme()`.

Follow-up to [37714], [48401].
See #50448.
Built from https://develop.svn.wordpress.org/trunk@48445


git-svn-id: http://core.svn.wordpress.org/trunk@48214 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-07-12 01:16:05 +00:00
parent 81a001117c
commit cecf7b9823
5 changed files with 11 additions and 10 deletions

View File

@ -4462,18 +4462,18 @@ function wp_ajax_update_plugin() {
$status['errorMessage'] = $skin->get_error_messages(); $status['errorMessage'] = $skin->get_error_messages();
wp_send_json_error( $status ); wp_send_json_error( $status );
} elseif ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) { } elseif ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) {
$plugin_update_data = current( $result );
/* /*
* If the `update_plugins` site transient is empty (e.g. when you update * Plugin is already at the latest version.
* two plugins in quick succession before the transient repopulates), *
* this may be the return. * This may also be the return value If the `update_plugins` site transient is empty,
* e.g. when you update two plugins in quick succession before the transient repopulates.
* *
* Preferably something can be done to ensure `update_plugins` isn't empty. * Preferably something can be done to ensure `update_plugins` isn't empty.
* For now, surface some sort of error here. * For now, surface some sort of error here.
*/ */
if ( true === $plugin_update_data ) { if ( true === $result[ $plugin ] ) {
$status['errorMessage'] = __( 'Plugin update failed.' ); $status['errorMessage'] = $upgrader->strings['up_to_date'];
wp_send_json_error( $status ); wp_send_json_error( $status );
} }
@ -4484,6 +4484,7 @@ function wp_ajax_update_plugin() {
/* translators: %s: Plugin version. */ /* translators: %s: Plugin version. */
$status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); $status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
} }
wp_send_json_success( $status ); wp_send_json_success( $status );
} elseif ( false === $result ) { } elseif ( false === $result ) {
global $wp_filesystem; global $wp_filesystem;

View File

@ -391,8 +391,8 @@ class Plugin_Upgrader extends WP_Upgrader {
unset( $past_failure_emails[ $plugin ] ); unset( $past_failure_emails[ $plugin ] );
} }
update_option( 'auto_plugin_theme_update_emails', $past_failure_emails ); update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
reset( $results );
return $results; return $results;
} }

View File

@ -500,8 +500,8 @@ class Theme_Upgrader extends WP_Upgrader {
unset( $past_failure_emails[ $theme ] ); unset( $past_failure_emails[ $theme ] );
} }
update_option( 'auto_plugin_theme_update_emails', $past_failure_emails ); update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
reset( $results );
return $results; return $results;
} }

View File

@ -660,7 +660,7 @@ class WP_Upgrader {
* @type array $hook_extra Extra arguments to pass to the filter hooks called by * @type array $hook_extra Extra arguments to pass to the filter hooks called by
* WP_Upgrader::run(). * WP_Upgrader::run().
* } * }
* @return array|false|WP_error The result from self::install_package() on success, otherwise a WP_Error, * @return array|false|WP_Error The result from self::install_package() on success, otherwise a WP_Error,
* or false if unable to connect to the filesystem. * or false if unable to connect to the filesystem.
*/ */
public function run( $options ) { public function run( $options ) {

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.5-beta1-48444'; $wp_version = '5.5-beta1-48445';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.