From 42fa8304ddb811b0f725f245130f70c0f5e86a6c Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 04 Nov 2025 06:12:02 +0000
Subject: [PATCH] =Refactored LoginManager to be more extensible and configurable, as well as an AjaxRateLimiter
---
inc/rest/routes/TermRoutes.php | 48 ++++++++++++++++++++++++++++++++++++++----------
1 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/inc/rest/routes/TermRoutes.php b/inc/rest/routes/TermRoutes.php
index da8f52c..7526566 100644
--- a/inc/rest/routes/TermRoutes.php
+++ b/inc/rest/routes/TermRoutes.php
@@ -149,6 +149,14 @@
public function getTermDetails(WP_REST_Request $request):WP_REST_Response
{
$data = $request->get_params();
+ // Collect all taxonomies being queried
+ $taxonomies = array_keys($data);
+
+ // Check HTTP cache headers
+ $cache_check = $this->checkHeaders($request, $taxonomies);
+ if ($cache_check) {
+ return $cache_check;
+ }
$terms = [];
foreach ($data as $tax => $IDs) {
$args = [
@@ -158,9 +166,10 @@
$terms[$tax] = $this->formatTerms($args, BASE.$tax);
}
- return new WP_REST_Response([
+ $response = new WP_REST_Response([
'items' => $terms,
]);
+ return $this->addCacheHeaders($response);
}
/**
@@ -173,6 +182,14 @@
$data = $request->get_params();
$taxonomy = jvbCheckBase($data['taxonomy']);
+ error_log('Term Request Data for '.$taxonomy.': '.print_r($data, true));
+ // Check HTTP cache headers
+ $cache_check = $this->checkHeaders($request, $taxonomy);
+ if ($cache_check) {
+ error_log('Header Check failed');
+ return $cache_check;
+ }
+
if (array_key_exists('termIDs', $data)) {
$args = [
'taxonomy' => $taxonomy,
@@ -182,7 +199,8 @@
$key = $this->cache->generateKey($args);
$cached = $this->cache->get($key);
if ($cached) {
- return new WP_REST_Response($cached);
+ $response = new WP_REST_Response($cached);
+ return $this->addCacheHeaders($response);
}
$formatted = $this->formatTerms($args, $taxonomy);
@@ -190,14 +208,16 @@
'items' => $formatted
];
$this->cache->set($key, $response);
- return new WP_REST_Response($response);
+ $response = new WP_REST_Response($response);
+ return $this->addCacheHeaders($response);
}
if (array_key_exists('content', $data)) {
// If content_type is provided, use the specialized endpoint
$content_type = $request->get_param('content');
global $feed_types;
if (taxIsJVBContentTax($content_type)) {
- return $this->getTermsForContentType($request);
+ $response = $this->getTermsForContentType($request);
+ return $this->addCacheHeaders($response);
}
}
@@ -225,7 +245,9 @@
// If searching, handle differently
if (!empty($search)) {
- return $this->handleTermSearch($request);
+ error_log('Handling search...');
+ $response = $this->handleTermSearch($request);
+ return $this->addCacheHeaders($response);
}
// Get terms for current level with child count
@@ -248,7 +270,7 @@
$related = $manager->getUserTermIDs($userID, $taxonomy);
if (empty($related)) {
- return new WP_REST_Response([
+ $response = new WP_REST_Response([
'items' => [],
'pagination' => [
'page' => 1,
@@ -258,6 +280,7 @@
'has_more' => false
]
]);
+ return $this->addCacheHeaders($response);
}
$args['include'] = $related;
@@ -270,7 +293,7 @@
$related = $manager->getRelatedTerms($ID, BASE.$request->get_param('taxonomy'));
if (empty($related)) {
- return new WP_REST_Response([
+ $response = new WP_REST_Response([
'items' => [],
'pagination' => [
'page' => 1,
@@ -280,6 +303,7 @@
'has_more' => false
]
]);
+ return $this->addCacheHeaders($response);
}
$args['tax_query'] = [
'taxonomy' => $taxonomy,
@@ -328,7 +352,7 @@
$args['include'] = $related_term_ids;
} else {
// No related terms found, return empty result
- return new WP_REST_Response([
+ $response = new WP_REST_Response([
'items' => [],
'pagination' => [
'page' => 1,
@@ -338,6 +362,8 @@
'has_more' => false
]
]);
+
+ return $this->addCacheHeaders($response);
}
}
@@ -347,7 +373,8 @@
$cache = $this->cache->get($key);
$cache = false;
if ($cache) {
- return $cache;
+ $response = new WP_ReST_Response($cache);
+ return $this->addCacheHeaders($response);
}
$formatted_terms = $this->formatTerms($args, $taxonomy);
@@ -375,7 +402,8 @@
];
$this->cache->set($key, $response);
- return new WP_REST_Response($response);
+ $response = new WP_REST_Response($response);
+ return $this->addCacheHeaders($response);
}
/**
--
Gitblit v1.10.0