Commit e4dac0ebc4 for wordpress.org

commit e4dac0ebc4209efb1574e0dca73066977d6f3c7e
Author: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Date:   Fri Nov 20 14:54:10 2026 +0000

    Editor: Validate the entity in the entity fields reads and REST route.

    The entity fields API lacked two input checks that the entity actions API has:
    - `WP_Entity_Fields_Registry::get_registered()` and `::get_registered_field_modules()` did not validate the entity kind and name, so an array caused a fatal `TypeError`. They now return an empty list with a `_doing_it_wrong()` notice.
    - The `kind` and `name` arguments of `/wp/v2/entity-fields` had no `minLength`, so empty values returned a 200 response. They now return a 400 error, like `/wp/v2/entity-actions`.
    The entity actions endpoint no longer skips registering its route when a post type or taxonomy uses `entity-actions` as its REST base. No other core endpoint with a fixed base, such as `/wp/v2/settings` or `/wp/v2/search`, has this check.

    Developed in https://github.com/WordPress/wordpress-develop/pull/16067.

    Follow-up to [64517], [64528].

    Props mukesh27, oandregal, jorgefilipecosta.
    Fixes #66229.
    Built from https://develop.svn.wordpress.org/trunk@65725


    git-svn-id: http://core.svn.wordpress.org/trunk@64755 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/class-wp-entity-fields-registry.php b/wp-includes/class-wp-entity-fields-registry.php
index 864828ca1c..1cc9b629e0 100644
--- a/wp-includes/class-wp-entity-fields-registry.php
+++ b/wp-includes/class-wp-entity-fields-registry.php
@@ -445,8 +445,12 @@ class WP_Entity_Fields_Registry {
 	 * @param string $kind The entity kind (e.g. `postType`).
 	 * @param string $name The entity name (e.g. `page`).
 	 * @return array[] The list of field definitions, in registration order.
+	 *                 Empty when the entity is invalid.
 	 */
 	public function get_registered( $kind, $name ) {
+		if ( ! $this->validate_entity( __METHOD__, $kind, $name ) ) {
+			return array();
+		}
 		$this->initialize();
 		return array_values( $this->fields[ $kind ][ $name ] ?? array() );
 	}
@@ -478,7 +482,8 @@ class WP_Entity_Fields_Registry {
 	 * @param string $kind The entity kind (e.g. `postType`).
 	 * @param string $name The entity name (e.g. `page`).
 	 * @return array[] {
-	 *     The script modules, in registration order.
+	 *     The script modules, in registration order. Empty when the entity
+	 *     is invalid.
 	 *
 	 *     @type array ...$0 {
 	 *         @type string   $id     The id of the script module.
@@ -488,6 +493,9 @@ class WP_Entity_Fields_Registry {
 	 * }
 	 */
 	public function get_registered_field_modules( $kind, $name ) {
+		if ( ! $this->validate_entity( __METHOD__, $kind, $name ) ) {
+			return array();
+		}
 		$this->initialize();
 		$modules = array();
 		foreach ( $this->field_modules[ $kind ][ $name ] ?? array() as $module => $field_ids ) {
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-entity-actions-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-entity-actions-controller.php
index bf9ebcf895..121421fc00 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-entity-actions-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-entity-actions-controller.php
@@ -39,10 +39,6 @@ class WP_REST_Entity_Actions_Controller extends WP_REST_Controller {
 	 * @since 7.2.0
 	 */
 	public function register_routes() {
-		if ( $this->is_route_of_entity_items() ) {
-			return;
-		}
-
 		register_rest_route(
 			$this->namespace,
 			'/' . $this->rest_base,
@@ -71,44 +67,6 @@ class WP_REST_Entity_Actions_Controller extends WP_REST_Controller {
 		);
 	}

-	/**
-	 * Checks whether a post type or taxonomy has its items on the route of
-	 * the controller, reporting it with _doing_it_wrong().
-	 *
-	 * The route is then left to the post type or taxonomy: registering it
-	 * as well would not serve the actions, as the route of the items comes
-	 * first, and would replace the schema of that route.
-	 *
-	 * @since 7.2.0
-	 *
-	 * @return bool Whether a post type or taxonomy has its items on the route.
-	 */
-	protected function is_route_of_entity_items() {
-		$objects = array_merge(
-			array_values( get_post_types( array( 'show_in_rest' => true ), 'objects' ) ),
-			array_values( get_taxonomies( array( 'show_in_rest' => true ), 'objects' ) )
-		);
-		foreach ( $objects as $object ) {
-			$namespace = $object->rest_namespace ? $object->rest_namespace : 'wp/v2';
-			$base      = $object->rest_base ? $object->rest_base : $object->name;
-			if ( $this->namespace === $namespace && $this->rest_base === $base ) {
-				_doing_it_wrong(
-					__METHOD__,
-					sprintf(
-						/* translators: 1: REST route, e.g. /wp/v2/entity-actions. 2: Post type or taxonomy name. */
-						__( 'The %1$s route serves the items of the "%2$s" post type or taxonomy, so the actions of entities are not available.' ),
-						'/' . $this->namespace . '/' . $this->rest_base,
-						$object->name
-					),
-					'7.2.0'
-				);
-				return true;
-			}
-		}
-
-		return false;
-	}
-
 	/**
 	 * Checks if a given request has access to read the actions of an entity.
 	 *
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-entity-fields-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-entity-fields-controller.php
index c9738f2a7b..cbc16bee7c 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-entity-fields-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-entity-fields-controller.php
@@ -51,11 +51,13 @@ class WP_REST_Entity_Fields_Controller extends WP_REST_Controller {
 						'kind' => array(
 							'description' => __( 'Entity kind.' ),
 							'type'        => 'string',
+							'minLength'   => 1,
 							'required'    => true,
 						),
 						'name' => array(
 							'description' => __( 'Entity name.' ),
 							'type'        => 'string',
+							'minLength'   => 1,
 							'required'    => true,
 						),
 					),
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 894b513c11..e730e3e7de 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-RC2-65724';
+$wp_version = '7.2-RC2-65725';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.