: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* List Table API: WP_Privacy_Requests_Table class
* @subpackage Administration
abstract class WP_Privacy_Requests_Table extends WP_List_Table {
* Action name for the requests this table will work with. Classes
* which inherit from WP_Privacy_Requests_Table should define this.
* Example: 'export_personal_data'.
* @var string $request_type Name of action.
protected $request_type = 'INVALID';
* @var string $post_type The post type.
protected $post_type = 'INVALID';
* Gets columns to show in the list table.
* @return string[] Array of column titles keyed by their column name.
public function get_columns() {
'cb' => '<input type="checkbox" />',
'email' => __( 'Requester' ),
'status' => __( 'Status' ),
'created_timestamp' => __( 'Requested' ),
'next_steps' => __( 'Next steps' ),
* Normalizes the admin URL to the current page (by request_type).
* @return string URL to the current admin page.
protected function get_admin_url() {
$pagenow = str_replace( '_', '-', $this->request_type );
if ( 'remove-personal-data' === $pagenow ) {
$pagenow = 'erase-personal-data';
return admin_url( $pagenow . '.php' );
* Gets a list of sortable columns.
* @return array Default sortable columns.
protected function get_sortable_columns() {
* 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'] );
'created_timestamp' => array( 'requested', $desc_first ),
* Returns the default primary column.
* @return string Default primary column name.
protected function get_default_primary_column_name() {
* Counts the number of requests for each status.
* @global wpdb $wpdb WordPress database abstraction object.
* @return object Number of posts for each status.
protected function get_request_counts() {
$cache_key = $this->post_type . '-' . $this->request_type;
$counts = wp_cache_get( $cache_key, 'counts' );
if ( false !== $counts ) {
SELECT post_status, COUNT( * ) AS num_posts
$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $this->post_type, $this->request_type ), ARRAY_A );
$counts = array_fill_keys( get_post_stati(), 0 );
foreach ( $results as $row ) {
$counts[ $row['post_status'] ] = $row['num_posts'];
$counts = (object) $counts;
wp_cache_set( $cache_key, $counts, 'counts' );
* Gets an associative array ( id => link ) with the list of views available on this table.
* @return string[] An array of HTML links keyed by their view.
protected function get_views() {
$current_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : '';
$statuses = _wp_privacy_statuses();
$counts = $this->get_request_counts();
$total_requests = absint( array_sum( (array) $counts ) );
$admin_url = $this->get_admin_url();
/* translators: %s: Number of requests. */
'All <span class="count">(%s)</span>',
'All <span class="count">(%s)</span>',
number_format_i18n( $total_requests )
'url' => esc_url( $admin_url ),
'label' => $status_label,
'current' => empty( $current_status ),
foreach ( $statuses as $status => $label ) {
$post_status = get_post_status_object( $status );
$total_status_requests = absint( $counts->{$status} );
if ( ! $total_status_requests ) {
translate_nooped_plural( $post_status->label_count, $total_status_requests ),
number_format_i18n( $total_status_requests )
$status_link = add_query_arg( 'filter-status', $status, $admin_url );
$views[ $status ] = array(
'url' => esc_url( $status_link ),
'label' => $status_label,
'current' => $status === $current_status,
return $this->get_views_links( $views );
* @return array Array of bulk action labels keyed by their action.
protected function get_bulk_actions() {
'resend' => __( 'Resend confirmation requests' ),
'complete' => __( 'Mark requests as completed' ),
'delete' => __( 'Delete requests' ),
* @since 5.6.0 Added support for the `complete` action.
public function process_bulk_action() {
$action = $this->current_action();
$request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array();
if ( empty( $request_ids ) ) {
check_admin_referer( 'bulk-privacy_requests' );
foreach ( $request_ids as $request_id ) {
$resend = _wp_privacy_resend_request( $request_id );
if ( $resend && ! is_wp_error( $resend ) ) {
/* translators: %d: Number of requests. */
'%d confirmation request failed to resend.',
'%d confirmation requests failed to resend.',
/* translators: %d: Number of requests. */
'%d confirmation request re-sent successfully.',
'%d confirmation requests re-sent successfully.',
foreach ( $request_ids as $request_id ) {
$result = _wp_privacy_completed_request( $request_id );
if ( $result && ! is_wp_error( $result ) ) {
/* translators: %d: Number of requests. */
'%d request marked as complete.',
'%d requests marked as complete.',
foreach ( $request_ids as $request_id ) {
if ( wp_delete_post( $request_id, true ) ) {
/* translators: %d: Number of requests. */
'%d request failed to delete.',
'%d requests failed to delete.',
/* translators: %d: Number of requests. */
'%d request deleted successfully.',
'%d requests deleted successfully.',
* Prepares items to output.
* @since 5.1.0 Added support for column sorting.
public function prepare_items() {
$posts_per_page = $this->get_items_per_page( $this->request_type . '_requests_per_page' );
'post_type' => $this->post_type,
'post_name__in' => array( $this->request_type ),
'posts_per_page' => $posts_per_page,
'offset' => isset( $_REQUEST['paged'] ) ? max( 0, absint( $_REQUEST['paged'] ) - 1 ) * $posts_per_page : 0,
'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;
$requests_query = new WP_Query( $args );
$requests = $requests_query->posts;
foreach ( $requests as $request ) {
$this->items[] = wp_get_user_request( $request->ID );
$this->items = array_filter( $this->items );
$this->set_pagination_args(
'total_items' => $requests_query->found_posts,
'per_page' => $posts_per_page,
* Returns the markup for the Checkbox column.
* @param WP_User_Request $item Item being shown.
* @return string Checkbox column markup.
public function column_cb( $item ) {
'<input type="checkbox" name="request_id[]" id="requester_%1$s" value="%1$s" />' .
'<label for="requester_%1$s"><span class="screen-reader-text">%2$s</span></label><span class="spinner"></span>',
/* translators: Hidden accessibility text. %s: Email address. */
sprintf( __( 'Select %s' ), $item->email )
* @param WP_User_Request $item Item being shown.
* @return string Status column markup.
public function column_status( $item ) {
$status = get_post_status( $item->ID );
$status_object = get_post_status_object( $status );
if ( ! $status_object || empty( $status_object->label ) ) {
case 'request-confirmed':
$timestamp = $item->confirmed_timestamp;
case 'request-completed':
$timestamp = $item->completed_timestamp;
echo '<span class="status-label status-' . esc_attr( $status ) . '">';
echo esc_html( $status_object->label );
echo ' (' . $this->get_timestamp_as_date( $timestamp ) . ')';
* Converts a timestamp for display.
* @param int $timestamp Event timestamp.
* @return string Human readable date.
protected function get_timestamp_as_date( $timestamp ) {
if ( empty( $timestamp ) ) {
$time_diff = time() - $timestamp;
if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) {
/* translators: %s: Human-readable time difference. */
return sprintf( __( '%s ago' ), human_time_diff( $timestamp ) );
return date_i18n( get_option( 'date_format' ), $timestamp );
* Handles the default column.
* @since 5.7.0 Added `manage_{$this->screen->id}_custom_column` action.
* @param WP_User_Request $item Item being shown.
* @param string $column_name Name of column being shown.
public function column_default( $item, $column_name ) {
* Fires for each custom column of a specific request type in the Requests list table.
* Custom columns are registered using the {@see 'manage_export-personal-data_columns'}