wp_validate_user_request_key( string $request_id, string $key ): true|WP_Error

In this article

Validates a user request by comparing the key with the request’s key.

Parameters

$request_idstringrequired
ID of the request being confirmed.
$keystringrequired
Provided key to validate.

Return

true|WP_Error True on success, WP_Error on failure.

Source

	 *     @type string          $description Description of the action being performed so the user knows what the email is for.
	 *     @type string          $confirm_url The link to click on to confirm the account action.
	 *     @type string          $sitename    The site name sending the mail.
	 *     @type string          $siteurl     The site URL sending the mail.
	 * }
	 */
	$headers = apply_filters( 'user_request_action_email_headers', $headers, $subject, $content, $request_id, $email_data );

	$email_sent = wp_mail( $email_data['email'], $subject, $content, $headers );

	if ( $switched_locale ) {
		restore_previous_locale();
	}

	if ( ! $email_sent ) {
		return new WP_Error( 'privacy_email_error', __( 'Unable to send personal data export confirmation email.' ) );
	}

	return true;
}

/**
 * Returns a confirmation key for a user action and stores the hashed version for future comparison.
 *
 * @since 4.9.6
 *
 * @param int $request_id Request ID.
 * @return string Confirmation key.
 */
function wp_generate_user_request_key( $request_id ) {
	// Generate something random for a confirmation key.
	$key = wp_generate_password( 20, false );

	// Save the key, hashed.
	wp_update_post(
		array(
			'ID'            => $request_id,
			'post_status'   => 'request-pending',
			'post_password' => wp_fast_hash( $key ),
		)
	);

	return $key;
}

Changelog

VersionDescription
4.9.6Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.