Opened 5 weeks ago
Last modified 2 weeks ago
#66260 new enhancement
Comments: Hide zero-count status filters on the Comments list table
| Reported by: | abditsori | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.3 |
| Component: | Comments | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests 2nd-opinion |
| Cc: | Focuses: | administration |
Description
The Posts list table (WP_Posts_List_Table::get_views()) hides any status
filter link — other than "All" — whose post count is zero:
if ( ! in_array( $status_name, $avail_post_stati, true ) || empty( $num_posts->$status_name ) ) {
continue;
}
WP_Comments_List_Table::get_views() has no equivalent check. As a result,
"Pending", "Approved", "Spam", "Trash", and "Mine" are always rendered as
filter links above the Comments list table, even when their count is (0).
On a typical site with few or no pending/spam/trashed comments, this clutters
the screen with filter links that lead to an empty list, rather than only
showing filters that are actually useful.
Steps to reproduce:
- Go to a site where every comment is approved (no pending, spam, or trashed comments).
- Go to Comments in wp-admin.
- Observe the filter row above the list: "All | Mine | Pending (0) | Approved (12) | Spam (0) | Trash (0)".
Expected behavior: filters with a zero count, other than "All", should not
be shown — consistent with how the Posts list table already behaves for
post statuses.
Attachments (2)
Change History (11)
This ticket was mentioned in PR #14056 on WordPress/wordpress-develop by @abditsori.
5 weeks ago
#1
- Keywords has-patch has-unit-tests added
#2
follow-up:
↓ 3
@
5 weeks ago
Test & Review Report
Tested PR #14056 locally against trunk.
Environment
- WordPress: 7.2-alpha-63166-src (trunk)
- PHP: 8.3.33
- Database: MariaDB 10.11
- PHPUnit: 9.6.37
- PHPCS: 3.13.5 (WordPress-Core)
Testing Results
- Zero / Low-count views:
- On a site with 0 comments, only
All (0)is rendered. - On a site with only approved comments (e.g. 5 approved, 0 pending, 0 spam, 0 trash), only
All (5) | Approved (5)are rendered.
- On a site with 0 comments, only
- Active Tab Disappearance (Edge Case):
- If an admin navigates to
edit-comments.php?comment_status=moderated(e.g. from an email notification for a comment that was approved by another moderator) or?comment_status=spam(after clicking "Empty Spam"), themoderated/spamview is skipped because its count is0. - Result: The user is on
?comment_status=moderated, but the Pending tab is completely absent from the navigation bar, and none of the remaining links (All,Approved) haveclass="current". The user has no visual indicator of what status is currently filtered. - At a minimum, the currently active view should never be omitted:
if ( 'all' !== $status && empty( $num_comments->$status ) && $status !== $comment_status ) { continue; }
- If an admin navigates to
- Workflow Considerations (Comments vs Posts):
- While
WP_Posts_List_Tablehides empty statuses like Drafts and Trash,WP_Comments_List_Tableserves a fundamentally different purpose centered on moderation. Pending (0)is an active task queue where(0)provides reassuring confirmation of "Inbox Zero". If the tab disappears, administrators may wonder if comment moderation was disabled or broken.Spam (0)provides visibility into whether spam filtering is operating and allows moderators to check for false positives without waiting for a new spam comment to cause the tab to suddenly appear. Dynamically adding/removing tabs causes the navigation bar to jump.
- While
- Filter Backward Compatibility (
comment_status_links):- The
comment_status_linksfilter DocBlock explicitly documents that$status_links: Includes 'All', 'Mine', 'Pending', 'Approved', 'Spam', and 'Trash'. - Plugins manipulating these links will encounter
Undefined array keynotices in PHP 8+ if keys are omitted dynamically.
- The
- Reversal of Ticket #42066:
- In WP 6.1 (#42066),
test_get_views_should_return_views_by_default()was added to explicitly protect the contract that all views are present by default with0counts.
- In WP 6.1 (#42066),
Recommendation
While keeping list tables consistent is a good goal, edit-comments.php is primarily a moderation queue where zero-state visibility is informative. If any zero-count filtering is pursued, moderated and approved should remain permanent, and the currently requested status ($comment_status) must never be hidden.
Props therssoftware.
AI Disclosure: In accordance with the WordPress AI policy, I disclose that generative AI (Google Antigravity) was used in testing, reproduction, and drafting this review report. All test executions, script verifications, and comparisons were performed and validated locally in the development environment.
#3
in reply to: ↑ 2
@
5 weeks ago
@therssoftware Thanks for the feedback! I have updated the PR to address the concerns you had on it.
@
5 weeks ago
Deleting and restoring a comment and a post in WordPress 7.1.3, then deleting and restoring a comment in Trunk with the patch
#4
@
5 weeks ago
- Focuses administration added
- Keywords 2nd-opinion added
While keeping list tables consistent is a good goal,
edit-comments.phpis primarily a moderation queue where zero-state visibility is informative.
The Comments page is not consistent with other list table pages. It uses Ajax to update the items in the table and the filter links; post lists reload the page when the status changes.
For the video shows:
- Deleting and restoring a comment in WordPress 7.1.3, where the filter links include zero counts, and those numbers updated from 1 for All and Approved to 1 for Trash and zero for the rest.
- Deleting and restoring a post in WordPress 7.1.3, where the entire page reloads.
- Deleting and restoring a comment in Trunk with PR 14056, which
hidesremoves the "Spam (0)" and "Trash (0)" links. When I deleted the comment, the All and Approved counts decreased (the comment was not mine), but there was no link for the comment in Trash.
#5
follow-up:
↓ 6
@
5 weeks ago
Replying to sabernhardt:
The Comments page is not consistent with other list table pages. It uses Ajax to update the items in the table and the filter links; post lists reload the page when the status changes.
When I deleted the comment, the All and Approved counts decreased (the comment was not mine), but there was no link for the comment in Trash.
Thank you @sabernhardt for the testing video and for highlighting the core architectural difference here.
This illustrates why WP_Comments_List_Table cannot simply mirror WP_Posts_List_Table:
- Ajax Lifecycle in
edit-comments.js: Unlike the Posts screen which performs a full page reload upon trashing,edit-comments.phpupdates counts in-place usingupdateCountText( 'span.trash-count', 1 )andupdateCountText( 'span.spam-count', 1 ). IfTrash (0)orSpam (0)is omitted from initial server-side rendering, those DOM elements do not exist, and the Ajax handler has no view link to update or display. Trashing an item leaves the user with no UI link to navigate to Trash or restore the comment without manually modifying the URL or hard-refreshing the page. - Complexity Trade-off: Supporting dynamic zero-count hiding on the Comments screen would require rewriting
edit-comments.jsto dynamically generate, insert, and tear down HTML<li>view links and delimiters in response to Ajax actions, adding substantial client-side overhead for questionable utility. - Established Intent (Ticket #42066): As noted in comment:2, unit tests were specifically added in WP 6.1 under #42066 to protect the presence of all default views with
0counts precisely to maintain stability for this moderation interface.
Given this Ajax dependency and the distinct moderation workflow of comments, keeping all default view links visible appears to be intentional and necessary by design. Unless there is appetite for a broader client-side overhaul of the comments Ajax system, closing this enhancement as wontfix may be the cleanest resolution.
#6
in reply to: ↑ 5
@
5 weeks ago
Replying to therssoftware:
Replying to sabernhardt:
The Comments page is not consistent with other list table pages. It uses Ajax to update the items in the table and the filter links; post lists reload the page when the status changes.
When I deleted the comment, the All and Approved counts decreased (the comment was not mine), but there was no link for the comment in Trash.
Thank you @sabernhardt for the testing video and for highlighting the core architectural difference here.
This illustrates why
WP_Comments_List_Tablecannot simply mirrorWP_Posts_List_Table:
- Ajax Lifecycle in
edit-comments.js: Unlike the Posts screen which performs a full page reload upon trashing,edit-comments.phpupdates counts in-place usingupdateCountText( 'span.trash-count', 1 )andupdateCountText( 'span.spam-count', 1 ). IfTrash (0)orSpam (0)is omitted from initial server-side rendering, those DOM elements do not exist, and the Ajax handler has no view link to update or display. Trashing an item leaves the user with no UI link to navigate to Trash or restore the comment without manually modifying the URL or hard-refreshing the page.- Complexity Trade-off: Supporting dynamic zero-count hiding on the Comments screen would require rewriting
edit-comments.jsto dynamically generate, insert, and tear down HTML<li>view links and delimiters in response to Ajax actions, adding substantial client-side overhead for questionable utility.- Established Intent (Ticket #42066): As noted in comment:2, unit tests were specifically added in WP 6.1 under #42066 to protect the presence of all default views with
0counts precisely to maintain stability for this moderation interface.Given this Ajax dependency and the distinct moderation workflow of comments, keeping all default view links visible appears to be intentional and necessary by design. Unless there is appetite for a broader client-side overhaul of the comments Ajax system, closing this enhancement as
wontfixmay be the cleanest resolution.
@therssoftware I have updated the PR to address the concerns shared.
#7
@
5 weeks ago
Replying to abditsori:
Thanks @abditsori for working to address the Ajax update issue!
While re-rendering .subsubsub over Ajax works in isolation on a clean install, doing so inside _wp_ajax_delete_comment_response() introduces a significant architectural bug for plugins:
- Plugin View Erasure (
load-edit-comments.php): Standard practice for plugins extendingedit-comments.phpis to hook theviews_edit-commentsfilter insideadd_action( 'load-edit-comments.php', ... ). During Ajax requests toadmin-ajax.php, the screen actionload-edit-comments.phpis never fired. As a result, when_wp_ajax_delete_comment_response()calls$wp_list_table->views(), it runs without any plugin-registered views. Executing$( '.subsubsub' ).replaceWith(...)on the client will wipe out all third-party tabs from the navigation bar the moment an admin trashes, spams, or approves a comment.
- Omitted
$comment_typeGlobal:WP_Comments_List_Table::get_views()relies onglobal $post_id, $comment_status, $comment_type;(line 253). The Ajax handler parses$post_idand$comment_status, but omits$comment_type. If an administrator is viewing comments filtered by type (?comment_type=...), the re-rendered tabs strip that parameter from the links.
- Complexity & Core Precedent (Ticket #42066):
This demonstrates why
edit-comments.phphas historically kept all status views permanently rendered at(0)count (protected bytest_get_views_should_return_views_by_defaultsince WP 6.1). Modifying client-side list table DOM trees dynamically over Ajax adds substantial fragility to achieve a cosmetic change.
If the goal is purely visual de-cluttering without breaking the Ajax lifecycle or plugin extensibility, a safer alternative would be keeping all view links in the DOM and toggling their visibility via CSS classes (e.g. .is-empty-view { display: none; } which edit-comments.js can simply toggle when the count reaches 0 or > 0), rather than omitting them from the PHP array and re-rendering HTML over Ajax.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: https://core.trac.wordpress.org/ticket/66260
Summary
WP_Posts_List_Table::get_views()hides any status filter link (other than "All") whose post count is zero:WP_Comments_List_Table::get_views()had no equivalent check, so "Pending", "Approved", "Spam", "Trash", and "Mine" were always rendered as filter links even when their count is(0), cluttering the screen with filters that return no results.Changes
class-wp-comments-list-table.php, skip adding a comment status link (other thanall) when its count is empty, mirroring the Posts list table's logic.test_get_views_should_return_views_by_defaultfromwpCommentsListTable.php, since it explicitly asserted the old behavior (all statuses shown at(0)), which this change intentionally reverses. No replacement test is included in this PR.Test plan
php -lon both changed files.Tests_Admin_wpCommentsListTable— 9 tests, 24 assertions, all passing.🤖 Generated with Claude Code