WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
класс не описан

WC_Rate_Limiter{} WC 1.0

Rate limit class.

Хуков нет.

Возвращает

Null. Ничего.

Использование

$WC_Rate_Limiter = new WC_Rate_Limiter();
// use class methods

Методы

  1. storage_id( $action_id )
  2. retried_too_soon( $action_id )
  3. set_rate_limit( $action_id, $delay )

Код WC_Rate_Limiter{} WC 4.5.2

woocommerce/includes/class-wc-rate-limiter.php
<?php
class WC_Rate_Limiter {

	/**
	 * Constructs Option name from action identifier.
	 *
	 * @param string $action_id Identifier of the action.
	 * @return string
	 */
	public static function storage_id( $action_id ) {
		return 'woocommerce_rate_limit_' . $action_id;
	}

	/**
	 * Returns true if the action is not allowed to be run by the rate limiter yet, false otherwise.
	 *
	 * @param string $action_id Identifier of the action.
	 * @return bool
	 */
	public static function retried_too_soon( $action_id ) {
		$next_try_allowed_at = get_option( self::storage_id( $action_id ) );

		// No record of action running, so action is allowed to run.
		if ( false === $next_try_allowed_at ) {
			return false;
		}

		// Before the next run is allowed, retry forbidden.
		if ( time() <= $next_try_allowed_at ) {
			return true;
		}

		// After the next run is allowed, retry allowed.
		return false;
	}

	/**
	 * Sets the rate limit delay in seconds for action with identifier $id.
	 *
	 * @param string $action_id Identifier of the action.
	 * @param int    $delay Delay in seconds.
	 * @return bool True if the option setting was successful, false otherwise.
	 */
	public static function set_rate_limit( $action_id, $delay ) {
		$option_name         = self::storage_id( $action_id );
		$next_try_allowed_at = time() + $delay;
		return update_option( $option_name, $next_try_allowed_at );
	}
}