Automattic\WooCommerce\Internal\StockNotifications\Frontend

SignupRateLimiter::get_options │ private static │ WC 1.0

Get the rate limiting options, with the filter applied and every value coerced to its type.

Method of the class: SignupRateLimiter{}

Returns

array{enabled: bool, proxy_support: bool, client_delay: int, email_delay: int}.

Usage

$result = SignupRateLimiter::get_options(): array;

SignupRateLimiter::get_options() code WC 11.2.1

private static function get_options(): array {
	$defaults = array(
		'enabled'       => self::ENABLED,
		'proxy_support' => self::PROXY_SUPPORT,
		'client_delay'  => (int) self::CLIENT_DELAY,
		'email_delay'   => (int) self::EMAIL_DELAY,
	);

	/**
	 * Filter: woocommerce_customer_stock_notifications_signup_rate_limit_options
	 *
	 * Options for rate limiting stock notification sign-ups. Mirrors the shape of
	 * `woocommerce_store_api_rate_limit_options`.
	 *
	 * - `enabled`: switches the limiter off entirely. Default true.
	 * - `proxy_support`: read the client address from forwarding headers (X-Real-IP,
	 *   X-Forwarded-For) rather than REMOTE_ADDR. Enable only when the store is behind a
	 *   proxy, load balancer or CDN that sets them, since the headers are otherwise
	 *   spoofable. Default false.
	 * - `client_delay`: seconds a client (the logged-in user, or the IP address for
	 *   guests) has to wait between two sign-up attempts. 0 switches this limit off.
	 *   Default 30.
	 * - `email_delay`: seconds an e-mail address has to wait between two sign-up attempts.
	 *   0 switches this limit off. Default 30.
	 *
	 * @since 11.2.0
	 *
	 * @param array $options Rate limiting options.
	 */
	$options = apply_filters( 'woocommerce_customer_stock_notifications_signup_rate_limit_options', $defaults );

	if ( ! is_array( $options ) ) {
		$options = $defaults;
	}

	// A callback can return anything: unknown or non-numeric values fall back to the
	// default, and a negative delay would clear the limit instead of setting one, so it
	// is clamped to zero.
	return array(
		'enabled'       => self::to_bool( $options['enabled'] ?? $defaults['enabled'], $defaults['enabled'] ),
		'proxy_support' => self::to_bool( $options['proxy_support'] ?? $defaults['proxy_support'], $defaults['proxy_support'] ),
		'client_delay'  => is_numeric( $options['client_delay'] ?? null ) ? max( 0, (int) $options['client_delay'] ) : $defaults['client_delay'],
		'email_delay'   => is_numeric( $options['email_delay'] ?? null ) ? max( 0, (int) $options['email_delay'] ) : $defaults['email_delay'],
	);
}