Commit 70752057c1 for wordpress.org

commit 70752057c16f69fd7c1fd57e79cf7b3230e709a7
Author: ntsekouras <ntsekouras@git.wordpress.org>
Date:   Wed Nov 25 15:43:50 2026 +0000

    Editor: Keep the entity fields registry immutable when its init action fires again.

    `WP_Entity_Fields_Registry` checked `doing_action( 'wp_entity_fields_api_init' )`
    to allow `register()`, `update()`, `unregister()`, and `register_collection()`.
    So firing the action again with `do_action()` after the registry had been read
    reopened it to changes. The registry now records when it fires the action
    itself, as `WP_Entity_Actions_Registry` already does.

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

    Props banghamid, oandregal, abhishekfdd, wildworks, mamaduka, ntsekouras.
    Fixes #66703.

    Built from https://develop.svn.wordpress.org/trunk@65781


    git-svn-id: http://core.svn.wordpress.org/trunk@64810 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 1cc9b629e0..58d6508a12 100644
--- a/wp-includes/class-wp-entity-fields-registry.php
+++ b/wp-includes/class-wp-entity-fields-registry.php
@@ -21,9 +21,11 @@
  * format.
  *
  * Fields are registered on the `wp_entity_fields_api_init` action, and only
- * there, with wp_register_entity_fields(), wp_update_entity_fields(), and
- * wp_unregister_entity_fields(): register(), update(), and unregister() refuse
- * to run while the action is not firing.
+ * there, with wp_register_entity_fields(), wp_update_entity_fields(),
+ * wp_unregister_entity_fields(), and wp_register_entity_field_collection():
+ * register(), update(), unregister(), and register_collection() refuse to run
+ * unless the registry itself is firing the action, on the first read of its
+ * fields. Firing the action by other means does not allow them to run.
  *
  * The registry is filled lazily: the first time its fields are read, it
  * fires the `wp_entity_fields_api_init` action, on which the default fields of every
@@ -70,6 +72,15 @@ class WP_Entity_Fields_Registry {
 	 */
 	protected $initialized = false;

+	/**
+	 * Whether the registry is firing the `wp_entity_fields_api_init` action, the
+	 * only time register(), update(), unregister(), and register_collection() run.
+	 *
+	 * @since 7.2.0
+	 * @var bool
+	 */
+	protected $initializing = false;
+
 	/**
 	 * The singleton instance.
 	 *
@@ -583,32 +594,39 @@ class WP_Entity_Fields_Registry {
 		// the fields it updates does not fire the action again.
 		$this->initialized = true;

-		/**
-		 * Fires the first time the registered fields are read, after `init`.
-		 *
-		 * Register or adjust fields here, with wp_register_entity_fields(),
-		 * wp_update_entity_fields(), and wp_unregister_entity_fields(): it is the only
-		 * time they run.
-		 *
-		 * The first read happens wherever the fields are needed: while
-		 * handling a REST request as well as on `admin_footer` of the pages
-		 * that load the editor script. A callback should register fields and
-		 * nothing else; script modules, styles, and their enqueue hooks
-		 * belong on `init`.
-		 *
-		 * @since 7.2.0
-		 */
-		do_action( 'wp_entity_fields_api_init' );
+		$this->initializing = true;
+		try {
+			/**
+			 * Fires the first time the registered fields are read, after `init`.
+			 *
+			 * Register or adjust fields here, with wp_register_entity_fields(),
+			 * wp_update_entity_fields(), and wp_unregister_entity_fields(): it is the only
+			 * time they run.
+			 *
+			 * The first read happens wherever the fields are needed: while
+			 * handling a REST request as well as on `admin_footer` of the pages
+			 * that load the editor script. A callback should register fields and
+			 * nothing else; script modules, styles, and their enqueue hooks
+			 * belong on `init`.
+			 *
+			 * @since 7.2.0
+			 */
+			do_action( 'wp_entity_fields_api_init' );
+		} finally {
+			$this->initializing = false;
+		}
 	}

 	/**
-	 * Checks that the `wp_entity_fields_api_init` action is firing, as register(),
-	 * update(), and unregister() require.
+	 * Checks that the registry is firing the `wp_entity_fields_api_init` action,
+	 * as register(), update(), unregister(), and register_collection() require.
 	 *
 	 * Outside the action a registration would either come before the
 	 * defaults, which could then not be registered, or after the fields have been read
 	 * and the import map of the editor script built from them. Refusing
-	 * keeps the registry immutable once read.
+	 * keeps the registry immutable once read, even when the action is fired
+	 * again with do_action(), which is why the registry tracks its own firing
+	 * rather than check doing_action().
 	 *
 	 * @since 7.2.0
 	 *
@@ -616,7 +634,7 @@ class WP_Entity_Fields_Registry {
 	 * @return bool Whether the action is firing.
 	 */
 	protected function doing_entity_fields_api_init( $method ) {
-		if ( doing_action( 'wp_entity_fields_api_init' ) ) {
+		if ( $this->initializing ) {
 			return true;
 		}

diff --git a/wp-includes/version.php b/wp-includes/version.php
index 6e583e88bb..8c43ba3d1b 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.3-alpha-65780';
+$wp_version = '7.3-alpha-65781';

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