Customizing OTP Request Limits (Rate Limiter) in WP SMS

Updated on Dec 23, 2024

Filters

wp_sms_otp_rate_limit_time_interval

wp_sms_otp_rate_limit_count

By default, WP SMS allows 5 OTP requests within a 5-minute period. However, you can easily customize both the rate limit and the maximum number of OTP requests a user can make in a specific time window. This is useful for preventing abuse and controlling the number of OTP requests made by users.

You can modify these limits using the following filters:

  • wp_sms_otp_rate_limit_time_interval: Defines the time period during which OTP requests are limited. The duration should be in ISO 8601 format (e.g., PT5M for 5 minutes, PT1H for 1 hour).
  • wp_sms_otp_rate_limit_count: Specifies the maximum number of OTP requests allowed within the given time interval.

Example Usage

Let’s say you want to limit users to only 1 OTP request every 2 minutes. The following code will achieve this. Add the following hooks to the functions.php file of your active theme.

add_filter('wp_sms_otp_rate_limit_time_interval', function($interval) {
    return new DateInterval('PT2M');  // Limit OTP requests to 2-minute intervals
});

add_filter('wp_sms_otp_rate_limit_count', function($count) {
    return 1;  // Only 1 OTP request allowed within the 2-minute window
});

Get our special CHRISTMAS Offer

20% OFF on all packages

CLAIM NOW

Coupon Code: