From 3baecf04ee1c013f3021d1509ff8ecc54caf5224 Mon Sep 17 00:00:00 2001 From: desrosj Date: Wed, 16 Jan 2019 17:52:49 +0000 Subject: [PATCH] Privacy: Allow column sorting in the privacy request admin tables. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Built from https://develop.svn.wordpress.org/trunk@44628 git-svn-id: http://core.svn.wordpress.org/trunk@44459 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/user.php | 34 +++++++++++++++++++++++++--------- wp-includes/version.php | 2 +- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index 16ea6eddbc..0aa70c35c8 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -809,6 +809,7 @@ function _wp_personal_data_export_page() { array( 'plural' => 'privacy_requests', 'singular' => 'privacy_request', + 'screen' => 'export_personal_data', ) ); $requests_table->process_bulk_action(); @@ -882,6 +883,7 @@ function _wp_personal_data_removal_page() { array( 'plural' => 'privacy_requests', 'singular' => 'privacy_request', + 'screen' => 'remove_personal_data', ) ); @@ -1090,7 +1092,15 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table { * @return array Default sortable columns. */ protected function get_sortable_columns() { - return array(); + // The initial sorting is by 'Requested' (post_date) and descending. + // With initial sorting, the first click on 'Requested' should be ascending. + // With 'Requester' sorting active, the next click on 'Requested' should be descending. + $desc_first = isset( $_GET['orderby'] ); + + return array( + 'email' => 'requester', + 'created_timestamp' => array( 'requested', $desc_first ), + ); } /** @@ -1235,18 +1245,11 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table { * Prepare items to output. * * @since 4.9.6 + * @since 5.1.0 Added support for column sorting. */ public function prepare_items() { global $wpdb; - $primary = $this->get_primary_column_name(); - $this->_column_headers = array( - $this->get_columns(), - array(), - $this->get_sortable_columns(), - $primary, - ); - $this->items = array(); $posts_per_page = $this->get_items_per_page( $this->request_type . '_requests_per_page' ); $args = array( @@ -1258,6 +1261,19 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table { 's' => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '', ); + $orderby_mapping = array( + 'requester' => 'post_title', + 'requested' => 'post_date', + ); + + if ( isset( $_REQUEST['orderby'] ) && isset( $orderby_mapping[ $_REQUEST['orderby'] ] ) ) { + $args['orderby'] = $orderby_mapping[ $_REQUEST['orderby'] ]; + } + + if ( isset( $_REQUEST['order'] ) && in_array( strtoupper( $_REQUEST['order'] ), array( 'ASC', 'DESC' ), true ) ) { + $args['order'] = strtoupper( $_REQUEST['order'] ); + } + if ( ! empty( $_REQUEST['filter-status'] ) ) { $filter_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : ''; $args['post_status'] = $filter_status; diff --git a/wp-includes/version.php b/wp-includes/version.php index 885e75fea6..74a38773c3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-beta1-44627'; +$wp_version = '5.1-beta1-44628'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.