From a58a2e7ca4700d3e23341fde767060a4c2c704a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 30 Aug 2026 21:04:37 +0000
Subject: [PATCH] =Minor tweaks to MenuBlock.php
---
inc/integrations/Requests.php | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/inc/integrations/Requests.php b/inc/integrations/Requests.php
index ad9ebfc..da6fd17 100644
--- a/inc/integrations/Requests.php
+++ b/inc/integrations/Requests.php
@@ -1,18 +1,20 @@
<?php
namespace JVBase\integrations;
+use WP_Error;
+
if (!defined('ABSPATH')) {
exit;
}
trait Requests
{
- protected bool $hasRequests = true;
/**
* Child classes must set this (e.g. 'https://api.example.com/v1/')
*/
protected ?string $baseUrl = null;
protected int $ttl = 300; //5 minutes default
+ protected ?RateLimits $requestLimiter = null;
/**
* Child classes define their auth headers (Bearer token, API key, etc.)
@@ -23,7 +25,16 @@
* Child classes inspect the wp_remote_request response,
* decode it, and handle/log errors as needed
*/
- abstract protected function handleResponse(array|\WP_Error $response, string $method, string $endpoint): array;
+ abstract protected function handleResponse(array|WP_Error $response, string $method, string $endpoint): array;
+
+ protected function initializeRequestLimiter():void
+ {
+ $key = $this->service_name;
+ if (!is_null($this->userID)) {
+ $key .= '_'.$this->userID;
+ }
+ $this->requestLimiter = new RateLimits($key);
+ }
public function getRequest(string $endpoint, array $data = [], bool $force = false, ?int $ttl = null): array
{
@@ -66,7 +77,7 @@
return [];
}
if ($this->requestLimiter && !$this->awaitRateLimit($endpoint)) {
- $error = new \WP_Error('rate_limit_exceeded', "Rate limit exceeded for {$endpoint}");
+ $error = new WP_Error('rate_limit_exceeded', "Rate limit exceeded for {$endpoint}");
return $this->handleResponse($error, $method, $endpoint);
}
--
Gitblit v1.10.0