From 9e33ac1beecc68230e357bde161dea1d05f5f1a4 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Fri, 18 Jul 2014 20:50:15 +0000 Subject: [PATCH] Plugin Install screens: Pass locale and installed plugins to the API, for context. props tellyworth. see #17902. Built from https://develop.svn.wordpress.org/trunk@29227 git-svn-id: http://core.svn.wordpress.org/trunk@29011 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-plugin-install-list-table.php | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/class-wp-plugin-install-list-table.php b/wp-admin/includes/class-wp-plugin-install-list-table.php index 804da69e64..b0887f5c33 100644 --- a/wp-admin/includes/class-wp-plugin-install-list-table.php +++ b/wp-admin/includes/class-wp-plugin-install-list-table.php @@ -17,6 +17,34 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { return current_user_can('install_plugins'); } + /** + * Return a list of slugs of installed plugins, if known. + * + * Uses the transient data from the updates API to determine the slugs of + * known installed plugins. This might be better elsewhere, perhaps even + * within get_plugins(). + * + * @since 4.0.0 + */ + protected function get_installed_plugin_slugs() { + $slugs = array(); + + $plugin_info = get_site_transient( 'update_plugins' ); + if ( isset( $plugin_info->no_update ) ) { + foreach ( $plugin_info->no_update as $plugin ) { + $slugs[] = $plugin->slug; + } + } + + if ( isset( $plugin_info->response ) ) { + foreach ( $plugin_info->response as $plugin ) { + $slugs[] = $plugin->slug; + } + } + + return $slugs; + } + public function prepare_items() { include( ABSPATH . 'wp-admin/includes/plugin-install.php' ); @@ -66,7 +94,14 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) ) $tab = key( $tabs ); - $args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => array( 'last_updated' => true, 'downloaded' => true ) ); + $args = array( + 'page' => $paged, + 'per_page' => $per_page, + 'fields' => array( 'last_updated' => true, 'downloaded' => true ), + // Send the locale and installed plugin slugs to the API so it can provide context-sensitive results. + 'locale' => get_locale(), + 'installed_plugins' => $this->get_installed_plugin_slugs(), + ); switch ( $tab ) { case 'search':