Make WordPress Core

Opened 9 hours ago

Last modified 9 hours ago

#66260 new enhancement

Comments: Hide zero-count status filters on the Comments list table

Reported by: abditsori Owned by:
Priority: normal Milestone: Awaiting Review
Component: Comments Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

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:

  1. Go to a site where every comment is approved (no pending, spam, or trashed comments).
  2. Go to Comments in wp-admin.
  3. 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.

Change History (1)

This ticket was mentioned in ​PR #14056 on ​WordPress/wordpress-develop by ​@abditsori.


9 hours ago
#1

  • Keywords has-patch has-unit-tests added

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:

if ( ! in_array( $status_name, $avail_post_stati, true ) || empty( $num_posts->$status_name ) ) {
        continue;
}

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

  • In class-wp-comments-list-table.php, skip adding a comment status link (other than all) when its count is empty, mirroring the Posts list table's logic.
  • Removed test_get_views_should_return_views_by_default from wpCommentsListTable.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

  • [x] php -l on both changed files.
  • [x] Ran the remaining tests in Tests_Admin_wpCommentsListTable — 9 tests, 24 assertions, all passing.

🤖 Generated with ​Claude Code

Note: See TracTickets for help on using tickets.