- Timestamp:
- 05/01/2018 06:59:48 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r43056 r43060 4335 4335 */ 4336 4336 function wp_ajax_wp_privacy_export_personal_data() { 4337 $request_id = (int) $_POST['id']; 4338 4339 if ( empty( $request_id ) ) { 4340 wp_send_json_error( __( 'Error: Invalid request ID.' ) ); 4337 4338 if ( empty( $_POST['id'] ) ) { 4339 wp_send_json_error( __( 'Missing request ID.' ) ); 4340 } 4341 $request_id = (int) $_POST['id']; 4342 4343 if ( $request_id < 1 ) { 4344 wp_send_json_error( __( 'Invalid request ID.' ) ); 4341 4345 } 4342 4346 4343 4347 if ( ! current_user_can( 'manage_options' ) ) { 4344 wp_send_json_error( __( ' Error:Invalid request.' ) );4348 wp_send_json_error( __( 'Invalid request.' ) ); 4345 4349 } 4346 4350 … … 4351 4355 4352 4356 if ( ! $request || 'export_personal_data' !== $request->action_name ) { 4353 wp_send_json_error( __( ' Error:Invalid request type.' ) );4357 wp_send_json_error( __( 'Invalid request type.' ) ); 4354 4358 } 4355 4359 4356 4360 $email_address = $request->email; 4357 4361 if ( ! is_email( $email_address ) ) { 4358 wp_send_json_error( __( 'Error: A valid email address must be given.' ) ); 4359 } 4360 4362 wp_send_json_error( __( 'A valid email address must be given.' ) ); 4363 } 4364 4365 if ( ! isset( $_POST['exporter'] ) ) { 4366 wp_send_json_error( __( 'Missing exporter index.' ) ); 4367 } 4361 4368 $exporter_index = (int) $_POST['exporter']; 4362 $page = (int) $_POST['page']; 4363 $send_as_email = isset( $_POST['sendAsEmail'] ) ? ( "true" === $_POST['sendAsEmail'] ) : false; 4369 4370 if ( ! isset( $_POST['page'] ) ) { 4371 wp_send_json_error( __( 'Missing page index.' ) ); 4372 } 4373 $page = (int) $_POST['page']; 4374 4375 $send_as_email = isset( $_POST['sendAsEmail'] ) ? ( 'true' === $_POST['sendAsEmail'] ) : false; 4364 4376 4365 4377 /** … … 4370 4382 * @param array $args { 4371 4383 * An array of callable exporters of personal data. Default empty array. 4372 * [ 4373 * callback string Callable exporter that accepts an email address and 4374 * a page and returns an array of name => value 4375 * pairs of personal data. 4376 * exporter_friendly_name string Translated user facing friendly name for the exporter. 4377 * ] 4384 * 4385 * @type array { 4386 * Array of personal data exporters. 4387 * 4388 * @type string $callback Callable exporter function that accepts an 4389 * email address and a page and returns an array 4390 * of name => value pairs of personal data. 4391 * @type string $exporter_friendly_name Translated user facing friendly name for the 4392 * exporter. 4393 * } 4378 4394 * } 4379 4395 */ … … 4381 4397 4382 4398 if ( ! is_array( $exporters ) ) { 4383 wp_send_json_error( 'An exporter has improperly used the registration filter.');4399 wp_send_json_error( __( 'An exporter has improperly used the registration filter.' ) ); 4384 4400 } 4385 4401 … … 4387 4403 if ( 0 < count( $exporters ) ) { 4388 4404 if ( $exporter_index < 1 ) { 4389 wp_send_json_error( 'Exporter index cannot be negative.');4405 wp_send_json_error( __( 'Exporter index cannot be negative.' ) ); 4390 4406 } 4391 4407 4392 4408 if ( $exporter_index > count( $exporters ) ) { 4393 wp_send_json_error( 'Exporter index out of range.');4409 wp_send_json_error( __( 'Exporter index out of range.' ) ); 4394 4410 } 4395 4411 … … 4397 4413 4398 4414 if ( $page < 1 ) { 4399 wp_send_json_error( 'Page index cannot be less than one.');4415 wp_send_json_error( __( 'Page index cannot be less than one.' ) ); 4400 4416 } 4401 4417 … … 4403 4419 4404 4420 if ( ! is_array( $exporter ) ) { 4405 wp_send_json_error( "Expected an array describing the exporter at index {$exporter_index}." ); 4421 wp_send_json_error( 4422 /* translators: %d: array index */ 4423 sprintf( __( 'Expected an array describing the exporter at index %d.' ), $exporter_index ) 4424 ); 4406 4425 } 4407 4426 if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) { 4408 wp_send_json_error( "Exporter array at index {$exporter_index} does not include a friendly name." ); 4427 wp_send_json_error( 4428 /* translators: %d: array index */ 4429 sprintf( __( 'Exporter array at index %d does not include a friendly name.' ), $exporter_index ) 4430 ); 4409 4431 } 4410 4432 if ( ! array_key_exists( 'callback', $exporter ) ) { 4411 wp_send_json_error( "Exporter does not include a callback: {$exporter['exporter_friendly_name']}." ); 4433 wp_send_json_error( 4434 /* translators: %s: exporter friendly name */ 4435 sprintf( __( 'Exporter does not include a callback: %s.' ), esc_html( $exporter['exporter_friendly_name'] ) ) 4436 ); 4412 4437 } 4413 4438 if ( ! is_callable( $exporter['callback'] ) ) { 4414 wp_send_json_error( "Exporter callback is not a valid callback: {$exporter['exporter_friendly_name']}." ); 4439 wp_send_json_error( 4440 /* translators: %s: exporter friendly name */ 4441 sprintf( __( 'Exporter callback is not a valid callback: %s.' ), esc_html( $exporter['exporter_friendly_name'] ) ) 4442 ); 4415 4443 } 4416 4444 … … 4424 4452 4425 4453 if ( ! is_array( $response ) ) { 4426 wp_send_json_error( "Expected response as an array from exporter: {$exporter_friendly_name}." ); 4454 wp_send_json_error( 4455 /* translators: %s: exporter friendly name */ 4456 sprintf( __( 'Expected response as an array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) 4457 ); 4427 4458 } 4428 4459 if ( ! array_key_exists( 'data', $response ) ) { 4429 wp_send_json_error( "Expected data in response array from exporter: {$exporter_friendly_name}." ); 4460 wp_send_json_error( 4461 /* translators: %s: exporter friendly name */ 4462 sprintf( __( 'Expected data in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) 4463 ); 4430 4464 } 4431 4465 if ( ! is_array( $response['data'] ) ) { 4432 wp_send_json_error( "Expected data array in response array from exporter: {$exporter_friendly_name}." ); 4466 wp_send_json_error( 4467 /* translators: %s: exporter friendly name */ 4468 sprintf( __( 'Expected data array in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) 4469 ); 4433 4470 } 4434 4471 if ( ! array_key_exists( 'done', $response ) ) { 4435 wp_send_json_error( "Expected done (boolean) in response array from exporter: {$exporter_friendly_name}." ); 4472 wp_send_json_error( 4473 /* translators: %s: exporter friendly name */ 4474 sprintf( __( 'Expected done (boolean) in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) 4475 ); 4436 4476 } 4437 4477 } else { … … 4453 4493 * @param int $exporter_index The index of the exporter that provided this data. 4454 4494 * @param string $email_address The email address associated with this personal data. 4455 * @param int $page The zero-basedpage for this response.4495 * @param int $page The page for this response. 4456 4496 * @param int $request_id The privacy request post ID associated with this request. 4457 4497 * @param bool $send_as_email Whether the final results of the export should be emailed to the user. … … 4472 4512 */ 4473 4513 function wp_ajax_wp_privacy_erase_personal_data() { 4474 $request_id = (int) $_POST['id']; 4475 4476 if ( empty( $request_id ) ) { 4477 wp_send_json_error( __( 'Error: Invalid request ID.' ) ); 4514 4515 if ( empty( $_POST['id'] ) ) { 4516 wp_send_json_error( __( 'Missing request ID.' ) ); 4517 } 4518 4519 $request_id = (int) $_POST['id']; 4520 4521 if ( $request_id < 1 ) { 4522 wp_send_json_error( __( 'Invalid request ID.' ) ); 4478 4523 } 4479 4524 4480 4525 if ( ! current_user_can( 'delete_users' ) ) { 4481 wp_send_json_error( __( ' Error:Invalid request.' ) );4526 wp_send_json_error( __( 'Invalid request.' ) ); 4482 4527 } 4483 4528 … … 4488 4533 4489 4534 if ( ! $request || 'remove_personal_data' !== $request->action_name ) { 4490 wp_send_json_error( __( ' Error:Invalid request ID.' ) );4535 wp_send_json_error( __( 'Invalid request ID.' ) ); 4491 4536 } 4492 4537 … … 4494 4539 4495 4540 if ( ! is_email( $email_address ) ) { 4496 wp_send_json_error( __( 'Error: Invalid email address in request.' ) ); 4541 wp_send_json_error( __( 'Invalid email address in request.' ) ); 4542 } 4543 4544 if ( ! isset( $_POST['eraser'] ) ) { 4545 wp_send_json_error( __( 'Missing eraser index.' ) ); 4497 4546 } 4498 4547 4499 4548 $eraser_index = (int) $_POST['eraser']; 4500 $page = (int) $_POST['page']; 4549 4550 if ( ! isset( $_POST['page'] ) ) { 4551 wp_send_json_error( __( 'Missing page index.' ) ); 4552 } 4553 4554 $page = (int) $_POST['page']; 4501 4555 4502 4556 /** … … 4507 4561 * @param array $args { 4508 4562 * An array of callable erasers of personal data. Default empty array. 4509 * [ 4510 * callback string Callable eraser that accepts an email address and 4511 * a page and returns an array with the number of items 4512 * removed, the number of items retained and any messages 4513 * from the eraser, as well as if additional pages are 4514 * available. 4515 * eraser_friendly_name string Translated user facing friendly name for the eraser. 4516 * ] 4563 * @type array { 4564 * Array of personal data exporters. 4565 * 4566 * @type string $callback Callable eraser that accepts an email address and 4567 * a page and returns an array with the number of items 4568 * removed, the number of items retained and any messages 4569 * from the eraser, as well as if additional pages are 4570 * available. 4571 * @type string $exporter_friendly_name Translated user facing friendly name for the eraser. 4572 * } 4517 4573 * } 4518 4574 */ … … 4521 4577 // Do we have any registered erasers? 4522 4578 if ( 0 < count( $erasers ) ) { 4579 4523 4580 if ( $eraser_index < 1 ) { 4524 wp_send_json_error( __( 'Er ror: Eraser index cannot be less than one.' ) );4581 wp_send_json_error( __( 'Eraser index cannot be less than one.' ) ); 4525 4582 } 4526 4583 4527 4584 if ( $eraser_index > count( $erasers ) ) { 4528 wp_send_json_error( __( 'Er ror: Eraser index is out of range.' ) );4585 wp_send_json_error( __( 'Eraser index is out of range.' ) ); 4529 4586 } 4530 4587 4531 4588 if ( $page < 1 ) { 4532 wp_send_json_error( __( ' Error:Page index cannot be less than one.' ) );4533 } 4534 4535 $index = $eraser_index - 1; // Convert to zero based for eraser index4589 wp_send_json_error( __( 'Page index cannot be less than one.' ) ); 4590 } 4591 4592 $index = $eraser_index - 1; // Convert to zero based for eraser index. 4536 4593 $eraser = $erasers[ $index ]; 4594 4537 4595 if ( ! is_array( $eraser ) ) { 4596 /* translators: %d: array index */ 4597 wp_send_json_error( sprintf( __( 'Expected an array describing the eraser at index %d.' ), $eraser_index ) ); 4598 } 4599 4600 if ( ! array_key_exists( 'callback', $eraser ) ) { 4601 /* translators: %d: array index */ 4602 wp_send_json_error( sprintf( __( 'Eraser array at index %d does not include a callback.' ), $eraser_index ) ); 4603 } 4604 4605 if ( ! is_callable( $eraser['callback'] ) ) { 4606 /* translators: %d: array index */ 4607 wp_send_json_error( sprintf( __( 'Eraser callback at index %d is not a valid callback.' ), $eraser_index ) ); 4608 } 4609 4610 if ( ! array_key_exists( 'eraser_friendly_name', $eraser ) ) { 4611 /* translators: %d: array index */ 4612 wp_send_json_error( sprintf( __( 'Eraser array at index %d does not include a friendly name.' ), $eraser_index ) ); 4613 } 4614 4615 $callback = $erasers[ $index ]['callback']; 4616 $eraser_friendly_name = $erasers[ $index ]['eraser_friendly_name']; 4617 4618 $response = call_user_func( $callback, $email_address, $page ); 4619 4620 if ( is_wp_error( $response ) ) { 4621 wp_send_json_error( $response ); 4622 } 4623 4624 if ( ! is_array( $response ) ) { 4538 4625 wp_send_json_error( 4539 4626 sprintf( 4540 __( 'Error: Expected an array describing the eraser at index %d.' ), 4627 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4628 __( 'Did not receive array from %1$s eraser (index %2$d).' ), 4629 esc_html( $eraser_friendly_name ), 4541 4630 $eraser_index 4542 4631 ) 4543 4632 ); 4544 4633 } 4545 if ( ! array_key_exists( 'callback', $eraser ) ) { 4634 4635 if ( ! array_key_exists( 'num_items_removed', $response ) ) { 4546 4636 wp_send_json_error( 4547 4637 sprintf( 4548 __( 'Error: Eraser array at index %d does not include a callback.' ), 4638 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4639 __( 'Expected num_items_removed key in response array from %1$s eraser (index %2$d).' ), 4640 esc_html( $eraser_friendly_name ), 4549 4641 $eraser_index 4550 4642 ) 4551 4643 ); 4552 4644 } 4553 if ( ! is_callable( $eraser['callback'] ) ) { 4645 4646 if ( ! array_key_exists( 'num_items_retained', $response ) ) { 4554 4647 wp_send_json_error( 4555 4648 sprintf( 4556 __( 'Error: Eraser callback at index %d is not a valid callback.' ), 4649 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4650 __( 'Expected num_items_retained key in response array from %1$s eraser (index %2$d).' ), 4651 esc_html( $eraser_friendly_name ), 4557 4652 $eraser_index 4558 4653 ) 4559 4654 ); 4560 4655 } 4561 if ( ! array_key_exists( 'eraser_friendly_name', $eraser ) ) { 4656 4657 if ( ! array_key_exists( 'messages', $response ) ) { 4562 4658 wp_send_json_error( 4563 4659 sprintf( 4564 __( 'Error: Eraser array at index %d does not include a friendly name.' ), 4660 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4661 __( 'Expected messages key in response array from %1$s eraser (index %2$d).' ), 4662 esc_html( $eraser_friendly_name ), 4565 4663 $eraser_index 4566 4664 ) … … 4568 4666 } 4569 4667 4570 $callback = $erasers[ $index ]['callback']; 4571 $eraser_friendly_name = $erasers[ $index ]['eraser_friendly_name']; 4572 4573 $response = call_user_func( $callback, $email_address, $page ); 4574 if ( is_wp_error( $response ) ) { 4575 wp_send_json_error( $response ); 4576 } 4577 4578 if ( ! is_array( $response ) ) { 4668 if ( ! is_array( $response['messages'] ) ) { 4579 4669 wp_send_json_error( 4580 4670 sprintf( 4581 __( 'Error: Did not receive array from %s eraser (index %d).' ), 4582 $eraser_friendly_name, 4671 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4672 __( 'Expected messages key to reference an array in response array from %1$s eraser (index %2$d).' ), 4673 esc_html( $eraser_friendly_name ), 4583 4674 $eraser_index 4584 4675 ) 4585 4676 ); 4586 4677 } 4587 if ( ! array_key_exists( 'num_items_removed', $response ) ) { 4678 4679 if ( ! array_key_exists( 'done', $response ) ) { 4588 4680 wp_send_json_error( 4589 4681 sprintf( 4590 __( 'Error: Expected num_items_removed key in response array from %s eraser (index %d).' ), 4591 $eraser_friendly_name, 4682 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4683 __( 'Expected done flag in response array from %1$s eraser (index %2$d).' ), 4684 esc_html( $eraser_friendly_name ), 4592 4685 $eraser_index 4593 4686 ) 4594 4687 ); 4595 4688 } 4596 if ( ! array_key_exists( 'num_items_retained', $response ) ) {4597 wp_send_json_error(4598 sprintf(4599 __( 'Error: Expected num_items_retained key in response array from %s eraser (index %d).' ),4600 $eraser_friendly_name,4601 $eraser_index4602 )4603 );4604 }4605 if ( ! array_key_exists( 'messages', $response ) ) {4606 wp_send_json_error(4607 sprintf(4608 __( 'Error: Expected messages key in response array from %s eraser (index %d).' ),4609 $eraser_friendly_name,4610 $eraser_index4611 )4612 );4613 }4614 if ( ! is_array( $response['messages'] ) ) {4615 wp_send_json_error(4616 sprintf(4617 __( 'Error: Expected messages key to reference an array in response array from %s eraser (index %d).' ),4618 $eraser_friendly_name,4619 $eraser_index4620 )4621 );4622 }4623 if ( ! array_key_exists( 'done', $response ) ) {4624 wp_send_json_error(4625 sprintf(4626 __( 'Error: Expected done flag in response array from %s eraser (index %d).' ),4627 $eraser_friendly_name,4628 $eraser_index4629 )4630 );4631 }4632 4689 } else { 4633 // No erasers, so we're done 4690 // No erasers, so we're done. 4634 4691 $response = array( 4635 'num_items_removed' => 0,4692 'num_items_removed' => 0, 4636 4693 'num_items_retained' => 0, 4637 'messages' => array(),4638 'done' => true,4694 'messages' => array(), 4695 'done' => true, 4639 4696 ); 4640 4697 } … … 4650 4707 * @param int $exporter_index The index of the exporter that provided this data. 4651 4708 * @param string $email_address The email address associated with this personal data. 4652 * @param int $page The zero-basedpage for this response.4709 * @param int $page The page for this response. 4653 4710 * @param int $request_id The privacy request post ID associated with this request. 4654 4711 */ 4655 4712 $response = apply_filters( 'wp_privacy_personal_data_erasure_page', $response, $eraser_index, $email_address, $page, $request_id ); 4713 4656 4714 if ( is_wp_error( $response ) ) { 4657 4715 wp_send_json_error( $response );
Note: See TracChangeset
for help on using the changeset viewer.