REST API: Add array argument to getItems for Pattern Directory endopoint

Since http://api.wordpress.org/patterns API supports array parameters, there is no need to implode slug values inside the _register_remote_theme_patterns function.
Both WP_REST_Pattern_Directory_Controller and _register_remote_theme_patternsmust be updated to support array request arguments.

Props antonvlasenko.
Fixes #55574.
Follow-up #55505, [53152].




git-svn-id: https://develop.svn.wordpress.org/trunk@53218 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Greg Ziółkowski 2022-04-19 14:56:40 +00:00
parent 5ae266fdc4
commit 32f1bdeec6
2 changed files with 4 additions and 8 deletions

View File

@ -155,7 +155,7 @@ function _register_remote_theme_patterns() {
}
$request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
$request['slug'] = implode( ',', $pattern_settings );
$request['slug'] = $pattern_settings;
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return;

View File

@ -25,8 +25,8 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller {
* @since 5.8.0
*/
public function __construct() {
$this->namespace = 'wp/v2';
$this->rest_base = 'pattern-directory';
$this->namespace = 'wp/v2';
$this->rest_base = 'pattern-directory';
}
/**
@ -137,11 +137,7 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller {
$raw_patterns = get_site_transient( $transient_key );
if ( ! $raw_patterns ) {
$api_url = add_query_arg(
array_map( 'rawurlencode', $query_args ),
'http://api.wordpress.org/patterns/1.0/'
);
$api_url = 'http://api.wordpress.org/patterns/1.0/?' . build_query( $query_args );
if ( wp_http_supports( array( 'ssl' ) ) ) {
$api_url = set_url_scheme( $api_url, 'https' );
}