Add view config API and endpoint#11272
Conversation
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
5a041c8 to
e0a178e
Compare
02fc7b1 to
d88742c
Compare
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
Introduces a new core API for retrieving an entity’s DataViews/DataForm view configuration and exposes it via a new REST endpoint, including PHPUnit coverage for both the API and endpoint behavior.
Changes:
- Added
wp_get_entity_view_config( $kind, $name )and default per-post-type providers registered oninit. - Added
WP_REST_View_Config_ControllerexposingGET /wp/v2/view-config?kind=…&name=…with schema + permission handling and JSON object serialization for empty object-shaped values. - Added PHPUnit tests for the API and the REST controller.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/phpunit/tests/view-config.php | Adds unit tests for the new view-config API defaults and filter behavior. |
| tests/phpunit/tests/rest-api/rest-view-config-controller.php | Adds REST API tests for routing, permissions, required params, schema shape, and object serialization. |
| src/wp-settings.php | Loads the new view-config API file and REST controller class during bootstrap. |
| src/wp-includes/view-config.php | Implements the new API and core default providers for several post types. |
| src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php | Adds REST controller exposing the view-config via wp/v2/view-config with schema. |
| src/wp-includes/rest-api.php | Registers the new controller’s routes in initial REST route setup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Introduces a server-side, filterable API for the default DataViews view
configuration of an entity, plus a REST endpoint that exposes it.
- `wp_get_entity_view_config( $kind, $name )` (new src/wp-includes/view-config.php)
builds the shared defaults (default view, layouts, view list, form) and
runs them through a dynamic `get_entity_view_config_{$kind}_{$name}` filter
so core and plugins can provide per-entity configuration.
- Core registers default providers for the `page`, `post`, `wp_block`,
`wp_template_part`, and `wp_template` post types as filter callbacks on
`init` (`_wp_get_entity_view_config_post_type_*`).
- `WP_REST_View_Config_Controller` exposes the config at
`GET /wp/v2/view-config?kind=…&name=…`, delegating to the API and handling
REST concerns (schema, `edit_posts` permission, empty-object serialization).
- Adds PHPUnit coverage for both the API and the controller.
Backports the following Gutenberg pull requests:
* WordPress/gutenberg#76573
* WordPress/gutenberg#76734
* WordPress/gutenberg#76622
* WordPress/gutenberg#76823
* WordPress/gutenberg#76953
* WordPress/gutenberg#76903
* WordPress/gutenberg#77290
* WordPress/gutenberg#78977
* WordPress/gutenberg#79195
* WordPress/gutenberg#76934
* WordPress/gutenberg#79347
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Porting the code and tests from Gutenberg and adapting them to
core conventions; all changes reviewed and tested by me.
The View Config controller registers `/wp/v2/view-config`, so include it in the expected routes for WP_Test_REST_Schema_Initialization::test_expected_routes_in_schema. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…enberg, if necessary
04d8b5a to
c1f8ba6
Compare
Trac ticket: https://core.trac.wordpress.org/ticket/65516
What?
Introduces a server-side, filterable API for the DataViews/DataForm configuration of an entity, plus a REST endpoint that exposes it.
wp_get_entity_view_config( $kind, $name )(new src/wp-includes/view-config.php) builds the shared defaults (default view, layouts, view list, form) and runs them through a dynamicget_entity_view_config_{$kind}_{$name}filter so core and plugins can provide per-entity configuration.page,post,wp_block,wp_template_part, andwp_templatepost types as filter callbacks oninit(_wp_get_entity_view_config_post_type_*).WP_REST_View_Config_Controllerexposes the config atGET /wp/v2/view-config?kind=…&name=…, delegating to the API and handling REST concerns (schema,edit_postspermission, empty-object serialization).Why?
Part of WordPress/gutenberg#76544
How?
Backports the View Config REST API endpoint from Gutenberg to WordPress Core.
excerptfield gutenberg#76903Testing Instructions
/wp-json/wp/v2/view-config?kind=postType&name=post— verify it returns generic defaults (table view, author/status fields)./wp-json/wp/v2/view-config?kind=postType&name=page— verify it returns page-specific config (list view, status sub-views like Published, Drafts, Trash).You may want to send a GET request from the console, after having logged in into wp-admin:
Use of AI Tools
This backport was prepared with the assistance of Claude Code (Claude Opus 4.8).