diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index 25b7fa2d8c..ea628684b9 100644
|
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2243 | 2243 | $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); |
2244 | 2244 | foreach ( $taxonomies as $taxonomy ) { |
2245 | 2245 | $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; |
| 2246 | |
| 2247 | if ( array_key_exists( $base, $schema['properties'] ) ) { |
| 2248 | _doing_it_wrong( __METHOD__, sprintf( __( "Property '%s' is already set on the schema." ), $base ), '5.4.0' ); |
| 2249 | } |
| 2250 | |
2246 | 2251 | $schema['properties'][ $base ] = array( |
2247 | 2252 | /* translators: %s: Taxonomy name. */ |
2248 | 2253 | 'description' => sprintf( __( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ), |
diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
index 2aca849347..869dbf6c49 100644
|
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
3918 | 3918 | $this->assertArrayHasKey( 'categories', $properties ); |
3919 | 3919 | } |
3920 | 3920 | |
| 3921 | /** |
| 3922 | * @ticket 48401 |
| 3923 | */ |
| 3924 | public function test_get_item_schema_issues_doing_it_wrong_when_taxonomy_name_is_already_set_in_properties() { |
| 3925 | $this->setExpectedIncorrectUsage( 'WP_REST_Posts_Controller::get_item_schema' ); |
| 3926 | |
| 3927 | // Register a taxonomy with 'status' as name. |
| 3928 | register_taxonomy( 'status', 'post', array( 'show_in_rest' => true ) ); |
| 3929 | |
| 3930 | // Re-initialize the controller |
| 3931 | $controller = new WP_REST_Posts_Controller( 'post' ); |
| 3932 | $controller->register_routes(); |
| 3933 | } |
| 3934 | |
3921 | 3935 | /** |
3922 | 3936 | * @ticket 39805 |
3923 | 3937 | */ |