| Server IP : 119.59.104.26 / Your IP : 216.73.217.51 Web Server : Apache/2 System : Linux ns69.hostinglotus.net 4.18.0-553.141.2.el8_10.x86_64 #1 SMP Wed Jul 8 10:28:18 EDT 2026 x86_64 User : com12370 ( 1517) PHP Version : 7.2.34 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/com12370/public_html/wp-content/plugins/woocommerce/includes/ |
Upload File : |
<?php
/**
* Provide basic rate limiting functionality via WP Options API.
*
* Currently only provides a simple limit by delaying action by X seconds.
*
* Example usage:
*
* When an action runs, call set_rate_limit, e.g.:
*
* WC_Rate_Limiter::set_rate_limit( "{$my_action_name}_{$user_id}", $delay );
*
* This sets a timestamp for future timestamp after which action can run again.
*
*
* Then before running the action again, check if the action is allowed to run, e.g.:
*
* if ( WC_Rate_Limiter::retried_too_soon( "{$my_action_name}_{$user_id}" ) ) {
* add_notice( 'Sorry, too soon!' );
* }
*
* @package WooCommerce\Classes
* @version 3.9.0
* @since 3.9.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Rate limit class.
*/
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 );
}
}