Search by

brianhenryie / bh-wp-rate-limiter

BrianHenryIE

Rate limiter using WordPress cache for storage.

Package info

github.com/BrianHenryIE/bh-wp-rate-limiter

Type:wordpress-library

pkg:composer/brianhenryie/bh-wp-rate-limiter

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-11-16 00:54 UTC

This package is auto-updated.

Last update: 2026-11-16 01:06:38 UTC


README

A rate limiter for WordPress, built on nikolaposa/rate-limit. It stores counts in WordPress transients, so an object cache plugin takes over the storage when one is installed. The transients are accessed through wp-oop/transient-cache.

Install

composer require wp-oop/transient-cache:@alpha brianhenryie/bh-wp-rate-limiter

You need wp-oop/transient-cache:@alpha because that package has only alpha releases. Composer ignores stability flags set inside dependencies, so your project has to allow alpha itself.

Usage

use BrianHenryIE\WP_Rate_Limiter\WordPress_Rate_Limiter;
use RateLimit\Exception\LimitExceeded;
use RateLimit\Rate;

$rate_limiter = new WordPress_Rate_Limiter( Rate::perMinute( 5 ), 'my-plugin' );

try {
	$rate_limiter->limit( $ip_address );
} catch ( LimitExceeded $e ) {
	// Too many requests.
}

If you'd rather check the status than catch an exception, use limitSilently(). It returns a RateLimit\Status.

Any of the characters {}()/\@: in a key (IPv6 addresses, for example) are replaced with -, because wp-oop/transient-cache reserves them.

For more, see the nikolaposa/rate-limit documentation.