WC_Shortcode_My_Account::consume_password_reset_bridge_token │ private static │ WC 1.0

Consume a URL bridge handle and exchange it for signed form credentials.

Method of the class: WC_Shortcode_My_Account{}

No Hooks.

Returns

array{key: string, login: string}|false. Form credentials on success, false otherwise.

Usage

$result = WC_Shortcode_My_Account::consume_password_reset_bridge_token( $handle );
$handle(mixed) (required)
URL bridge handle.

WC_Shortcode_My_Account::consume_password_reset_bridge_token() code WC 11.2.2

private static function consume_password_reset_bridge_token( $handle ) {
	if ( ! self::is_password_reset_bridge_handle( $handle ) ) {
		return false;
	}

	$transient_name = self::get_password_reset_bridge_transient_name( $handle );
	$payload        = get_transient( $transient_name );

	// Only the request whose delete actually removed the row may exchange the handle.
	if ( ! delete_transient( $transient_name ) ) {
		return false;
	}

	if (
		! is_array( $payload ) ||
		! isset( $payload['user_id'], $payload['expiration'], $payload['state_signature'] ) ||
		! is_string( $payload['state_signature'] )
	) {
		return false;
	}

	$expiration = absint( $payload['expiration'] );
	$user       = self::get_eligible_password_reset_user( absint( $payload['user_id'] ), $expiration );

	if ( ! $user ) {
		return false;
	}

	if ( ! hash_equals( self::get_password_reset_state_signature( $user ), $payload['state_signature'] ) ) {
		return false;
	}

	// Old-style keys carry no timestamp and keep the bridge's short window; everything else lasts as long as the WordPress key.
	$form_expiration = self::get_password_reset_state_expiration( $user );
	if ( PHP_INT_MAX === $form_expiration ) {
		$form_expiration = $expiration;
	}

	return array(
		'key'   => self::create_password_reset_form_token( $user, $form_expiration ),
		'login' => $user->user_login,
	);
}