API Rate Limiting Strategies for WordPress

If your WordPress site exposes REST API endpoints — especially form submission endpoints — rate limiting is not optional. Without it, a single script can flood your server with thousands of requests per second.
The Transient Approach
For simple rate limiting without external dependencies, WordPress transients work well:
function check_rate_limit(string $prefix, int $max = 5, int $window = 3600): bool {
$key = $prefix . "_" . md5($_SERVER["REMOTE_ADDR"] ?? "unknown");
$count = (int) get_transient($key);
if ($count >= $max) {
return false; // Rate limited
}
set_transient($key, $count + 1, $window);
return true; // Allowed
}
This allows 5 requests per hour per IP address. Simple, effective, and works on any WordPress host.
Server-Level Rate Limiting
For high-traffic sites, rate limiting should happen at the web server level before PHP even starts:
# Nginx rate limiting
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
location /wp-json/ {
limit_req zone=api burst=20 nodelay;
# ... existing config
}
This is more efficient than PHP-based limiting because Nginx handles it before any PHP processing occurs.
Layered Defense
I use both approaches: Nginx rate limiting for general API protection and PHP transients for stricter limits on sensitive endpoints like form submissions and authentication. The combination handles both automated attacks and abuse without affecting normal users.
Written by
Adrian Saycon
A developer with a passion for emerging technologies, Adrian Saycon focuses on transforming the latest tech trends into great, functional products.
Discussion (0)
Sign in to join the discussion
No comments yet. Be the first to share your thoughts.
Related Articles

Building and Deploying Full-Stack Apps with AI Assistance
A weekend project walkthrough: building a full-stack task manager from architecture planning to deployment, with AI as t

AI-Assisted Database Design and Query Optimization
How to use AI for schema design, index recommendations, N+1 detection, and query optimization in PostgreSQL and MySQL.

How MCP Servers Are Changing AI-Assisted Development
An introduction to Model Context Protocol (MCP) and how to set up and build MCP servers that connect AI tools to your de