Make WordPress Core


Ignore:
Timestamp:
01/16/2019 05:51:56 PM (5 years ago)
Author:
desrosj
Message:

Privacy: Allow column sorting in the privacy request admin tables.

This allows users to sort the export and erase personal data request tables by “Requester” (post_title, or user email) and “Requested” (post_date, or when the request was created), which can be helpful when sites have many requests present.

Props birgire, ianbelanger, pbiron, desrosj.
Fixes #43405.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/user.php

    r44606 r44628  
    810810            'plural'   => 'privacy_requests',
    811811            'singular' => 'privacy_request',
     812            'screen'   => 'export_personal_data',
    812813        )
    813814    );
     
    883884            'plural'   => 'privacy_requests',
    884885            'singular' => 'privacy_request',
     886            'screen'   => 'remove_personal_data',
    885887        )
    886888    );
     
    10911093     */
    10921094    protected function get_sortable_columns() {
    1093         return array();
     1095        // The initial sorting is by 'Requested' (post_date) and descending.
     1096        // With initial sorting, the first click on 'Requested' should be ascending.
     1097        // With 'Requester' sorting active, the next click on 'Requested' should be descending.
     1098        $desc_first = isset( $_GET['orderby'] );
     1099
     1100        return array(
     1101            'email'             => 'requester',
     1102            'created_timestamp' => array( 'requested', $desc_first ),
     1103        );
    10941104    }
    10951105
     
    12361246     *
    12371247     * @since 4.9.6
     1248     * @since 5.1.0 Added support for column sorting.
    12381249     */
    12391250    public function prepare_items() {
    12401251        global $wpdb;
    1241 
    1242         $primary               = $this->get_primary_column_name();
    1243         $this->_column_headers = array(
    1244             $this->get_columns(),
    1245             array(),
    1246             $this->get_sortable_columns(),
    1247             $primary,
    1248         );
    12491252
    12501253        $this->items    = array();
     
    12581261            's'              => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '',
    12591262        );
     1263
     1264        $orderby_mapping = array(
     1265            'requester' => 'post_title',
     1266            'requested' => 'post_date',
     1267        );
     1268
     1269        if ( isset( $_REQUEST['orderby'] ) && isset( $orderby_mapping[ $_REQUEST['orderby'] ] ) ) {
     1270            $args['orderby'] = $orderby_mapping[ $_REQUEST['orderby'] ];
     1271        }
     1272
     1273        if ( isset( $_REQUEST['order'] ) && in_array( strtoupper( $_REQUEST['order'] ), array( 'ASC', 'DESC' ), true ) ) {
     1274            $args['order'] = strtoupper( $_REQUEST['order'] );
     1275        }
    12601276
    12611277        if ( ! empty( $_REQUEST['filter-status'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.