Make WordPress Core


Ignore:
Timestamp:
09/19/2022 09:06:08 PM (22 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-privacy-requests-table.php

    r52239 r54215  
    154154        $admin_url = $this->get_admin_url();
    155155
    156         $current_link_attributes = empty( $current_status ) ? ' class="current" aria-current="page"' : '';
    157         $status_label            = sprintf(
     156        $status_label = sprintf(
    158157            /* translators: %s: Number of requests. */
    159158            _nx(
     
    166165        );
    167166
    168         $views['all'] = sprintf(
    169             '<a href="%s"%s>%s</a>',
    170             esc_url( $admin_url ),
    171             $current_link_attributes,
    172             $status_label
     167        $views['all'] = array(
     168            'url'     => esc_url( $admin_url ),
     169            'label'   => $status_label,
     170            'current' => empty( $current_status ),
    173171        );
    174172
     
    179177            }
    180178
    181             $current_link_attributes = $status === $current_status ? ' class="current" aria-current="page"' : '';
    182             $total_status_requests   = absint( $counts->{$status} );
     179            $total_status_requests = absint( $counts->{$status} );
    183180
    184181            if ( ! $total_status_requests ) {
     
    193190            $status_link = add_query_arg( 'filter-status', $status, $admin_url );
    194191
    195             $views[ $status ] = sprintf(
    196                 '<a href="%s"%s>%s</a>',
    197                 esc_url( $status_link ),
    198                 $current_link_attributes,
    199                 $status_label
     192            $views[ $status ] = array(
     193                'url'     => esc_url( $status_link ),
     194                'label'   => $status_label,
     195                'current' => $status === $current_status,
    200196            );
    201197        }
    202198
    203         return $views;
     199        return $this->get_views_links( $views );
    204200    }
    205201
Note: See TracChangeset for help on using the changeset viewer.