Make WordPress Core

Changeset 48445


Ignore:
Timestamp:
07/12/2020 01:14:01 AM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
5 edited

Legend:

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

    r48375 r48445  
    44634463        wp_send_json_error( $status );
    44644464    } elseif ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) {
    4465         $plugin_update_data = current( $result );
    44664465
    44674466        /*
    4468          * If the `update_plugins` site transient is empty (e.g. when you update
    4469          * two plugins in quick succession before the transient repopulates),
    4470          * this may be the return.
     4467         * Plugin is already at the latest version.
     4468         *
     4469         * This may also be the return value If the `update_plugins` site transient is empty,
     4470         * e.g. when you update two plugins in quick succession before the transient repopulates.
    44714471         *
    44724472         * Preferably something can be done to ensure `update_plugins` isn't empty.
    44734473         * For now, surface some sort of error here.
    44744474         */
    4475         if ( true === $plugin_update_data ) {
    4476             $status['errorMessage'] = __( 'Plugin update failed.' );
     4475        if ( true === $result[ $plugin ] ) {
     4476            $status['errorMessage'] = $upgrader->strings['up_to_date'];
    44774477            wp_send_json_error( $status );
    44784478        }
     
    44854485            $status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
    44864486        }
     4487
    44874488        wp_send_json_success( $status );
    44884489    } elseif ( false === $result ) {
  • trunk/src/wp-admin/includes/class-plugin-upgrader.php

    r48401 r48445  
    392392            unset( $past_failure_emails[ $plugin ] );
    393393        }
     394
    394395        update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
    395         reset( $results );
    396396
    397397        return $results;
  • trunk/src/wp-admin/includes/class-theme-upgrader.php

    r48401 r48445  
    501501            unset( $past_failure_emails[ $theme ] );
    502502        }
     503
    503504        update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
    504         reset( $results );
    505505
    506506        return $results;
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r48399 r48445  
    661661     *                                               WP_Upgrader::run().
    662662     * }
    663      * @return array|false|WP_error The result from self::install_package() on success, otherwise a WP_Error,
     663     * @return array|false|WP_Error The result from self::install_package() on success, otherwise a WP_Error,
    664664     *                              or false if unable to connect to the filesystem.
    665665     */
  • trunk/tests/phpunit/tests/ajax/UpdatePlugin.php

    r47198 r48445  
    158158                'plugin'       => 'hello.php',
    159159                'pluginName'   => 'Hello Dolly',
    160                 'errorMessage' => 'Plugin update failed.',
     160                'errorMessage' => 'The plugin is at the latest version.',
    161161                'oldVersion'   => 'Version 1.7.2',
    162162                'newVersion'   => '',
Note: See TracChangeset for help on using the changeset viewer.