PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / mcp-core / Support / ImportRateLimiter.php

ImportRateLimiter.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/mcp-core/Support/ImportRateLimiter.php

42 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Local, per-authenticated-user import rate limiter (FR-015).
4 *
5 * A small, self-contained seed — not the "shared infrastructure" the spec's
6 * Clarifications describe, because no such shared layer exists anywhere in
7 * this codebase yet (research.md §5, spec.md Assumptions). Isolated behind
8 * this one class so it can be swapped for real shared infrastructure later
9 * without touching any ability.
10 *
11 * @package Templately\Modules\McpCore\Support
12 */
13
14 namespace Templately\Modules\McpCore\Support;
15
16 use WP_Error;
17
18 class ImportRateLimiter {
19
20 const MAX_CALLS = 10;
21 const WINDOW_SECONDS = 60;
22
23 /**
24 * @return WP_Error|null Null if the call may proceed.
25 */
26 public static function check(): ?WP_Error {
27 $key = 'templately_mcp_import_rl_' . get_current_user_id();
28 $count = (int) get_transient( $key );
29
30 if ( $count >= self::MAX_CALLS ) {
31 return new WP_Error(
32 'rate_limited',
33 __( 'Too many import requests. Please wait a moment and try again.', 'templately' )
34 );
35 }
36
37 set_transient( $key, $count + 1, self::WINDOW_SECONDS );
38
39 return null;
40 }
41 }
42