Plugins: Use `api.wordpress.org/plugins/info/1.2/` for querying plugins & plugin information.

See #43192.
Fixes #29274.


git-svn-id: https://develop.svn.wordpress.org/trunk@42631 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2018-02-01 05:16:15 +00:00
parent cc9a5641a6
commit e0d5a8ac54
4 changed files with 47 additions and 60 deletions

View File

@ -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':

View File

@ -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 ) ) {
<h3><?php _e( 'Contributors' ); ?></h3>
<ul class="contributors">
<?php
foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
continue;
}
if ( empty( $contrib_username ) ) {
$contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
}
$contrib_username = sanitize_user( $contrib_username );
if ( empty( $contrib_profile ) ) {
echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' alt='' />{$contrib_username}</li>";
} else {
echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' alt='' />{$contrib_username}</a></li>";
foreach ( (array) $api->contributors as $contrib_username => $contrib_details ) {
$contrib_name = $contrib_details['display_name'];
if ( ! $contrib_name ) {
$contrin_name = $contrib_username;
}
$contrib_name = esc_html( $contrib_name );
$contrib_profile = esc_url( $contrib_details['profile'] );
$contrib_avatar = esc_url( add_query_arg( 's', '36', $contrib_details['avatar'] ) );
echo "<li><a href='{$contrib_profile}' target='_blank'><img src='{$contrib_avatar}' width='18' height='18' alt='' />{$contrib_name}</a></li>";
}
?>
</ul>

View File

@ -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 = '<br />' . 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 = '<br />' . 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 = '<br />' . 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 .= '<br />' . 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 .= '<br />' . 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 .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $core_update_version );
}

View File

@ -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,
),
)
);