Automattic\WooCommerce\Internal\StockNotifications\Frontend

SignupRateLimiter::apply │ public static │ WC 11.2.0

Start the rate limit windows for the current sign-up attempt.

Method of the class: SignupRateLimiter{}

No Hooks.

Returns

bool. True if every rate limit was applied.

Usage

$result = SignupRateLimiter::apply( $user_email ): bool;
$user_email(string) (required)
The e-mail address used to sign up.

Changelog

Since 11.2.0 Introduced.

SignupRateLimiter::apply() code WC 11.3.0

public static function apply( string $user_email ): bool {
	$applied_rate_limit_ids = array();

	foreach ( self::get_rate_limits( $user_email ) as $rate_limit_id => $delay ) {
		if ( ! WC_Rate_Limiter::set_rate_limit( $rate_limit_id, $delay ) ) {
			// Leave no partial window behind: a half-applied limit would block the
			// customer on an attempt that never went through. The failed limit is
			// cleared too, since set_rate_limit() caches the new expiry even when the
			// write itself fails.
			foreach ( array_merge( array( $rate_limit_id ), $applied_rate_limit_ids ) as $applied_rate_limit_id ) {
				WC_Rate_Limiter::set_rate_limit( $applied_rate_limit_id, -1 );
			}

			return false;
		}

		$applied_rate_limit_ids[] = $rate_limit_id;
	}

	return true;
}