Skip to content

Editor: Track wp_entity_fields_api_init firing internally in WP_Entity_Fields_Registry - #16009

Closed
banghamid wants to merge 2 commits into
WordPress:trunkfrom
banghamid:trac-66703
Closed

banghamid wants to merge 2 commits into
WordPress:trunkfrom
banghamid:trac-66703

Conversation

@banghamid

@banghamid banghamid commented Nov 15, 2026 •

Copy link
Copy Markdown

Track wp_entity_fields_api_init execution via an internal $initializing flag in WP_Entity_Fields_Registry instead of relying on WordPress' doing_action( 'wp_entity_fields_api_init' ).

Previously, calling do_action( 'wp_entity_fields_api_init' ) again after the registry had already been initialized and read caused doing_entity_fields_api_init() to return true, allowing register(), update(), unregister(), and register_collection() to mutate the registry and violating its immutability guarantee. This aligns WP_Entity_Fields_Registry with WP_Entity_Actions_Registry, and adds a PHPUnit regression test.

Trac ticket: https://core.trac.wordpress.org/ticket/66703

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini 3.8 Flash, Gemini 4 Argon, Gemini 4 Hydrogen, Orchestrator (Argon)
Used for: Root cause analysis, patch implementation, and regression test drafting; all changes were reviewed and verified locally.

…y_Fields_Registry.

Refusing mutations once read keeps the registry immutable even when wp_entity_fields_api_init is fired again with do_action(), matching WP_Entity_Actions_Registry.

Fixes #66703.
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props banghamid, oandregal, ntsekouras, wildworks, mamaduka.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@banghamid

Copy link
Copy Markdown
Author

@propsbot refresh

…s docblock.

The guard now checks that the registry itself is firing
wp_entity_fields_api_init, not just that the action is firing. Update the
class docblock to match, and list register_collection() among the guarded
methods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@oandregal oandregal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a docblock update, but the change looks good to me.

@oandregal

Copy link
Copy Markdown
Member

As Gutenberg maintains these classes as well, I've ported these changes over there as well at WordPress/gutenberg#87387

@t-hamano

Copy link
Copy Markdown
Contributor

@oandregal @ntsekouras @jorgefilipecosta, do you have the bandwidth to finalize this PR and also merge WordPress/gutenberg#87387 so that the fix can be included in 7.2 RC4?

@ntsekouras ntsekouras left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@ntsekouras

Copy link
Copy Markdown
Contributor

Noting that this should be also committed to 7.2 branch.

@oandregal

Copy link
Copy Markdown
Member

do you have the bandwidth to finalize this PR and also merge WordPress/gutenberg#87387 so that the fix can be included in 7.2 RC4?

I'll likely be unable to do it today, but can do tomorrow morning if @ntsekouras or @jorgefilipecosta don't beat me to it. Though I understand we need two separate core committers (one from trunk other for the 7.2 branch).

@ntsekouras

Copy link
Copy Markdown
Contributor

I'll likely be unable to do it today, but can do tomorrow morning if @ntsekouras or @jorgefilipecosta don't beat me to it. Though I understand we need two separate core committers (one from trunk other for the 7.2 branch).

I guess that's fine to commit to 7.2 since this PR has already two approvals? --cc @Mamaduka

@Mamaduka

Copy link
Copy Markdown
Member

Yes, this should be good to commit.

@ntsekouras

Copy link
Copy Markdown
Contributor

I'll start with the commits.

wporg-sync pushed a commit that referenced this pull request Nov 25, 2026
…n 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 #16009.

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


git-svn-id: https://develop.svn.wordpress.org/trunk@65781 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65781
GitHub commit: 20f9614

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 25, 2026
…n 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 WordPress/wordpress-develop#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
wporg-sync pushed a commit that referenced this pull request Nov 25, 2026
…n 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 #16009.

Reviewed by oandregal.
Merges [65781] to the 7.2 branch.

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


git-svn-id: https://develop.svn.wordpress.org/branches/7.2@65782 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65782
GitHub commit: 7f11f05

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 25, 2026
…n 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 WordPress/wordpress-develop#16009.

Reviewed by oandregal.
Merges [65781] to the 7.2 branch.

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

Built from https://develop.svn.wordpress.org/branches/7.2@65782


git-svn-id: http://core.svn.wordpress.org/branches/7.2@64811 1a063a9b-81f0-0310-95a4-ce76da25c4cd
ntsekouras added a commit to WordPress/gutenberg that referenced this pull request Nov 25, 2026
…he registry (#87387)

* Entity Fields: Track wp_entity_fields_api_init firing internally in the registry

register(), update(), unregister(), and register_collection() checked
doing_action( 'wp_entity_fields_api_init' ), so any do_action() call of the
hook from outside the registry let them run: firing it again once the
registry had been read reopened it, after the REST controller and the
import map of the editor script were built from its fields.

The registry now sets an internal flag while it fires the action on the
first read, and the guard checks that flag instead. The plugin subclass
overrides initialize() and doing_entity_fields_api_init() so the fix
applies on WordPress versions whose registry predates it.

Port of WordPress/wordpress-develop#16009.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Add backport changelog entry for wordpress-develop#16009

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
peterwilsoncc pushed a commit to peterwilsoncc/gutenberg-build that referenced this pull request Nov 25, 2026
…he registry (#87387)

* Entity Fields: Track wp_entity_fields_api_init firing internally in the registry

register(), update(), unregister(), and register_collection() checked
doing_action( 'wp_entity_fields_api_init' ), so any do_action() call of the
hook from outside the registry let them run: firing it again once the
registry had been read reopened it, after the REST controller and the
import map of the editor script were built from its fields.

The registry now sets an internal flag while it fires the action on the
first read, and the guard checks that flag instead. The plugin subclass
overrides initialize() and doing_entity_fields_api_init() so the fix
applies on WordPress versions whose registry predates it.

Port of WordPress/wordpress-develop#16009.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Add backport changelog entry for wordpress-develop#16009

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>

Source: WordPress/gutenberg@95d4da9
@oandregal

Copy link
Copy Markdown
Member

Thank you @ntsekouras for going ahead and taking care of this! 🙏 ❤️

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants