Make WordPress Core


Ignore:
Timestamp:
09/27/2017 11:59:01 AM (7 years ago)
Author:
swissspidy
Message:

Upgrade/Install: Fix updating plugins on the Add Plugins screen.

Props imath.
Fixes #41407.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-plugin-install-list-table.php

    r41608 r41612  
    3333
    3434    /**
     35     * Return the list of known plugins.
     36     *
     37     * Uses the transient data from the updates API to determine the known
     38     * installed plugins.
     39     *
     40     * @since 4.9.0
     41     * @access protected
     42     *
     43     * @return array
     44     */
     45    protected function get_installed_plugins() {
     46        $plugins = array();
     47
     48        $plugin_info = get_site_transient( 'update_plugins' );
     49        if ( isset( $plugin_info->no_update ) ) {
     50            foreach ( $plugin_info->no_update as $plugin ) {
     51                $plugin->upgrade          = false;
     52                $plugins[ $plugin->slug ] = $plugin;
     53            }
     54        }
     55
     56        if ( isset( $plugin_info->response ) ) {
     57            foreach ( $plugin_info->response as $plugin ) {
     58                $plugin->upgrade          = true;
     59                $plugins[ $plugin->slug ] = $plugin;
     60            }
     61        }
     62
     63        return $plugins;
     64    }
     65
     66    /**
    3567     * Return a list of slugs of installed plugins, if known.
    3668     *
     
    4476     */
    4577    protected function get_installed_plugin_slugs() {
    46         $slugs = array();
    47 
    48         $plugin_info = get_site_transient( 'update_plugins' );
    49         if ( isset( $plugin_info->no_update ) ) {
    50             foreach ( $plugin_info->no_update as $plugin ) {
    51                 $slugs[] = $plugin->slug;
    52             }
    53         }
    54 
    55         if ( isset( $plugin_info->response ) ) {
    56             foreach ( $plugin_info->response as $plugin ) {
    57                 $slugs[] = $plugin->slug;
    58             }
    59         }
    60 
    61         return $slugs;
     78        return array_keys( $this->get_installed_plugins() );
    6279    }
    6380
     
    124141        if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
    125142            $tab = key( $tabs );
     143
     144        $installed_plugins = $this->get_installed_plugins();
    126145
    127146        $args = array(
     
    135154            // Send the locale and installed plugin slugs to the API so it can provide context-sensitive results.
    136155            'locale' => get_user_locale(),
    137             'installed_plugins' => $this->get_installed_plugin_slugs(),
     156            'installed_plugins' => array_keys( $installed_plugins ),
    138157        );
    139158
     
    224243        if ( isset( $api->info['groups'] ) ) {
    225244            $this->groups = $api->info['groups'];
     245        }
     246
     247        if ( $installed_plugins ) {
     248            $js_plugins = array_fill_keys(
     249                array( 'all', 'search', 'active', 'inactive', 'recently_activated', 'mustuse', 'dropins' ),
     250                array()
     251            );
     252
     253            $js_plugins['all'] = array_values( wp_list_pluck( $installed_plugins, 'plugin' ) );
     254            $upgrade_plugins   = wp_filter_object_list( $installed_plugins, array( 'upgrade' => true ), 'and', 'plugin' );
     255
     256            if ( $upgrade_plugins ) {
     257                $js_plugins['upgrade'] = array_values( $upgrade_plugins );
     258            }
     259
     260            wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
     261                'plugins' => $js_plugins,
     262                'totals'  => wp_get_update_data(),
     263            ) );
    226264        }
    227265    }
Note: See TracChangeset for help on using the changeset viewer.