WooCommerce Code Reference

RateLimits extends WC_Rate_Limiter
in package

RateLimits class.

Table of Contents

CACHE_GROUP  = 'store_api_rate_limit'
Cache group.
ENABLED  = false
Rate limiting enabled default value.
LIMIT  = 25
Default amount of max requests allowed for the defined timeframe.
PROXY_SUPPORT  = false
Proxy support enabled default value.
SECONDS  = 10
Default time in seconds before rate limits are reset.
cleanup()  : mixed
Cleanup expired rate limits from the database and clear caches.
get_option()  : mixed
Gets a single option through provided name.
get_options()  : object
Return options for Rate Limits, to be returned by the "woocommerce_store_api_rate_limit_options" filter.
get_rate_limit()  : object
Returns current rate limit values using cache where possible.
init()  : mixed
Hook in methods.
is_exceeded_retry_after()  : bool|int
If exceeded, seconds until reset.
retried_too_soon()  : bool
Returns true if the action is not allowed to be run by the rate limiter yet, false otherwise.
set_rate_limit()  : bool
Sets the rate limit delay in seconds for action with identifier $id.
storage_id()  : string
Constructs key name from action identifier.
update_rate_limit()  : object
Sets the rate limit delay in seconds for action with identifier $id.
get_cache_key()  : string
Gets a cache prefix.
get_cached()  : bool|object
Retrieve a cached store api rate limit.
get_rate_limit_row()  : object
Get current rate limit row from DB and normalize types. This query is not cached, and returns a new rate limit row if none exists.
set_cache()  : bool
Cache a rate limit.

Constants

Methods

cleanup()

Cleanup expired rate limits from the database and clear caches.

public static cleanup() : mixed
Return values
mixed

get_option()

Gets a single option through provided name.

public static get_option(string $option) : mixed
Parameters
$option : string

Option name.

Return values
mixed

get_options()

Return options for Rate Limits, to be returned by the "woocommerce_store_api_rate_limit_options" filter.

public static get_options() : object
Return values
objectDefault options.

get_rate_limit()

Returns current rate limit values using cache where possible.

public static get_rate_limit(string $action_id) : object
Parameters
$action_id : string

Identifier of the action.

Return values
object

is_exceeded_retry_after()

If exceeded, seconds until reset.

public static is_exceeded_retry_after(string $action_id) : bool|int
Parameters
$action_id : string

Identifier of the action.

Return values
bool|int

retried_too_soon()

Returns true if the action is not allowed to be run by the rate limiter yet, false otherwise.

public static retried_too_soon(string $action_id) : bool
Parameters
$action_id : string

Identifier of the action.

Return values
bool

set_rate_limit()

Sets the rate limit delay in seconds for action with identifier $id.

public static set_rate_limit(string $action_id, int $delay) : bool
Parameters
$action_id : string

Identifier of the action.

$delay : int

Delay in seconds.

Return values
boolTrue if the option setting was successful, false otherwise.

storage_id()

Constructs key name from action identifier.

public static storage_id(string $action_id) : string

Left in for backwards compatibility.

Parameters
$action_id : string

Identifier of the action.

Return values
string

update_rate_limit()

Sets the rate limit delay in seconds for action with identifier $id.

public static update_rate_limit(string $action_id) : object
Parameters
$action_id : string

Identifier of the action.

Return values
objectCurrent rate limits.

get_cache_key()

Gets a cache prefix.

protected static get_cache_key(string $action_id) : string
Parameters
$action_id : string

Identifier of the action.

Return values
string

get_cached()

Retrieve a cached store api rate limit.

protected static get_cached(string $action_id) : bool|object
Parameters
$action_id : string

Identifier of the action.

Return values
bool|object

get_rate_limit_row()

Get current rate limit row from DB and normalize types. This query is not cached, and returns a new rate limit row if none exists.

protected static get_rate_limit_row(string $action_id) : object
Parameters
$action_id : string

Identifier of the action.

Return values
objectObject containing reset and remaining.

set_cache()

Cache a rate limit.

protected static set_cache(string $action_id, object $current_limit) : bool
Parameters
$action_id : string

Identifier of the action.

$current_limit : object

Current limit object with expiry and retries remaining.

Return values
bool