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-ms-themes-list-table.php

    r51795 r54215  
    445445
    446446            if ( 'search' !== $type ) {
    447                 $status_links[ $type ] = sprintf(
    448                     "<a href='%s'%s>%s</a>",
    449                     esc_url( add_query_arg( 'theme_status', $type, $url ) ),
    450                     ( $type === $status ) ? ' class="current" aria-current="page"' : '',
    451                     sprintf( $text, number_format_i18n( $count ) )
     447                $status_links[ $type ] = array(
     448                    'url'     => esc_url( add_query_arg( 'theme_status', $type, $url ) ),
     449                    'label'   => sprintf( $text, number_format_i18n( $count ) ),
     450                    'current' => $type === $status,
    452451                );
    453452            }
    454453        }
    455454
    456         return $status_links;
     455        return $this->get_views_links( $status_links );
    457456    }
    458457
Note: See TracChangeset for help on using the changeset viewer.