Themes: Use `api.wordpress.org/themes/info/1.2/` to query theme information.
See #43192. Built from https://develop.svn.wordpress.org/trunk@42632 git-svn-id: http://core.svn.wordpress.org/trunk@42461 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
7abfd84c75
commit
1e5629d1f1
|
@ -3218,7 +3218,7 @@ function wp_ajax_query_themes() {
|
|||
}
|
||||
|
||||
$theme->name = wp_kses( $theme->name, $themes_allowedtags );
|
||||
$theme->author = wp_kses( $theme->author, $themes_allowedtags );
|
||||
$theme->author = wp_kses( $theme->author['display_name'], $themes_allowedtags );
|
||||
$theme->version = wp_kses( $theme->version, $themes_allowedtags );
|
||||
$theme->description = wp_kses( $theme->description, $themes_allowedtags );
|
||||
$theme->stars = wp_star_rating(
|
||||
|
|
|
@ -421,19 +421,27 @@ function get_theme_feature_list( $api = true ) {
|
|||
* for more information on the make-up of possible return objects depending on the value of `$action`.
|
||||
*/
|
||||
function themes_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_themes' == $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 arguments used to query for installer pages from the WordPress.org Themes API.
|
||||
*
|
||||
|
@ -465,22 +473,24 @@ function themes_api( $action, $args = array() ) {
|
|||
$res = apply_filters( 'themes_api', false, $action, $args );
|
||||
|
||||
if ( ! $res ) {
|
||||
// include an unmodified $wp_version
|
||||
include( ABSPATH . WPINC . '/version.php' );
|
||||
$url = 'http://api.wordpress.org/themes/info/1.2/';
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'action' => $action,
|
||||
'request' => $args,
|
||||
),
|
||||
$url
|
||||
);
|
||||
|
||||
$url = $http_url = 'http://api.wordpress.org/themes/info/1.0/';
|
||||
$http_url = $url;
|
||||
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
|
||||
$url = set_url_scheme( $url, 'https' );
|
||||
}
|
||||
|
||||
$http_args = array(
|
||||
'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 ( ! wp_doing_ajax() ) {
|
||||
|
@ -493,7 +503,7 @@ function themes_api( $action, $args = array() ) {
|
|||
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 ) ) {
|
||||
|
@ -507,8 +517,11 @@ function themes_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(
|
||||
'themes_api_failed',
|
||||
sprintf(
|
||||
|
@ -519,6 +532,21 @@ function themes_api( $action, $args = array() ) {
|
|||
wp_remote_retrieve_body( $request )
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $res->error ) ) {
|
||||
$res = new WP_Error( 'themes_api_failed', $res->error );
|
||||
}
|
||||
}
|
||||
|
||||
// Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects.
|
||||
if ( 'query_themes' == $action ) {
|
||||
foreach ( $res->themes as $i => $theme ) {
|
||||
$res->themes[ $i ] = (object) $theme;
|
||||
}
|
||||
}
|
||||
// Back-compat for info/1.2 API, downgrade the feature_list result back to an array.
|
||||
if ( 'feature_list' == $action ) {
|
||||
$res = (array) $res;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -334,18 +334,7 @@ themes.Collection = Backbone.Collection.extend({
|
|||
data: {
|
||||
// Request data
|
||||
request: _.extend({
|
||||
per_page: 100,
|
||||
fields: {
|
||||
description: true,
|
||||
tested: true,
|
||||
requires: true,
|
||||
rating: true,
|
||||
downloaded: true,
|
||||
downloadLink: true,
|
||||
last_updated: true,
|
||||
homepage: true,
|
||||
num_ratings: true
|
||||
}
|
||||
per_page: 100
|
||||
}, request)
|
||||
},
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -5619,19 +5619,6 @@ final class WP_Customize_Manager {
|
|||
// Arguments for all queries.
|
||||
$wporg_args = array(
|
||||
'per_page' => 100,
|
||||
'fields' => array(
|
||||
'screenshot_url' => true,
|
||||
'description' => true,
|
||||
'rating' => true,
|
||||
'downloaded' => true,
|
||||
'downloadlink' => true,
|
||||
'last_updated' => true,
|
||||
'homepage' => true,
|
||||
'num_ratings' => true,
|
||||
'tags' => true,
|
||||
'parent' => true,
|
||||
// 'extended_author' => true, @todo: WordPress.org throws a 500 server error when this is here.
|
||||
),
|
||||
);
|
||||
|
||||
$args = array_merge( $wporg_args, $args );
|
||||
|
@ -5674,10 +5661,8 @@ final class WP_Customize_Manager {
|
|||
);
|
||||
|
||||
$theme->name = wp_kses( $theme->name, $themes_allowedtags );
|
||||
$theme->author = wp_kses( $theme->author, $themes_allowedtags );
|
||||
$theme->version = wp_kses( $theme->version, $themes_allowedtags );
|
||||
$theme->description = wp_kses( $theme->description, $themes_allowedtags );
|
||||
$theme->tags = implode( ', ', $theme->tags );
|
||||
$theme->stars = wp_star_rating(
|
||||
array(
|
||||
'rating' => $theme->rating,
|
||||
|
@ -5702,8 +5687,8 @@ final class WP_Customize_Manager {
|
|||
// Map available theme properties to installed theme properties.
|
||||
$theme->id = $theme->slug;
|
||||
$theme->screenshot = array( $theme->screenshot_url );
|
||||
$theme->authorAndUri = $theme->author;
|
||||
// The .org API can return the full parent theme details if passed the 'parent' arg, or if passed the 'template' option it'll return that in the event it's a child theme.
|
||||
$theme->authorAndUri = wp_kses( $theme->author['display_name'], $themes_allowedtags );
|
||||
|
||||
if ( isset( $theme->parent ) ) {
|
||||
$theme->parent = $theme->parent['slug'];
|
||||
} else {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.0-alpha-42631';
|
||||
$wp_version = '5.0-alpha-42632';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue