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:
parent
cc9a5641a6
commit
e0d5a8ac54
@ -145,14 +145,8 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
|
|||||||
$args = array(
|
$args = array(
|
||||||
'page' => $paged,
|
'page' => $paged,
|
||||||
'per_page' => $per_page,
|
'per_page' => $per_page,
|
||||||
'fields' => array(
|
// Send the locale to the API so it can provide context-sensitive results.
|
||||||
'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.
|
|
||||||
'locale' => get_user_locale(),
|
'locale' => get_user_locale(),
|
||||||
'installed_plugins' => array_keys( $installed_plugins ),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
switch ( $tab ) {
|
switch ( $tab ) {
|
||||||
@ -175,14 +169,15 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'featured':
|
case 'featured':
|
||||||
$args['fields']['group'] = true;
|
|
||||||
$this->orderby = 'group';
|
|
||||||
// No break!
|
|
||||||
case 'popular':
|
case 'popular':
|
||||||
case 'new':
|
case 'new':
|
||||||
case 'beta':
|
case 'beta':
|
||||||
|
$args['browse'] = $tab;
|
||||||
|
break;
|
||||||
case 'recommended':
|
case 'recommended':
|
||||||
$args['browse'] = $tab;
|
$args['browse'] = $tab;
|
||||||
|
// Include the list of installed plugins so we can get relevant results.
|
||||||
|
$args['installed_plugins'] = array_keys( $installed_plugins );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'favorites':
|
case 'favorites':
|
||||||
|
@ -99,19 +99,27 @@
|
|||||||
* for more information on the make-up of possible return values depending on the value of `$action`.
|
* for more information on the make-up of possible return values depending on the value of `$action`.
|
||||||
*/
|
*/
|
||||||
function plugins_api( $action, $args = array() ) {
|
function plugins_api( $action, $args = array() ) {
|
||||||
|
// include an unmodified $wp_version
|
||||||
|
include( ABSPATH . WPINC . '/version.php' );
|
||||||
|
|
||||||
if ( is_array( $args ) ) {
|
if ( is_array( $args ) ) {
|
||||||
$args = (object) $args;
|
$args = (object) $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset( $args->per_page ) ) {
|
if ( 'query_plugins' == $action ) {
|
||||||
$args->per_page = 24;
|
if ( ! isset( $args->per_page ) ) {
|
||||||
|
$args->per_page = 24;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset( $args->locale ) ) {
|
if ( ! isset( $args->locale ) ) {
|
||||||
$args->locale = get_user_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.
|
* 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 );
|
$res = apply_filters( 'plugins_api', false, $action, $args );
|
||||||
|
|
||||||
if ( false === $res ) {
|
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' ) ) ) {
|
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
|
||||||
$url = set_url_scheme( $url, 'https' );
|
$url = set_url_scheme( $url, 'https' );
|
||||||
}
|
}
|
||||||
@ -152,12 +167,8 @@ function plugins_api( $action, $args = array() ) {
|
|||||||
$http_args = array(
|
$http_args = array(
|
||||||
'timeout' => 15,
|
'timeout' => 15,
|
||||||
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
|
'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 ) ) {
|
if ( $ssl && is_wp_error( $request ) ) {
|
||||||
trigger_error(
|
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.)' ),
|
) . ' ' . __( '(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
|
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 ) ) {
|
if ( is_wp_error( $request ) ) {
|
||||||
@ -182,8 +193,11 @@ function plugins_api( $action, $args = array() ) {
|
|||||||
$request->get_error_message()
|
$request->get_error_message()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
|
$res = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||||
if ( ! is_object( $res ) && ! is_array( $res ) ) {
|
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(
|
$res = new WP_Error(
|
||||||
'plugins_api_failed',
|
'plugins_api_failed',
|
||||||
sprintf(
|
sprintf(
|
||||||
@ -194,6 +208,10 @@ function plugins_api( $action, $args = array() ) {
|
|||||||
wp_remote_retrieve_body( $request )
|
wp_remote_retrieve_body( $request )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( isset( $res->error ) ) {
|
||||||
|
$res = new WP_Error( 'plugins_api_failed', $res->error );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elseif ( ! is_wp_error( $res ) ) {
|
} elseif ( ! is_wp_error( $res ) ) {
|
||||||
$res->external = true;
|
$res->external = true;
|
||||||
@ -485,13 +503,6 @@ function install_plugin_information() {
|
|||||||
$api = plugins_api(
|
$api = plugins_api(
|
||||||
'plugin_information', array(
|
'plugin_information', array(
|
||||||
'slug' => wp_unslash( $_REQUEST['plugin'] ),
|
'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>
|
<h3><?php _e( 'Contributors' ); ?></h3>
|
||||||
<ul class="contributors">
|
<ul class="contributors">
|
||||||
<?php
|
<?php
|
||||||
foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
|
foreach ( (array) $api->contributors as $contrib_username => $contrib_details ) {
|
||||||
if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
|
$contrib_name = $contrib_details['display_name'];
|
||||||
continue;
|
if ( ! $contrib_name ) {
|
||||||
}
|
$contrin_name = $contrib_username;
|
||||||
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}&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}&s=36' width='18' height='18' alt='' />{$contrib_username}</a></li>";
|
|
||||||
}
|
}
|
||||||
|
$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>
|
</ul>
|
||||||
|
@ -277,9 +277,6 @@ foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
|
|||||||
// Get plugin compat for running version of WordPress.
|
// Get plugin compat for running version of WordPress.
|
||||||
if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $cur_wp_version, '>=' ) ) {
|
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 );
|
$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 {
|
} else {
|
||||||
$compat = '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $cur_wp_version );
|
$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 ( $core_update_version ) {
|
||||||
if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $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 );
|
$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 {
|
} else {
|
||||||
$compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $core_update_version );
|
$compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $core_update_version );
|
||||||
}
|
}
|
||||||
|
@ -109,18 +109,7 @@ if ( isset( $_GET['action'] ) ) {
|
|||||||
'plugin_information', array(
|
'plugin_information', array(
|
||||||
'slug' => $plugin,
|
'slug' => $plugin,
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'short_description' => false,
|
'sections' => 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,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user