WooCommerce Code Reference

WC_Rate_Limiter
in package

Rate limit class.

Table of Contents

CACHE_GROUP  = 'wc_rate_limit'
Cache group.
cleanup()  : mixed
Cleanup expired rate limits from the database and clear caches.
init()  : mixed
Hook in methods.
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.
get_cache_key()  : string
Gets a cache prefix.
get_cached()  : bool|int
Retrieve a cached rate limit.
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

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

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 rate limit.

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

Identifier of the action.

Return values
bool|int

set_cache()

Cache a rate limit.

protected static set_cache(string $action_id, int $expiry) : bool
Parameters
$action_id : string

Identifier of the action.

$expiry : int

Timestamp when the limit expires.

Return values
bool