Make WordPress Core


Ignore:
Timestamp:
09/19/2022 09:06:08 PM (19 months ago)
Author:
davidbaumwald
Message:

Administration: Add new get_views_links method to WP_List_Table.

Many WP_List_Table child classes in core use mostly the same code to create their "view" links markup. To DRY-up the code, a new WP_List_Table->get_view_links method is being introduced to consolidate the HTML link generation when provided an array of links.

This change also implements this new method in the relevant WP_List_Table_xxx child classes get_views methods. Finally, unit tests are being added to validate view links markup and test for some "unhappy paths".

Props afercia, costdev, garrett-eclipse, Dharm1025, juhise, peterwilsoncc.
Fixes #42066.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r54071 r54215  
    294294
    295295        foreach ( $stati as $status => $label ) {
    296             $current_link_attributes = '';
    297 
    298             if ( $status === $comment_status ) {
    299                 $current_link_attributes = ' class="current" aria-current="page"';
    300             }
    301 
    302296            if ( 'mine' === $status ) {
    303297                $current_user_id    = get_current_user_id();
     
    330324            */
    331325
    332             $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . sprintf(
    333                 translate_nooped_plural( $label, $num_comments->$status ),
    334                 sprintf(
    335                     '<span class="%s-count">%s</span>',
    336                     ( 'moderated' === $status ) ? 'pending' : $status,
    337                     number_format_i18n( $num_comments->$status )
    338                 )
    339             ) . '</a>';
     326            $status_links[ $status ] = array(
     327                'url'     => esc_url( $link ),
     328                'label'   => sprintf(
     329                    translate_nooped_plural( $label, $num_comments->$status ),
     330                    sprintf(
     331                        '<span class="%s-count">%s</span>',
     332                        ( 'moderated' === $status ) ? 'pending' : $status,
     333                        number_format_i18n( $num_comments->$status )
     334                    )
     335                ),
     336                'current' => $status === $comment_status,
     337            );
    340338        }
    341339
     
    349347         *                              'Pending', 'Approved', 'Spam', and 'Trash'.
    350348         */
    351         return apply_filters( 'comment_status_links', $status_links );
     349        return apply_filters( 'comment_status_links', $this->get_views_links( $status_links ) );
    352350    }
    353351
Note: See TracChangeset for help on using the changeset viewer.