Automattic\WooCommerce\Internal\CustomerEmailVerification

EmailVerificationService::create_verification_keypublicWC 11.0.0

Generate and store a one-time email-verification key for the given user.

The plaintext key is returned for inclusion in the verification email link. The stored value is a "{timestamp}:{key_hash}:{email_hash}" triplet so the plaintext is never persisted, the key expires after {@see self::KEY_TTL}, and the email hash binds the key to the account email in effect at issuance (a key emailed to one address can never verify a different address the account is later switched to).

Method of the class: EmailVerificationService{}

No Hooks.

Returns

string. The plaintext verification key.

Usage

$EmailVerificationService = new EmailVerificationService();
$EmailVerificationService->create_verification_key( $user_id ): string;
$user_id(int) (required)
WordPress user ID.

Changelog

Since 11.0.0 Introduced.

EmailVerificationService::create_verification_key() code WC 11.0.1

public function create_verification_key( int $user_id ): string {
	$key           = wp_generate_password( self::KEY_LENGTH, false );
	$account_email = $this->get_account_email( $user_id );
	$email_hash    = null !== $account_email ? wp_fast_hash( $account_email ) : '';

	Users::update_site_user_meta( $user_id, self::KEY_META, time() . ':' . wp_fast_hash( $key ) . ':' . $email_hash );

	return $key;
}