Skip to content

Add entity fields: API, registry, endpoint - #13911

Closed
oandregal wants to merge 5 commits into
WordPress:trunkfrom
oandregal:add/fields-api-endpoint
Closed

oandregal wants to merge 5 commits into
WordPress:trunkfrom
oandregal:add/fields-api-endpoint

Conversation

@oandregal

@oandregal oandregal commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/66229
See: WordPress/gutenberg#74865

What

This PR lands the PHP parts of the entity fields API.

Prerequisites to merge

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 5.5
Used for: Implementation. Reviewed and edited by me.

@oandregal oandregal changed the title Add/fields api endpoint Register and filter fields for DataViews/DataForm Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 19, 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. You can also manually ask me to refresh this list by adding the props-bot label.

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

Props oandregal, jorgefilipecosta.

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

@oandregal oandregal changed the title Register and filter fields for DataViews/DataForm Add entity fields API Oct 19, 2026
@oandregal oandregal changed the title Add entity fields API Add entity fields: API, registry, endpoint Oct 19, 2026
Comment thread src/wp-includes/view-config.php
Comment thread src/wp-includes/rest-api.php
@oandregal
oandregal force-pushed the add/fields-api-endpoint branch from 4db7bb1 to 5dbb447 Compare October 19, 2026 14:36
@oandregal

Copy link
Copy Markdown
Member Author

#14495 was merged and this rebased onto trunk.

}
// The id comes first, like in the fields registered directly.
$field = array_merge( array( 'id' => basename( dirname( $file ) ) ), $field );
$fields[ $field['id'] ] = $field;

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.

Should we validate that $field['id'] is a string? A field.php returning an array id causes a fatal error here.

@oandregal oandregal Oct 19, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, that's good thinking, thanks. Related to your comment, I found an edge case and pushed a fix (and tests) at 91fea0c

Comment thread src/wp-includes/class-wp-entity-fields-registry.php Outdated
@oandregal
oandregal force-pushed the add/fields-api-endpoint branch from 5dbb447 to 0a5dedd Compare October 19, 2026 15:09

@jorgefilipecosta jorgefilipecosta 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.

Left some comments but they are not blockers.

oandregal and others added 3 commits October 19, 2026 19:03
Adds a registry of the fields of an entity, identified by its kind and name, along with `wp_register_entity_fields()`, `wp_update_entity_fields()`, `wp_unregister_entity_fields()`, and `wp_register_entity_field_collection()`, which only run on the new `wp_entity_fields_api_init` action, and the functions that read the registry. The registry is filled lazily: the action fires the first time the fields are read, once `init` has completed.

A field definition is the serializable subset of the DataViews Field API. Its JavaScript parts ship in a script module registered along with the fields. The script modules of the fields are added as dynamic `module_dependencies` of the `wp-editor` script on `admin_footer`, so they reach the import map of the pages that load the editor.

The `WP_REST_Entity_Fields_Controller` class is introduced too, as the registry validates the field types against its schema. Its route is registered separately.

Synced from WordPress/gutenberg#84078.
Synced from WordPress/gutenberg#84168.
Synced from WordPress/gutenberg#84691.

See #66229.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Registers the `/wp/v2/entity-fields` route, served by `WP_REST_Entity_Fields_Controller`. Given an entity kind and name, it returns the fields registered for the entity with the Entity Fields API, and the script modules providing their JavaScript parts, each with the ids of the fields it applies to.

Access mirrors the `/wp/v2/view-config` route: post types require their own `edit_posts` capability, taxonomies their `manage_terms` capability, and root entities `manage_options`. Post types and taxonomies that are not registered or not exposed in the REST API are not found.

Synced from WordPress/gutenberg#84078.
Synced from WordPress/gutenberg#84691.

See #66229.

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

The Site Editor reads the fields of the post types it lists from the `/wp/v2/entity-fields` route before it can render them. The fields of the edited post type, if any, and of the post types of the screen the Site Editor opens on, from its `p` query arg, are now added to the preloaded paths.

Synced from WordPress/gutenberg#84700.

See #66229.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
oandregal and others added 2 commits October 19, 2026 19:03
A `field.php` that returned a non-string `id`, such as an array, caused
a fatal error when the id was used as a key in get_collection_fields().
Other non-string ids were silently coerced, and a folder setting the id
of an earlier one silently replaced it.

Such fields are now reported with _doing_it_wrong() and skipped, along
with a `field.php` that does not return an array. The rest of the
collection is read, and register_collection() returns false when a
field was skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pass hook names, file names, keys, and method names as placeholders, wrapped in `<code>`, instead of keeping them inside the strings to translate, as core does elsewhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oandregal
oandregal force-pushed the add/fields-api-endpoint branch from 788e45c to ff8698d Compare October 19, 2026 17:04
@oandregal

Copy link
Copy Markdown
Member Author

@oandregal oandregal closed this Oct 19, 2026
@oandregal
oandregal deleted the add/fields-api-endpoint branch October 19, 2026 17:46
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.

3 participants