From 772462eeca3002a1d52508aeba485aab2b4742ad Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 03 Mar 2026 19:06:19 +0000
Subject: [PATCH] =MAJOR OVERHAUL. Likely should have made a new branch ages ago. Key changes: Registrar.php is the base for custom post types, taxonomies, and user roles. Replaces JVB_CONTENT, JVB_TAXONOMY, and JVB_USER constants, eliminates most of Features.php (except for JVB_SITE, JVB_MEMBERSHIP), and has built in sanitizing and validation via sub-classes. Also started a major overhaul of the Schema output. Created a shit ton of property traits and classes to help sanitize and ensure proper data for different schema types. Still a bunch to do, but better to be starting committing changes here on this other branch.

---
 inc/rest/routes/VoteRoutes.php |   36 +++++++++++++++---------------------
 1 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/inc/rest/routes/VoteRoutes.php b/inc/rest/routes/VoteRoutes.php
index b79ec08..7f55f1d 100644
--- a/inc/rest/routes/VoteRoutes.php
+++ b/inc/rest/routes/VoteRoutes.php
@@ -2,10 +2,10 @@
 namespace JVBase\rest\routes;
 
 use JVBase\managers\CustomTable;
+use JVBase\registrar\Registrar;
 use JVBase\rest\Response;
 use JVBase\rest\Rest;
 use JVBase\rest\Route;
-use JVBase\utility\Features;
 use WP_REST_Request;
 use WP_REST_Response;
 use WP_Error;
@@ -58,7 +58,8 @@
     public function handleVote(WP_REST_Request $request):WP_REST_Response
     {
         $content = sanitize_text_field($request->get_param('content')??'');
-		if ((!Features::forContent($content)->has('karma') && !Features::forTaxonomy($content)->has('karma') && !Features::forUser($content)->has('karma'))) {
+		$registrar = Registrar::getInstance($content);
+		if (!$registrar || !$registrar->hasFeature('karma')) {
 			return Response::validationError(['message' => __('Invalid content', 'jvb')]);
 		}
 
@@ -75,12 +76,7 @@
 
         $operation = sanitize_text_field($request->get_param('id'));
 
-		$type = match(true) {
-			array_key_exists($content, JVB_CONTENT) => 'post',
-			array_key_exists($content, JVB_TAXONOMY) => 'term',
-			array_key_exists($content, JVB_USER) => 'user',
-			default => false
-		};
+		$type = Registrar::getInstance($content)->getType()??false;
 		if (!$type) {
 			return Response::validationError(['message' => __('Invalid content type', 'jvb')]);
 		}
@@ -282,22 +278,20 @@
 
 		$votes = [];
 
-		foreach (jvbGlobalKarma() as $type => $content_types) {
-			foreach ($content_types as $content_type) {
-				$table = CustomTable::for('karma_' . $content_type);
+		foreach (Registrar::getFeatured('has_karma') as $type) {
+			$table = CustomTable::for('karma_' . $type);
 
-				// Skip if table doesn't exist
-				global $wpdb;
-				if ($wpdb->get_var("SHOW TABLES LIKE '{$table->getFullTableName()}'") != $table->getFullTableName()) {
-					continue;
-				}
+			// Skip if table doesn't exist
+			global $wpdb;
+			if ($wpdb->get_var("SHOW TABLES LIKE '{$table->getFullTableName()}'") != $table->getFullTableName()) {
+				continue;
+			}
 
-				$results = $table->where(['user_id' => $user])->getResults();
+			$results = $table->where(['user_id' => $user])->getResults();
 
-				if (!empty($results)) {
-					foreach ($results as $vote) {
-						$votes[$content_type][$vote->item_id] = $vote->vote;
-					}
+			if (!empty($results)) {
+				foreach ($results as $vote) {
+					$votes[$type][$vote->item_id] = $vote->vote;
 				}
 			}
 		}

--
Gitblit v1.10.0