Make WordPress Core


Ignore:
Timestamp:
09/19/2022 09:06:08 PM (2 years 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-ms-sites-list-table.php

    r54071 r54215  
    263263
    264264        foreach ( $statuses as $status => $label_count ) {
    265             $current_link_attributes = $requested_status === $status || ( '' === $requested_status && 'all' === $status )
    266                 ? ' class="current" aria-current="page"'
    267                 : '';
    268265            if ( (int) $counts[ $status ] > 0 ) {
    269266                $label    = sprintf( translate_nooped_plural( $label_count, $counts[ $status ] ), number_format_i18n( $counts[ $status ] ) );
    270267                $full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url );
    271268
    272                 $view_links[ $status ] = sprintf(
    273                     '<a href="%1$s"%2$s>%3$s</a>',
    274                     esc_url( $full_url ),
    275                     $current_link_attributes,
    276                     $label
     269                $view_links[ $status ] = array(
     270                    'url'     => esc_url( $full_url ),
     271                    'label'   => $label,
     272                    'current' => $requested_status === $status || ( '' === $requested_status && 'all' === $status ),
    277273                );
    278274            }
    279275        }
    280276
    281         return $view_links;
     277        return $this->get_views_links( $view_links );
    282278    }
    283279
Note: See TracChangeset for help on using the changeset viewer.