DeleteDataRequest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * Class NF_Actions_DataRemoval
  4. */
  5. final class NF_Actions_DeleteDataRequest extends NF_Abstracts_Action
  6. {
  7. /**
  8. * @var string
  9. */
  10. protected $_name = 'deletedatarequest';
  11. /**
  12. * @var array
  13. */
  14. protected $_tags = array();
  15. /**
  16. * @var string
  17. */
  18. protected $_timing = 'late';
  19. /**
  20. * @var int
  21. */
  22. protected $_priority = 10;
  23. /**
  24. * Constructor
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. $this->_nicename = __( 'Delete Data Request', 'ninja-forms' );
  30. $settings = Ninja_Forms::config( 'ActionDeleteDataRequestSettings' );
  31. $this->_settings = array_merge( $this->_settings, $settings );
  32. }
  33. /*
  34. * PUBLIC METHODS
  35. */
  36. public function save( $action_settings )
  37. {
  38. }
  39. /**
  40. * Creates a Erase Personal Data request for the user with the email
  41. * provided
  42. *
  43. * @param $action_settings
  44. * @param $form_id
  45. * @param $data
  46. *
  47. * @return array
  48. */
  49. public function process( $action_settings, $form_id, $data )
  50. {
  51. $data = array();
  52. if( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){
  53. return $data;
  54. }
  55. // get the email setting
  56. $email = $action_settings[ 'email' ];
  57. // create request for user
  58. $request_id = wp_create_user_request( $email,
  59. 'remove_personal_data' );
  60. /**
  61. * Basically ignore if we get a user error as it will be one of two
  62. * things.
  63. *
  64. * 1) The email in question is already in the erase data request queue
  65. * 2) The email does not belong to an actual user.
  66. */
  67. if( ! $request_id instanceof WP_Error ) {
  68. // send the request if it's not an error.
  69. // to anonymize or not to anonymize, that is the question
  70. add_post_meta( $request_id,
  71. 'nf_anonymize_data',
  72. $action_settings[ 'anonymize' ] );
  73. wp_send_user_request( $request_id );
  74. }
  75. return $data;
  76. }
  77. }