Automattic\WooCommerce\Admin\API

MobileAppQRLogin::claim_token_with_option_keyprivateWC 1.0

Atomically claim a token using an option key.

Method of the class: MobileAppQRLogin{}

No Hooks.

Returns

true|false. True if the claim was acquired.

Usage

// private - for code of main (parent) class only
$result = $this->claim_token_with_option_key( $claim_key, $expires_at );
$claim_key(string) (required)
Option key used as the claim mutex.
$expires_at(int) (required)
Unix timestamp when the token expires.

MobileAppQRLogin::claim_token_with_option_key() code WC 11.0.1

private function claim_token_with_option_key( $claim_key, $expires_at ) {
	$claim_expires_at = max( time() + 30, (int) $expires_at );

	if ( add_option( $claim_key, (string) $claim_expires_at, '', false ) ) {
		return true;
	}

	$existing_expires_at = (int) get_option( $claim_key, 0 );
	if ( $existing_expires_at > 0 && $existing_expires_at <= time() ) {
		$this->delete_claim_if_value_matches( $claim_key, (string) $existing_expires_at );
		return add_option( $claim_key, (string) $claim_expires_at, '', false );
	}

	return false;
}