Make WordPress Core


Ignore:
Timestamp:
09/19/2022 09:06:08 PM (21 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-theme-install-list-table.php

    r52947 r54215  
    187187        $display_tabs = array();
    188188        foreach ( (array) $tabs as $action => $text ) {
    189             $current_link_attributes                    = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
    190             $href                                       = self_admin_url( 'theme-install.php?tab=' . $action );
    191             $display_tabs[ 'theme-install-' . $action ] = "<a href='$href'$current_link_attributes>$text</a>";
    192         }
    193 
    194         return $display_tabs;
     189            $display_tabs[ 'theme-install-' . $action ] = array(
     190                'url'     => self_admin_url( 'theme-install.php?tab=' . $action ),
     191                'label'   => $text,
     192                'current' => $action === $tab,
     193            );
     194        }
     195
     196        return $this->get_views_links( $display_tabs );
    195197    }
    196198
Note: See TracChangeset for help on using the changeset viewer.