Skip to content

Add view config API and endpoint#11272

Closed
oandregal wants to merge 12 commits into
WordPress:trunkfrom
oandregal:try/entity-config
Closed

Add view config API and endpoint#11272
oandregal wants to merge 12 commits into
WordPress:trunkfrom
oandregal:try/entity-config

Conversation

@oandregal

@oandregal oandregal commented Mar 17, 2026

Copy link
Copy Markdown
Member

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

Why?

Part of WordPress/gutenberg#76544

How?

Backports the View Config REST API endpoint from Gutenberg to WordPress Core.

Testing Instructions

  1. Start a WordPress development environment.
  2. Log in as an admin user.
  3. Send a GET request to /wp-json/wp/v2/view-config?kind=postType&name=post — verify it returns generic defaults (table view, author/status fields).
  4. Send a GET request to /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).
  5. Send the same request as an unauthenticated user — verify it returns a rest_cannot_read error.

You may want to send a GET request from the console, after having logged in into wp-admin:

fetch('http://localhost:8889/wp-json/wp/v2/view-config?kind=postType&name=post', {
    headers:{
        'X-WP-Nonce': wpApiSettings.nonce
    }
})
  .then(res => res.json())
  .then(console.log)

Use of AI Tools

This backport was prepared with the assistance of Claude Code (Claude Opus 4.8).

@oandregal oandregal self-assigned this Mar 17, 2026
@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.

@github-actions

github-actions Bot commented Jun 22, 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, ntsekouras.

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

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.

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 on init.
  • Added WP_REST_View_Config_Controller exposing GET /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.

Comment thread src/wp-includes/view-config.php
Comment thread src/wp-includes/view-config.php
Comment thread tests/phpunit/tests/view-config.php
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php Outdated
Comment thread src/wp-includes/view-config.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php Outdated
Comment thread src/wp-includes/default-filters.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php Outdated

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

LGTM, thanks!

oandregal and others added 3 commits June 23, 2026 12:44
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>
@oandregal oandregal force-pushed the try/entity-config branch from 04d8b5a to c1f8ba6 Compare June 23, 2026 10:44
@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: 62547
GitHub commit: 36cc6e9

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

@github-actions github-actions Bot closed this Jun 23, 2026
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