mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Themes: Use api.wordpress.org/themes/info/1.2/ to query theme information.
See #43192. git-svn-id: https://develop.svn.wordpress.org/trunk@42632 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user