Make WordPress Core

Ticket #50538: 50538.3.diff

File 50538.3.diff, 4.6 KB (added by pbiron, 5 years ago)
  • src/js/_enqueues/admin/edit-comments.js

    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, 
    1515        isDashboard = $('#dashboard_right_now').length,
    1616        titleDiv, titleRegEx;
    1717
     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       
    1828        /**
    1929         * Extracts a number from the content of a jQuery element.
    2030         *
    var getCount, updateCount, updateCountText, updatePending, updateApproved, 
    5868                        n = n + n1;
    5969                }
    6070                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                }
    6186        };
    6287
    6388        /**
  • src/wp-admin/css/common.css

    diff --git a/src/wp-admin/css/common.css b/src/wp-admin/css/common.css
    index b959b1c40a..91799cf553 100644
    a b code { 
    457457        white-space: nowrap;
    458458}
    459459
     460.edit-comments-php .subsubsub li.hidden,
     461.index-php #latest-comments .subsubsub li.hidden {
     462        display: none;
     463}
     464
    460465/* .widefat - main style for tables */
    461466.widefat {
    462467        border-spacing: 0;
  • src/wp-admin/includes/class-wp-comments-list-table.php

    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 { 
    302302                        }
    303303
    304304                        if ( ! isset( $num_comments->$status ) ) {
    305                                 $num_comments->$status = 10;
     305                                $num_comments->$status = 0;
    306306                        }
     307
    307308                        $link = add_query_arg( 'comment_status', $status, $link );
    308309                        if ( $post_id ) {
    309310                                $link = add_query_arg( 'p', absint( $post_id ), $link );
    310311                        }
     312
    311313                        /*
    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>';
    324332                }
    325333
    326334                /**