WC_Helper_API_Backoff::get_retry_after │ public static │ WC 11.2.0

Seconds remaining in a request type's backoff window.

Lets callers align a user-facing message with the window the site is actually observing, so a rate-limit notice stays visible for exactly as long as requests are being suppressed.

Method of the class: WC_Helper_API_Backoff{}

No Hooks.

Returns

int|null. Seconds until the window expires, or null when not rate limited.

Usage

$result = WC_Helper_API_Backoff::get_retry_after( $request_type ): ?int;
$request_type(string) (required)
The Helper API request type (e.g. 'update-check').

Changelog

Since 11.2.0 Introduced.

WC_Helper_API_Backoff::get_retry_after() code WC 11.3.0

public static function get_retry_after( string $request_type ): ?int {
	$expires_at = get_transient( self::get_transient_key( $request_type ) );

	if ( ! is_numeric( $expires_at ) ) {
		return null;
	}

	$remaining = (int) $expires_at - time();

	return $remaining > 0 ? $remaining : null;
}