WP_ERASE_PERSONAL_USER_DATA::erase_user_personal_data( $user_id,  $action_data,  $recipe_id,  $args )

Validation function when the action is hit


Parameters Parameters

$user_id

(Required)

$action_data

(Required)

$recipe_id

(Required)

$args

(Required)


Source Source

File: src/integrations/wp/actions/wp-erase-personal-user-data.php

	public function erase_user_personal_data( $user_id, $action_data, $recipe_id, $args ) {

		$flag     = Automator()->parse->text( $action_data['meta'][ $this->action_meta . '_flag' ], $recipe_id, $user_id, $args );
		$user     = Automator()->parse->text( $action_data['meta'][ $this->action_meta . '_user' ], $recipe_id, $user_id, $args );
		$the_user = get_user_by( 'email', $user );
		if ( ! $the_user instanceof \WP_User ) {
			// translators: Email
			$message                             = sprintf( __( 'Unable to find a user with the provided email (%s).', 'uncanny-automator' ), $user );
			$action_data['complete_with_errors'] = true;
			Automator()->complete->action( $user_id, $action_data, $recipe_id, $message );

			return;
		}

		$request_id = wp_create_user_request( $the_user->user_email, 'remove_personal_data' );

		if ( is_object( $request_id ) ) {
			$action_data['complete_with_errors'] = true;
			Automator()->complete->action( $user_id, $action_data, $recipe_id, $request_id->get_error_message() );

			return;
		}

		if ( ! $request_id ) {
			$message                             = __( 'Unable to initiate confirmation request.', 'uncanny-automator' );
			$action_data['complete_with_errors'] = true;
			Automator()->complete->action( $user_id, $action_data, $recipe_id, $message );

			return;
		}

		if ( 'true' === $flag ) {
			wp_send_user_request( $request_id );
		}
		Automator()->complete->action( $user_id, $action_data, $recipe_id );
	}