Make WordPress Core

Ticket #41407: 41407.diff

File 41407.diff, 3.4 KB (added by swissspidy, 7 years ago)
  • src/wp-admin/includes/class-wp-plugin-install-list-table.php

    diff --git src/wp-admin/includes/class-wp-plugin-install-list-table.php src/wp-admin/includes/class-wp-plugin-install-list-table.php
    index 39442a6034..e82f5c993d 100644
    class WP_Plugin_Install_List_Table extends WP_List_Table { 
    3232        }
    3333
    3434        /**
    35          * Return a list of slugs of installed plugins, if known.
     35         * Return the list of known plugins.
    3636         *
    37          * Uses the transient data from the updates API to determine the slugs of
    38          * known installed plugins. This might be better elsewhere, perhaps even
    39          * within get_plugins().
     37         * Uses the transient data from the updates API to determine the known
     38         * installed plugins.
    4039         *
    41          * @since 4.0.0
     40         * @since 4.9.0
     41         * @access protected
    4242         *
    4343         * @return array
    4444         */
    45         protected function get_installed_plugin_slugs() {
    46                 $slugs = array();
     45        protected function get_installed_plugins() {
     46                $plugins = array();
    4747
    4848                $plugin_info = get_site_transient( 'update_plugins' );
    4949                if ( isset( $plugin_info->no_update ) ) {
    5050                        foreach ( $plugin_info->no_update as $plugin ) {
    51                                 $slugs[] = $plugin->slug;
     51                                $plugin->upgrade          = false;
     52                                $plugins[ $plugin->slug ] = $plugin;
    5253                        }
    5354                }
    5455
    5556                if ( isset( $plugin_info->response ) ) {
    5657                        foreach ( $plugin_info->response as $plugin ) {
    57                                 $slugs[] = $plugin->slug;
     58                                $plugin->upgrade          = true;
     59                                $plugins[ $plugin->slug ] = $plugin;
    5860                        }
    5961                }
    6062
    61                 return $slugs;
     63                return $plugins;
     64        }
     65
     66        /**
     67         * Return a list of slugs of installed plugins, if known.
     68         *
     69         * Uses the transient data from the updates API to determine the slugs of
     70         * known installed plugins. This might be better elsewhere, perhaps even
     71         * within get_plugins().
     72         *
     73         * @since 4.0.0
     74         *
     75         * @return array
     76         */
     77        protected function get_installed_plugin_slugs() {
     78                return array_keys( $this->get_installed_plugins() );
    6279        }
    6380
    6481        /**
    class WP_Plugin_Install_List_Table extends WP_List_Table { 
    124141                if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
    125142                        $tab = key( $tabs );
    126143
     144                $installed_plugins = $this->get_installed_plugins();
     145
    127146                $args = array(
    128147                        'page' => $paged,
    129148                        'per_page' => $per_page,
    class WP_Plugin_Install_List_Table extends WP_List_Table { 
    134153                        ),
    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
    140159                switch ( $tab ) {
    class WP_Plugin_Install_List_Table extends WP_List_Table { 
    224243                if ( isset( $api->info['groups'] ) ) {
    225244                        $this->groups = $api->info['groups'];
    226245                }
     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                        ) );
     264                }
    227265        }
    228266
    229267        /**