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

    r54062 r54215  
    577577
    578578            if ( 'search' !== $type ) {
    579                 $status_links[ $type ] = sprintf(
    580                     "<a href='%s'%s>%s</a>",
    581                     add_query_arg( 'plugin_status', $type, 'plugins.php' ),
    582                     ( $type === $status ) ? ' class="current" aria-current="page"' : '',
    583                     sprintf( $text, number_format_i18n( $count ) )
     579                $status_links[ $type ] = array(
     580                    'url'     => add_query_arg( 'plugin_status', $type, 'plugins.php' ),
     581                    'label'   => sprintf( $text, number_format_i18n( $count ) ),
     582                    'current' => $type === $status,
    584583                );
    585584            }
    586585        }
    587586
    588         return $status_links;
     587        return $this->get_views_links( $status_links );
    589588    }
    590589
Note: See TracChangeset for help on using the changeset viewer.