Skip to content
Permalink
Browse files

REST API: Always return post types list in taxonomies endpoint respon…

…se as an array.

Prevents a non-sequential post type array such as [ 0 => 'post', 2 => 'page' ] from being improperly converted to an object in the taxonomy endpoint's response JSON.

Props TimothyBlynJacobs, birgire, spectacula.
Fixes #42209.


git-svn-id: https://develop.svn.wordpress.org/trunk@45813 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
kadamwhite committed Aug 15, 2019
1 parent 8f10077 commit d65b89c5e4d76850f3beda4d779e1e922a3041c3
@@ -210,7 +210,7 @@ public function prepare_item_for_response( $taxonomy, $request ) {
}
if ( in_array( 'types', $fields, true ) ) {
$data['types'] = $taxonomy->object_type;
$data['types'] = array_values( $taxonomy->object_type );
}
if ( in_array( 'show_cloud', $fields, true ) ) {
@@ -195,6 +195,21 @@ public function test_prepare_item_limit_fields() {
);
}
public function test_object_types_is_an_array_if_object_type_is_unregistered() {
register_taxonomy_for_object_type( 'category', 'page' );
register_taxonomy_for_object_type( 'category', 'attachment' );
unregister_taxonomy_for_object_type( 'category', 'page' );
$request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/category' );
$response = rest_get_server()->dispatch( $request );
$types = $response->get_data()['types'];
$this->assertArrayHasKey( 0, $types );
$this->assertEquals( 'post', $types[0] );
$this->assertArrayHasKey( 1, $types );
$this->assertEquals( 'attachment', $types[1] );
}
public function test_get_item_schema() {
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/taxonomies' );
$response = rest_get_server()->dispatch( $request );

0 comments on commit d65b89c

Please sign in to comment.
You can’t perform that action at this time.