ExportDataRequest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * Class NF_Actions_ExportPersonalData
  4. */
  5. final class NF_Actions_ExportDataRequest extends NF_Abstracts_Action
  6. {
  7. /**
  8. * @var string
  9. */
  10. protected $_name = 'exportdatarequest';
  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 = __( 'Export Data Request', 'ninja-forms' );
  30. $settings = Ninja_Forms::config( 'ActionExportDataRequestSettings' );
  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 Export 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. 'export_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. wp_send_user_request( $request_id );
  69. }
  70. return $data;
  71. }
  72. }