Opened 5 hours ago
Last modified 5 hours ago
#66362 new enhancement
REST API: Add item counts to the page view list in the view config endpoint
| Reported by: | im3dabasia1 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.3 |
| Component: | REST API | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Adds a count to each status view in the page view list of the view config endpoint, so the Pages screen in the site editor can show item counts on its status tabs, like the classic Pages screen does.
Views narrowed by more than their status get no count.
Gutenberg PR: https://github.com/WordPress/gutenberg/pull/82247
Core PR: https://github.com/WordPress/wordpress-develop/pull/14070
Change History (2)
This ticket was mentioned in PR #14070 on WordPress/wordpress-develop by @im3dabasia1.
5 hours ago
#2
- Keywords has-unit-tests added
Backports the PHP changes from https://github.com/WordPress/gutenberg/pull/82247. The JS ships through the package sync.
Trac ticket: https://core.trac.wordpress.org/ticket/66362
What
GET /wp/v2/view-config?kind=postType&name=page now adds a count to each view list entry whose total a status count can answer:
- A view without filters counts every status but trash.
- A view whose only filter is on
status(is/isAny) counts those statuses. - A view narrowed by anything else (another filter, or a search) gets no count, so it never shows a total that doesn't describe it.
The counts are added in WP_REST_View_Config_Controller::get_items() after every get_entity_view_config_* filter has run, so they describe the final view list, including views added or changed by plugins. One wp_count_posts( 'page', 'readable' ) call supplies every count, which keeps private pages the current user can't read out of the totals. The item schema now includes view_list[].count.
Why
Users can't tell how many drafts or pending items exist without opening each tab, while classic wp-admin shows these counts. This adds the server side of the status tab counts in the site editor's post list.
Files
src/wp-includes/view-config.php: adds_wp_add_counts_to_view_list()and_wp_get_view_list_entry_statuses().src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php: adds the counts inget_items()andcountto the item schema.tests/phpunit/tests/rest-api/rest-view-config-controller.php: three count tests, andtest_get_items_matches_underlying_confignow expects the counts.
Testing Instructions
- Have a few pages in different statuses (for example 2 drafts, 1 published, 1 in the trash).
- Open the site editor and run this in the browser console:
await wp.apiFetch( { path: '/wp/v2/view-config?kind=postType&name=page' } ) - Confirm each entry in
view_listhas acountmatching its status, and thatallcounts every page except trashed ones. - Run the tests:
npm run test:php -- --group view-config
Use of AI Tools
Ported with Claude Code (Claude Opus 5.5). I reviewed every change and ran the tests locally.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Test Report
Description
This report validates that the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/14070 (head b0167ed6ce)
Environment
Actual Results
phpunit --group view-config: OK (98 tests, 238 assertions), single site and multisite. All 9 new count tests pass.pageview list counts withwp_count_posts( 'page', 'readable' ):edit_pagesbut noread_private_pages: all 6, private 1 (only their own). Other users' private pages are not counted.edit_pages, so counts are not exposed to Subscribers or logged-out users.Notes
@sincetags (5 of them, in the controller and inview-config.php) say7.2.0, but this ticket is milestoned for 7.3. They should probably be7.3.0.Trac ticket: https://core.trac.wordpress.org/ticket/66362should fix it.Supplemental Artifacts
None.