frosty-media/wp-rest-cop
Composer 安装命令:
composer require frosty-media/wp-rest-cop
包简介
A WordPress plugin for managing access to the WP REST API.
README 文档
README
Manage access to the WP REST API with rate limits and IP-based rules.
Rate Limits
Rate limits allow for configuring the number of requests a client can make within a certain interval. The default in WP Rest Cop is 60 requests per minute.
The rate limit functionality uses transients which will use persistent object cache if present.
Headers
A few headers are sent with every request so clients can keep track of their current limit:
| Header | Description |
|---|---|
X-Rate-Limit-Limit |
Requests allowed per interval. |
X-Rate-Limit-Rules |
Default rule set to client "Ip". |
X-Rate-Limit-Remaining |
Remaining requests that are allowed in the current interval. |
X-Rate-Limit-Reset |
Seconds until the limit is reset. |
If a client has reached their limit, an additional header will be sent:
| Header | Description |
|---|---|
Retry-After |
Seconds until the limit is reset. |
Clients may send a HEAD request to view their current limit without ticking the meter.
Configuring Settings
Configure the default interval & limit settings using the simple API from the main plugin instance:
<?php use FrostyMedia\WpRestCop\RestApi\Officer; /** * Set the rate limit to 1000 requests every hour. */ add_action( 'wp_rest_cop_plugin_loaded', static function(Officer $officer): void { $officer ->setInterval(HOUR_IN_SECONDS) ->setLimit(1000); });
Settings can also be configured with the built-in WP CLI commands.
Disable Rate Limiting
If you just want the IP rules functionality and want to disable the rate limits, set the interval to -1. Or, filter
the current request:
<?php use FrostyMedia\WpRestCop\RestApi\Officer; /** * Skip the rate limit throttle on current route or other conditions. */ add_filter( 'wp_rest_cop_skip_throttle', static function( bool $skip, WP_REST_Request $request, WP_REST_Server $server): bool { if ($request->get_route() === 'some/route') { $skip = true; } return $skip; }, 10, 3);
IP Rules
IP rules can be configured globally, or at the route level as a simple allowlist or blocklist.
Global Configuration
<?php use FrostyMedia\WpRestCop\RestApi\Rules\IpRulesInterface; use FrostyMedia\WpRestCop\RestApi\Officer; /** * Modify IP rules configuration via code. */ add_action( 'wp_rest_cop_rest_api_init', static function(Officer $officer, IpRulesInterface $ipRules): void { $ipRules->allow('192.168.50.4'); // Also accepts an array of IP addresses. // Or... $ipRules->deny('66.249.66.1'); // Also accepts an array of IP addresses. }, 10, 2);
When allowing an IP address, the policy is to deny any requests from IPs not in the allowlist.
The opposite is true when denying IP addresses. All IPs not in the blocklist will have access.
Global IP rules can also be configured with the built-in WP CLI commands.
Route Configuration
Routes may also be configured with their own IP rules:
<?php use FrostyMedia\WpRestCop\RestApi\Rules\IpRulesInterface; /** * Register routes. */ add_action('rest_api_init', static function (): void { register_rest_route( 'myplugin/v1', '/internal/(?P<id>\d+)', [ 'methods' => 'GET', 'callback' => 'my_awesome_expensive_func', IpRulesInterface::IPS => [ IpRulesInterface::ALLOW => ['192.168.50.4'], IpRulesInterface::DENY => ['66.249.66.1'], ], ]); });
WP CLI Commands
A few WP CLI commands are included to configure the plugin without requiring code.
| Command | Description |
|---|---|
wp restcop allow <ip> |
Allow one or more IPs. |
wp restcop check <ip> |
Check whether an IP has access. |
wp restcop deny <ip> |
Deny one or more IPs |
wp restcop set <key> <value> |
Update a setting value. |
wp restcop status |
View global IP rules. |
Potential Roadmap
- Support for logging various events.
- Additional rate limit strategies.
- More route-level capabilities.
- Advanced access rules.
frosty-media/wp-rest-cop 适用场景与选型建议
frosty-media/wp-rest-cop 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress-plugin」 「rate-limiting」 「wordpress-rest-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 frosty-media/wp-rest-cop 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 frosty-media/wp-rest-cop 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 frosty-media/wp-rest-cop 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Throttle notifications on a per-channel basis
A modular queue system featuring multiple storage drivers, scalable workers, job batching, chaining, rate limiting, events, and an intuitive CLI for managing jobs.
A flexible rate limiting middleware for Laravel and Lumen applications
A Gutenberg like color palette field for ACF.
Quickly add routes to the WordPress Rest API.
WordPress Plugin Framework
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2025-05-20
