Skip to content

Commit 26266c2

Browse files
oandregalclaude
andcommitted
REST API: Remove the route collision check from the entity fields endpoint.
The other core endpoints with a fixed base do not check whether a post type or taxonomy already serves its items on their route, so the entity fields endpoint no longer does either. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 21a9795 commit 26266c2

2 files changed

Lines changed: 0 additions & 72 deletions

File tree

‎src/wp-includes/rest-api/endpoints/class-wp-rest-entity-fields-controller.php‎

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ public function __construct() {
3939
* @since 7.2.0
4040
*/
4141
public function register_routes() {
42-
if ( $this->is_route_of_entity_items() ) {
43-
return;
44-
}
45-
4642
register_rest_route(
4743
$this->namespace,
4844
'/' . $this->rest_base,
@@ -71,44 +67,6 @@ public function register_routes() {
7167
);
7268
}
7369

74-
/**
75-
* Checks whether a post type or taxonomy has its items on the route of
76-
* the controller, reporting it with _doing_it_wrong().
77-
*
78-
* The route is then left to the post type or taxonomy: registering it
79-
* as well would not serve the fields, as the route of the items comes
80-
* first, and would replace the schema of that route.
81-
*
82-
* @since 7.2.0
83-
*
84-
* @return bool Whether a post type or taxonomy has its items on the route.
85-
*/
86-
protected function is_route_of_entity_items() {
87-
$objects = array_merge(
88-
array_values( get_post_types( array( 'show_in_rest' => true ), 'objects' ) ),
89-
array_values( get_taxonomies( array( 'show_in_rest' => true ), 'objects' ) )
90-
);
91-
foreach ( $objects as $object ) {
92-
$namespace = $object->rest_namespace ? $object->rest_namespace : 'wp/v2';
93-
$base = $object->rest_base ? $object->rest_base : $object->name;
94-
if ( $this->namespace === $namespace && $this->rest_base === $base ) {
95-
_doing_it_wrong(
96-
__METHOD__,
97-
sprintf(
98-
/* translators: 1: REST route, e.g. /wp/v2/entity-fields. 2: Post type or taxonomy name. */
99-
__( 'The %1$s route serves the items of the "%2$s" post type or taxonomy, so the fields of entities are not available.' ),
100-
'/' . $this->namespace . '/' . $this->rest_base,
101-
$object->name
102-
),
103-
'7.2.0'
104-
);
105-
return true;
106-
}
107-
}
108-
109-
return false;
110-
}
111-
11270
/**
11371
* Checks if a given request has access to read the fields of an entity.
11472
*

‎tests/phpunit/tests/rest-api/rest-entity-fields-controller.php‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -182,36 +182,6 @@ public function test_register_routes() {
182182
$this->assertInstanceOf( 'WP_REST_Entity_Fields_Controller', $routes[ self::ROUTE ][0]['callback'][0] );
183183
}
184184

185-
/**
186-
* A taxonomy whose items are on the route keeps it: the route of the
187-
* fields is not registered, and that is reported.
188-
*
189-
* @covers ::register_routes
190-
* @covers ::is_route_of_entity_items
191-
*
192-
* @ticket 66229
193-
*/
194-
public function test_the_route_of_a_taxonomy_with_the_same_base_is_kept() {
195-
global $wp_rest_server;
196-
$this->setExpectedIncorrectUsage( 'WP_REST_Entity_Fields_Controller::is_route_of_entity_items' );
197-
register_taxonomy( 'entity-fields', 'post', array( 'show_in_rest' => true ) );
198-
199-
try {
200-
$wp_rest_server = null;
201-
$handlers = rest_get_server()->get_routes()[ self::ROUTE ];
202-
$response = rest_get_server()->dispatch( new WP_REST_Request( 'GET', self::ROUTE ) );
203-
} finally {
204-
unregister_taxonomy( 'entity-fields' );
205-
$wp_rest_server = null;
206-
}
207-
208-
$this->assertCount( 2, $handlers, 'Only the route of the terms is registered.' );
209-
$this->assertInstanceOf( WP_REST_Terms_Controller::class, $handlers[0]['callback'][0] );
210-
$this->assertArrayHasKey( 'POST', $handlers[1]['methods'], 'Terms can still be created.' );
211-
$this->assertSame( 200, $response->get_status(), 'The terms are listed.' );
212-
$this->assertSame( array(), $response->get_data() );
213-
}
214-
215185
/**
216186
* Editors (with `edit_posts`) can read the fields.
217187
*

0 commit comments

Comments
 (0)