Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.

git-svn-id: https://develop.svn.wordpress.org/trunk@48445 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov authored and SergeyBiryukov committed Jul 12, 2020
1 parent 7cf1e60 commit 9d30b02
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/wp-admin/includes/ajax-actions.php
Expand Up @@ -4462,18 +4462,18 @@ function wp_ajax_update_plugin() {
$status['errorMessage'] = $skin->get_error_messages();
wp_send_json_error( $status );
} 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
* two plugins in quick succession before the transient repopulates),
* this may be the return.
* Plugin is already at the latest version.
*
* 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.
* For now, surface some sort of error here.
*/
if ( true === $plugin_update_data ) {
$status['errorMessage'] = __( 'Plugin update failed.' );
if ( true === $result[ $plugin ] ) {
$status['errorMessage'] = $upgrader->strings['up_to_date'];
wp_send_json_error( $status );
}

Expand All @@ -4484,6 +4484,7 @@ function wp_ajax_update_plugin() {
/* translators: %s: Plugin version. */
$status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
}

wp_send_json_success( $status );
} elseif ( false === $result ) {
global $wp_filesystem;
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-plugin-upgrader.php
Expand Up @@ -391,8 +391,8 @@ public function bulk_upgrade( $plugins, $args = array() ) {

unset( $past_failure_emails[ $plugin ] );
}

update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
reset( $results );

return $results;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-theme-upgrader.php
Expand Up @@ -500,8 +500,8 @@ public function bulk_upgrade( $themes, $args = array() ) {

unset( $past_failure_emails[ $theme ] );
}

update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
reset( $results );

return $results;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-wp-upgrader.php
Expand Up @@ -660,7 +660,7 @@ public function install_package( $args = array() ) {
* @type array $hook_extra Extra arguments to pass to the filter hooks called by
* 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.
*/
public function run( $options ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/ajax/UpdatePlugin.php
Expand Up @@ -157,7 +157,7 @@ public function test_update_plugin() {
'slug' => 'hello-dolly',
'plugin' => 'hello.php',
'pluginName' => 'Hello Dolly',
'errorMessage' => 'Plugin update failed.',
'errorMessage' => 'The plugin is at the latest version.',
'oldVersion' => 'Version 1.7.2',
'newVersion' => '',
'debug' => array( 'The plugin is at the latest version.' ),
Expand Down

0 comments on commit 9d30b02

Please sign in to comment.