From 99cc86c0a2336f39862afb31d73dddaa8ba33d9e Mon Sep 17 00:00:00 2001
From: Paul Biron <paul@sparrowhawkcomputing.com>
Date: Sun, 5 Jul 2020 11:28:05 -0600
Subject: [PATCH] Hide views with 0 counts on the comments list table.
---
src/js/_enqueues/admin/edit-comments.js | 25 ++++++++++++++
src/wp-admin/css/common.css | 5 +++
.../includes/class-wp-comments-list-table.php | 34 ++++++++++++-------
3 files changed, 51 insertions(+), 13 deletions(-)
diff --git a/src/js/_enqueues/admin/edit-comments.js b/src/js/_enqueues/admin/edit-comments.js
index 1be9f2c473..0a1abe16a2 100644
a
|
b
|
var getCount, updateCount, updateCountText, updatePending, updateApproved, |
15 | 15 | isDashboard = $('#dashboard_right_now').length, |
16 | 16 | titleDiv, titleRegEx; |
17 | 17 | |
| 18 | $( document ).ready( function() { |
| 19 | // Wrap the view separators (" |") in a span so that we can hide/show them in updateCount(). |
| 20 | $( '.wrap > .subsubsub li, #latest-comments .subsubsub li' ).each( function() { |
| 21 | $( this ).html( $( this ).html().replace( ' |', '<span class="separator"> |</span>') ); |
| 22 | } ); |
| 23 | // Hide the separator on the last visibile view. |
| 24 | $( '.wrap > .subsubsub li:not( .hidden ), #latest-comments .subsubsub li:not( .hidden )' ) |
| 25 | .last().find( '.separator' ).addClass( 'hidden' ); |
| 26 | } ); |
| 27 | |
18 | 28 | /** |
19 | 29 | * Extracts a number from the content of a jQuery element. |
20 | 30 | * |
… |
… |
var getCount, updateCount, updateCountText, updatePending, updateApproved, |
58 | 68 | n = n + n1; |
59 | 69 | } |
60 | 70 | el.html(n); |
| 71 | |
| 72 | if ( ! ( el.parents( 'div' ).hasClass( 'wp-menu-name' ) || el.parents( 'li' ).hasClass( 'all' ) ) ) { |
| 73 | // Not the main WP menu or the "all" status. |
| 74 | // Hide the view if the count is 0, show it otherwise. |
| 75 | if ( '0' === n ) { |
| 76 | el.parents( 'li' ).addClass( 'hidden' ); |
| 77 | } else { |
| 78 | el.parents( 'li' ).removeClass( 'hidden' ); |
| 79 | } |
| 80 | |
| 81 | // Ensure all but the last separator are visible. |
| 82 | $( '.wrap > .subsubsub li .separator, #latest-comments .subsubsub li .separator' ).removeClass( 'hidden' ); |
| 83 | $( '.wrap > .subsubsub li:not( .hidden ), #latest-comments .subsubsub li:not( .hidden )' ) |
| 84 | .last().find( '.separator' ).addClass( 'hidden' ); |
| 85 | } |
61 | 86 | }; |
62 | 87 | |
63 | 88 | /** |
diff --git a/src/wp-admin/css/common.css b/src/wp-admin/css/common.css
index b959b1c40a..91799cf553 100644
a
|
b
|
code { |
457 | 457 | white-space: nowrap; |
458 | 458 | } |
459 | 459 | |
| 460 | .edit-comments-php .subsubsub li.hidden, |
| 461 | .index-php #latest-comments .subsubsub li.hidden { |
| 462 | display: none; |
| 463 | } |
| 464 | |
460 | 465 | /* .widefat - main style for tables */ |
461 | 466 | .widefat { |
462 | 467 | border-spacing: 0; |
diff --git a/src/wp-admin/includes/class-wp-comments-list-table.php b/src/wp-admin/includes/class-wp-comments-list-table.php
index e3678b60d5..ae783eccdd 100644
a
|
b
|
class WP_Comments_List_Table extends WP_List_Table { |
302 | 302 | } |
303 | 303 | |
304 | 304 | if ( ! isset( $num_comments->$status ) ) { |
305 | | $num_comments->$status = 10; |
| 305 | $num_comments->$status = 0; |
306 | 306 | } |
| 307 | |
307 | 308 | $link = add_query_arg( 'comment_status', $status, $link ); |
308 | 309 | if ( $post_id ) { |
309 | 310 | $link = add_query_arg( 'p', absint( $post_id ), $link ); |
310 | 311 | } |
| 312 | |
311 | 313 | /* |
312 | | // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark |
313 | | if ( !empty( $_REQUEST['s'] ) ) |
314 | | $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link ); |
315 | | */ |
316 | | $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . sprintf( |
317 | | translate_nooped_plural( $label, $num_comments->$status ), |
318 | | sprintf( |
319 | | '<span class="%s-count">%s</span>', |
320 | | ( 'moderated' === $status ) ? 'pending' : $status, |
321 | | number_format_i18n( $num_comments->$status ) |
322 | | ) |
323 | | ) . '</a>'; |
| 314 | // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark |
| 315 | if ( !empty( $_REQUEST['s'] ) ) |
| 316 | $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link ); |
| 317 | */ |
| 318 | |
| 319 | $hidden = ''; |
| 320 | if ( ! ( 'all' === $status || $num_comments->$status ) ) { |
| 321 | $hidden = ' hidden'; |
| 322 | } |
| 323 | |
| 324 | $status_links[ "{$status}{$hidden}" ] = "<a href='$link'$current_link_attributes>" . sprintf( |
| 325 | translate_nooped_plural( $label, $num_comments->$status ), |
| 326 | sprintf( |
| 327 | '<span class="%s-count">%s</span>', |
| 328 | ( 'moderated' === $status ) ? 'pending' : $status, |
| 329 | number_format_i18n( $num_comments->$status ) |
| 330 | ) |
| 331 | ) . '</a>'; |
324 | 332 | } |
325 | 333 | |
326 | 334 | /** |