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

    r54063 r54215  
    311311        $display_tabs = array();
    312312        foreach ( (array) $tabs as $action => $text ) {
    313             $current_link_attributes                     = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
    314             $href                                        = self_admin_url( 'plugin-install.php?tab=' . $action );
    315             $display_tabs[ 'plugin-install-' . $action ] = "<a href='$href'$current_link_attributes>$text</a>";
     313            $display_tabs[ 'plugin-install-' . $action ] = array(
     314                'url'     => self_admin_url( 'plugin-install.php?tab=' . $action ),
     315                'label'   => $text,
     316                'current' => $action === $tab,
     317            );
    316318        }
    317319        // No longer a real tab.
    318320        unset( $display_tabs['plugin-install-upload'] );
    319321
    320         return $display_tabs;
     322        return $this->get_views_links( $display_tabs );
    321323    }
    322324
Note: See TracChangeset for help on using the changeset viewer.