Opened 4 days ago
Last modified 4 days ago
#66229 assigned enhancement
Register and filter fields for DataViews/DataForm in the server
| Reported by: | oandregal | Owned by: | oandregal |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | General | Version: | trunk |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Related to https://core.trac.wordpress.org/ticket/65981
We want to introduce the ability to register and extend the fields used by DataViews/DataForm in the server for any given entity.
The whole initiative is tracked in Gutenberg at https://github.com/WordPress/gutenberg/issues/74865
Change History (3)
This ticket was mentioned in PR #13911 on WordPress/wordpress-develop by @oandregal.
4 days ago
#2
- Keywords has-patch has-unit-tests added
#3
@
4 days ago
Tested PR #13911 on WordPress Playground (core-pr=13911).
Environment:
- WordPress: 7.2-alpha-20261001.231912
- PHP: 7.4
- Playground (WASM) — https://playground.wordpress.net/?core-pr=13911
Testing performed:
- REST endpoint verification
- GET /wp/v2/fields → 400 rest_missing_callback_param (kind, name required) ✅
- GET /wp/v2/fields?kind=postType&name=page (unauthenticated) → 401 rest_cannot_read ✅
- GET /wp/v2/fields?kind=postType&name=page (authenticated via wp.apiFetch) → 200 with empty fields ✅
- Field registration via fields_api_init hook
Registered 2 custom fields on postType/page using WP_Fields_Registry::register():
- my_test_field (text)
- my_second_field (integer)
Confirmed signature: register( $origin, $kind, $name, $fields[], $script_module = null )
- REST response after registration GET /wp/v2/fields?kind=postType&name=page → { kind: 'postType', name: 'page', fields: Array(2), script_modules: Array(0) } Both fields returned correctly ✅
- Validation
- Calling register() with incorrect arguments (missing 'id' in field definition) produces proper _doing_it_wrong() notice ✅
- Duplicate fields are skipped as documented ✅
Result: PR works as described. The register() method correctly stores origin as
both 'origin' and 'registeredBy' properties on each field, and the REST
controller serves them per entity.
Note: During testing, I confirmed that the fields definition parameter must be
a list of arrays (each with an 'id' key), not a single field definition. The
docblock is clear about this, but it's worth noting for anyone writing their
first registration.
Props to @oandregal for the implementation.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: https://core.trac.wordpress.org/ticket/66229
See: https://github.com/WordPress/gutenberg/pull/83368
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 5.5
Used for: Implementation. Reviewed and edited by me.