Automattic\WooCommerce\Internal\CustomerEmailVerification

EmailVerificationService::mark_verified │ public │ WC 11.0.0

Mark the given user as having verified the expected account email address.

Stores the verified email address, clears any pending key, and fires the woocommerce_customer_email_verified action. No-ops if the user is already verified for their current email. The expected email must still match the account email, preventing a concurrently changed address from being marked as verified.

Method of the class: EmailVerificationService{}

Hooks from the method

Returns

void. Nothing (null).

Usage

$EmailVerificationService = new EmailVerificationService();
$EmailVerificationService->mark_verified( $user_id, ?string $expected_email ): void;
$user_id(int) (required)
WordPress user ID.
?string $expected_email
.
Default: null

Changelog

Since 11.0.0 Introduced.

EmailVerificationService::mark_verified() code WC 11.3.0

public function mark_verified( int $user_id, ?string $expected_email = null ): void {
	if ( $this->is_verified( $user_id ) ) {
		return;
	}

	if ( null === $expected_email ) {
		wc_doing_it_wrong(
			__METHOD__,
			'Verification was skipped because no expected email was provided. Pass the email address proven by the verification flow as the second argument.',
			'11.3.0'
		);
		return;
	}

	$account_email  = $this->get_account_email( $user_id );
	$expected_email = strtolower( $expected_email );

	if ( null === $account_email || $expected_email !== $account_email ) {
		return;
	}

	// Storing the email (not a bool) lets the status self-invalidate if the account email later changes.
	Users::update_site_user_meta( $user_id, self::VERIFIED_META, $account_email );
	Users::delete_site_user_meta( $user_id, self::KEY_META );

	/**
	 * Fires after a customer has verified their email address.
	 *
	 * @param int $user_id The WordPress user ID of the verified customer.
	 *
	 * @since 11.0.0
	 */
	do_action( 'woocommerce_customer_email_verified', $user_id );
}