From 7abfd84c75a05c360d59f163880a1aa7a0e494c0 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Thu, 1 Feb 2018 05:17:33 +0000 Subject: [PATCH] Plugins: Use `api.wordpress.org/plugins/info/1.2/` for querying plugins & plugin information. See #43192. Fixes #29274. Built from https://develop.svn.wordpress.org/trunk@42631 git-svn-id: http://core.svn.wordpress.org/trunk@42460 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-plugin-install-list-table.php | 15 ++-- wp-admin/includes/plugin-install.php | 73 +++++++++++-------- wp-admin/update-core.php | 6 -- wp-admin/update.php | 13 +--- wp-includes/version.php | 2 +- 5 files changed, 48 insertions(+), 61 deletions(-) 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 c755f96fbd..f82180109e 100644 --- a/wp-admin/includes/class-wp-plugin-install-list-table.php +++ b/wp-admin/includes/class-wp-plugin-install-list-table.php @@ -145,14 +145,8 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { $args = array( 'page' => $paged, 'per_page' => $per_page, - 'fields' => array( - 'last_updated' => true, - 'icons' => true, - 'active_installs' => true, - ), - // Send the locale and installed plugin slugs to the API so it can provide context-sensitive results. + // Send the locale to the API so it can provide context-sensitive results. 'locale' => get_user_locale(), - 'installed_plugins' => array_keys( $installed_plugins ), ); switch ( $tab ) { @@ -175,14 +169,15 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { break; case 'featured': - $args['fields']['group'] = true; - $this->orderby = 'group'; - // No break! case 'popular': case 'new': case 'beta': + $args['browse'] = $tab; + break; case 'recommended': $args['browse'] = $tab; + // Include the list of installed plugins so we can get relevant results. + $args['installed_plugins'] = array_keys( $installed_plugins ); break; case 'favorites': diff --git a/wp-admin/includes/plugin-install.php b/wp-admin/includes/plugin-install.php index 1838ce1cb3..d8b9cd3c8a 100644 --- a/wp-admin/includes/plugin-install.php +++ b/wp-admin/includes/plugin-install.php @@ -99,19 +99,27 @@ * for more information on the make-up of possible return values depending on the value of `$action`. */ function plugins_api( $action, $args = array() ) { + // include an unmodified $wp_version + include( ABSPATH . WPINC . '/version.php' ); if ( is_array( $args ) ) { $args = (object) $args; } - if ( ! isset( $args->per_page ) ) { - $args->per_page = 24; + if ( 'query_plugins' == $action ) { + if ( ! isset( $args->per_page ) ) { + $args->per_page = 24; + } } if ( ! isset( $args->locale ) ) { $args->locale = get_user_locale(); } + if ( ! isset( $args->wp_version ) ) { + $args->wp_version = substr( $wp_version, 0, 3 ); // X.y + } + /** * Filters the WordPress.org Plugin Installation API arguments. * @@ -141,10 +149,17 @@ function plugins_api( $action, $args = array() ) { $res = apply_filters( 'plugins_api', false, $action, $args ); if ( false === $res ) { - // include an unmodified $wp_version - include( ABSPATH . WPINC . '/version.php' ); - $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/'; + $url = 'http://api.wordpress.org/plugins/info/1.2/'; + $url = add_query_arg( + array( + 'action' => $action, + 'request' => $args, + ), + $url + ); + + $http_url = $url; if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { $url = set_url_scheme( $url, 'https' ); } @@ -152,12 +167,8 @@ function plugins_api( $action, $args = array() ) { $http_args = array( 'timeout' => 15, 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), - 'body' => array( - 'action' => $action, - 'request' => serialize( $args ), - ), ); - $request = wp_remote_post( $url, $http_args ); + $request = wp_remote_get( $url, $http_args ); if ( $ssl && is_wp_error( $request ) ) { trigger_error( @@ -168,7 +179,7 @@ function plugins_api( $action, $args = array() ) { ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE ); - $request = wp_remote_post( $http_url, $http_args ); + $request = wp_remote_get( $http_url, $http_args ); } if ( is_wp_error( $request ) ) { @@ -182,8 +193,11 @@ function plugins_api( $action, $args = array() ) { $request->get_error_message() ); } else { - $res = maybe_unserialize( wp_remote_retrieve_body( $request ) ); - if ( ! is_object( $res ) && ! is_array( $res ) ) { + $res = json_decode( wp_remote_retrieve_body( $request ), true ); + if ( is_array( $res ) ) { + // Object casting is required in order to match the info/1.0 format. + $res = (object) $res; + } elseif ( null === $res ) { $res = new WP_Error( 'plugins_api_failed', sprintf( @@ -194,6 +208,10 @@ function plugins_api( $action, $args = array() ) { wp_remote_retrieve_body( $request ) ); } + + if ( isset( $res->error ) ) { + $res = new WP_Error( 'plugins_api_failed', $res->error ); + } } } elseif ( ! is_wp_error( $res ) ) { $res->external = true; @@ -485,13 +503,6 @@ function install_plugin_information() { $api = plugins_api( 'plugin_information', array( 'slug' => wp_unslash( $_REQUEST['plugin'] ), - 'is_ssl' => is_ssl(), - 'fields' => array( - 'banners' => true, - 'reviews' => true, - 'downloaded' => false, - 'active_installs' => true, - ), ) ); @@ -707,19 +718,17 @@ if ( ! empty( $api->contributors ) ) {

diff --git a/wp-admin/update-core.php b/wp-admin/update-core.php index f6f10bee7e..0808364216 100644 --- a/wp-admin/update-core.php +++ b/wp-admin/update-core.php @@ -277,9 +277,6 @@ foreach ( (array) $plugins as $plugin_file => $plugin_data ) { // Get plugin compat for running version of WordPress. if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $cur_wp_version, '>=' ) ) { $compat = '
' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $cur_wp_version ); - } elseif ( isset( $plugin_data->update->compatibility->{$cur_wp_version} ) ) { - $compat = $plugin_data->update->compatibility->{$cur_wp_version}; - $compat = '
' . sprintf( __( 'Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)' ), $cur_wp_version, $compat->percent, $compat->votes, $compat->total_votes ); } else { $compat = '
' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $cur_wp_version ); } @@ -287,9 +284,6 @@ foreach ( (array) $plugins as $plugin_file => $plugin_data ) { if ( $core_update_version ) { if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) { $compat .= '
' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $core_update_version ); - } elseif ( isset( $plugin_data->update->compatibility->{$core_update_version} ) ) { - $update_compat = $plugin_data->update->compatibility->{$core_update_version}; - $compat .= '
' . sprintf( __( 'Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)' ), $core_update_version, $update_compat->percent, $update_compat->votes, $update_compat->total_votes ); } else { $compat .= '
' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $core_update_version ); } diff --git a/wp-admin/update.php b/wp-admin/update.php index bb7bf8f7bb..5b07beb710 100644 --- a/wp-admin/update.php +++ b/wp-admin/update.php @@ -109,18 +109,7 @@ if ( isset( $_GET['action'] ) ) { 'plugin_information', array( 'slug' => $plugin, 'fields' => array( - 'short_description' => false, - 'sections' => false, - 'requires' => false, - 'rating' => false, - 'ratings' => false, - 'downloaded' => false, - 'last_updated' => false, - 'added' => false, - 'tags' => false, - 'compatibility' => false, - 'homepage' => false, - 'donate_link' => false, + 'sections' => false, ), ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index bfc769e95a..7ff6a1ae0b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-alpha-42630'; +$wp_version = '5.0-alpha-42631'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.