Ticket #38607: post-type-links.patch
| File post-type-links.patch, 2.4 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
197 197 $response = rest_ensure_response( $data ); 198 198 199 199 $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; 200 $ response->add_links(array(200 $links = array( 201 201 'collection' => array( 202 202 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), 203 203 ), … … 204 204 'https://api.w.org/items' => array( 205 205 'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ), 206 206 ), 207 ) );207 ); 208 208 209 $post_type_links = array(); 210 foreach ( $taxonomy->object_type as $type ) { 211 $post_type_object = get_post_type_object( $type ); 212 213 // Skip post types that are not public. 214 if ( empty( $post_type_object->show_in_rest ) ) { 215 continue; 216 } 217 218 $rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name; 219 $post_type_links[] = array( 220 'href' => rest_url( 'wp/v2/' . $rest_base ), 221 'post_type' => $type, 222 ); 223 } 224 225 if ( ! empty( $post_type_links ) ) { 226 $links['https://api.w.org/post_type'] = $post_type_links; 227 } 228 229 $response->add_links( $links ); 230 209 231 /** 210 232 * Filters a taxonomy returned from the REST API. 211 233 * -
tests/phpunit/tests/rest-api/rest-taxonomies-controller.php
170 170 $this->assertEquals( $tax_obj->hierarchical, $data['hierarchical'] ); 171 171 $this->assertEquals( rest_url( 'wp/v2/taxonomies' ), $links['collection'][0]['href'] ); 172 172 $this->assertArrayHasKey( 'https://api.w.org/items', $links ); 173 $this->assertArrayHasKey( 'https://api.w.org/post_type', $links ); 174 $this->assertEquals( rest_url( 'wp/v2/posts' ), $links['https://api.w.org/post_type'][0]['href'] ); 173 175 if ( 'edit' === $context ) { 174 176 $this->assertEquals( $tax_obj->cap, $data['capabilities'] ); 175 177 $this->assertEquals( $tax_obj->labels, $data['labels'] );