wp/wp-admin/includes/class-wp-privacy-requests-table.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    41 		$columns = array(
    41 		$columns = array(
    42 			'cb'                => '<input type="checkbox" />',
    42 			'cb'                => '<input type="checkbox" />',
    43 			'email'             => __( 'Requester' ),
    43 			'email'             => __( 'Requester' ),
    44 			'status'            => __( 'Status' ),
    44 			'status'            => __( 'Status' ),
    45 			'created_timestamp' => __( 'Requested' ),
    45 			'created_timestamp' => __( 'Requested' ),
    46 			'next_steps'        => __( 'Next Steps' ),
    46 			'next_steps'        => __( 'Next steps' ),
    47 		);
    47 		);
    48 		return $columns;
    48 		return $columns;
    49 	}
    49 	}
    50 
    50 
    51 	/**
    51 	/**
   204 	/**
   204 	/**
   205 	 * Get bulk actions.
   205 	 * Get bulk actions.
   206 	 *
   206 	 *
   207 	 * @since 4.9.6
   207 	 * @since 4.9.6
   208 	 *
   208 	 *
   209 	 * @return string[] Array of bulk action labels keyed by their action.
   209 	 * @return array Array of bulk action labels keyed by their action.
   210 	 */
   210 	 */
   211 	protected function get_bulk_actions() {
   211 	protected function get_bulk_actions() {
   212 		return array(
   212 		return array(
   213 			'delete' => __( 'Delete Requests' ),
   213 			'resend'   => __( 'Resend confirmation requests' ),
   214 			'resend' => __( 'Resend Confirmation Requests' ),
   214 			'complete' => __( 'Mark requests as completed' ),
       
   215 			'delete'   => __( 'Delete requests' ),
   215 		);
   216 		);
   216 	}
   217 	}
   217 
   218 
   218 	/**
   219 	/**
   219 	 * Process bulk actions.
   220 	 * Process bulk actions.
   220 	 *
   221 	 *
   221 	 * @since 4.9.6
   222 	 * @since 4.9.6
       
   223 	 * @since 5.6.0 Added support for the `complete` action.
   222 	 */
   224 	 */
   223 	public function process_bulk_action() {
   225 	public function process_bulk_action() {
   224 		$action      = $this->current_action();
   226 		$action      = $this->current_action();
   225 		$request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array();
   227 		$request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array();
   226 
   228 
   227 		$count = 0;
   229 		if ( empty( $request_ids ) ) {
   228 
   230 			return;
   229 		if ( $request_ids ) {
   231 		}
   230 			check_admin_referer( 'bulk-privacy_requests' );
   232 
   231 		}
   233 		$count    = 0;
       
   234 		$failures = 0;
       
   235 
       
   236 		check_admin_referer( 'bulk-privacy_requests' );
   232 
   237 
   233 		switch ( $action ) {
   238 		switch ( $action ) {
       
   239 			case 'resend':
       
   240 				foreach ( $request_ids as $request_id ) {
       
   241 					$resend = _wp_privacy_resend_request( $request_id );
       
   242 
       
   243 					if ( $resend && ! is_wp_error( $resend ) ) {
       
   244 						$count++;
       
   245 					} else {
       
   246 						$failures++;
       
   247 					}
       
   248 				}
       
   249 
       
   250 				if ( $failures ) {
       
   251 					add_settings_error(
       
   252 						'bulk_action',
       
   253 						'bulk_action',
       
   254 						sprintf(
       
   255 							/* translators: %d: Number of requests. */
       
   256 							_n(
       
   257 								'%d confirmation request failed to resend.',
       
   258 								'%d confirmation requests failed to resend.',
       
   259 								$failures
       
   260 							),
       
   261 							$failures
       
   262 						),
       
   263 						'error'
       
   264 					);
       
   265 				}
       
   266 
       
   267 				if ( $count ) {
       
   268 					add_settings_error(
       
   269 						'bulk_action',
       
   270 						'bulk_action',
       
   271 						sprintf(
       
   272 							/* translators: %d: Number of requests. */
       
   273 							_n(
       
   274 								'%d confirmation request re-sent successfully.',
       
   275 								'%d confirmation requests re-sent successfully.',
       
   276 								$count
       
   277 							),
       
   278 							$count
       
   279 						),
       
   280 						'success'
       
   281 					);
       
   282 				}
       
   283 
       
   284 				break;
       
   285 
       
   286 			case 'complete':
       
   287 				foreach ( $request_ids as $request_id ) {
       
   288 					$result = _wp_privacy_completed_request( $request_id );
       
   289 
       
   290 					if ( $result && ! is_wp_error( $result ) ) {
       
   291 						$count++;
       
   292 					}
       
   293 				}
       
   294 
       
   295 				add_settings_error(
       
   296 					'bulk_action',
       
   297 					'bulk_action',
       
   298 					sprintf(
       
   299 						/* translators: %d: Number of requests. */
       
   300 						_n(
       
   301 							'%d request marked as complete.',
       
   302 							'%d requests marked as complete.',
       
   303 							$count
       
   304 						),
       
   305 						$count
       
   306 					),
       
   307 					'success'
       
   308 				);
       
   309 				break;
       
   310 
   234 			case 'delete':
   311 			case 'delete':
   235 				foreach ( $request_ids as $request_id ) {
   312 				foreach ( $request_ids as $request_id ) {
   236 					if ( wp_delete_post( $request_id, true ) ) {
   313 					if ( wp_delete_post( $request_id, true ) ) {
   237 						$count ++;
   314 						$count++;
       
   315 					} else {
       
   316 						$failures++;
   238 					}
   317 					}
   239 				}
   318 				}
   240 
   319 
   241 				add_settings_error(
   320 				if ( $failures ) {
   242 					'bulk_action',
   321 					add_settings_error(
   243 					'bulk_action',
   322 						'bulk_action',
   244 					/* translators: %d: Number of requests. */
   323 						'bulk_action',
   245 					sprintf( _n( 'Deleted %d request', 'Deleted %d requests', $count ), $count ),
   324 						sprintf(
   246 					'success'
   325 							/* translators: %d: Number of requests. */
   247 				);
   326 							_n(
   248 				break;
   327 								'%d request failed to delete.',
   249 			case 'resend':
   328 								'%d requests failed to delete.',
   250 				foreach ( $request_ids as $request_id ) {
   329 								$failures
   251 					$resend = _wp_privacy_resend_request( $request_id );
   330 							),
   252 
   331 							$failures
   253 					if ( $resend && ! is_wp_error( $resend ) ) {
   332 						),
   254 						$count++;
   333 						'error'
   255 					}
   334 					);
   256 				}
   335 				}
   257 
   336 
   258 				add_settings_error(
   337 				if ( $count ) {
   259 					'bulk_action',
   338 					add_settings_error(
   260 					'bulk_action',
   339 						'bulk_action',
   261 					/* translators: %d: Number of requests. */
   340 						'bulk_action',
   262 					sprintf( _n( 'Re-sent %d request', 'Re-sent %d requests', $count ), $count ),
   341 						sprintf(
   263 					'success'
   342 							/* translators: %d: Number of requests. */
   264 				);
   343 							_n(
       
   344 								'%d request deleted successfully.',
       
   345 								'%d requests deleted successfully.',
       
   346 								$count
       
   347 							),
       
   348 							$count
       
   349 						),
       
   350 						'success'
       
   351 					);
       
   352 				}
       
   353 
   265 				break;
   354 				break;
   266 		}
   355 		}
   267 	}
   356 	}
   268 
   357 
   269 	/**
   358 	/**
   393 
   482 
   394 	/**
   483 	/**
   395 	 * Default column handler.
   484 	 * Default column handler.
   396 	 *
   485 	 *
   397 	 * @since 4.9.6
   486 	 * @since 4.9.6
       
   487 	 * @since 5.7.0 Added `manage_{$this->screen->id}_custom_column` action.
   398 	 *
   488 	 *
   399 	 * @param WP_User_Request $item        Item being shown.
   489 	 * @param WP_User_Request $item        Item being shown.
   400 	 * @param string          $column_name Name of column being shown.
   490 	 * @param string          $column_name Name of column being shown.
   401 	 * @return string Default column output.
       
   402 	 */
   491 	 */
   403 	public function column_default( $item, $column_name ) {
   492 	public function column_default( $item, $column_name ) {
   404 		$cell_value = $item->$column_name;
   493 		/**
   405 
   494 		 * Fires for each custom column of a specific request type in the Requests list table.
   406 		if ( in_array( $column_name, array( 'created_timestamp' ), true ) ) {
   495 		 *
   407 			return $this->get_timestamp_as_date( $cell_value );
   496 		 * Custom columns are registered using the {@see 'manage_export-personal-data_columns'}
   408 		}
   497 		 * and the {@see 'manage_erase-personal-data_columns'} filters.
   409 
   498 		 *
   410 		return $cell_value;
   499 		 * @since 5.7.0
       
   500 		 *
       
   501 		 * @param string          $column_name The name of the column to display.
       
   502 		 * @param WP_User_Request $item        The item being shown.
       
   503 		 */
       
   504 		do_action( "manage_{$this->screen->id}_custom_column", $column_name, $item );
       
   505 	}
       
   506 
       
   507 	/**
       
   508 	 * Created timestamp column. Overridden by children.
       
   509 	 *
       
   510 	 * @since 5.7.0
       
   511 	 *
       
   512 	 * @param WP_User_Request $item Item being shown.
       
   513 	 * @return string Human readable date.
       
   514 	 */
       
   515 	public function column_created_timestamp( $item ) {
       
   516 		return $this->get_timestamp_as_date( $item->created_timestamp );
   411 	}
   517 	}
   412 
   518 
   413 	/**
   519 	/**
   414 	 * Actions column. Overridden by children.
   520 	 * Actions column. Overridden by children.
   415 	 *
   521 	 *