From ba1e1ccf869b818f7a7a897264dfea05563a7796 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 07 Jun 2026 20:10:20 +0000
Subject: [PATCH] =Major overhaul of Integrations. Playing around with adding fields to post types through Registrar from an integrations' class file.

---
 inc/rest/routes/SettingsRoutes.php |   52 +++++++++++++++++++++++++---------------------------
 1 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/inc/rest/routes/SettingsRoutes.php b/inc/rest/routes/SettingsRoutes.php
index ff4faaa..b5d4926 100644
--- a/inc/rest/routes/SettingsRoutes.php
+++ b/inc/rest/routes/SettingsRoutes.php
@@ -2,10 +2,12 @@
 namespace JVBase\rest\routes;
 
 use JVBase\JVB;
-use JVBase\rest\RestRouteManager;
+use JVBase\rest\PermissionHandler;
+use JVBase\rest\Rest;
 use JVBase\managers\Cache;
-use JVBase\meta\MetaManager;
-use JVBase\meta\MetaSanitizer;
+use JVBase\meta\Meta;
+use JVBase\meta\Sanitizer;
+use JVBase\rest\Route;
 use WP_REST_Request;
 use WP_REST_Response;
 use WP_Error;
@@ -14,15 +16,15 @@
 if (!defined('ABSPATH')) {
     exit; // Exit if accessed directly
 }
-class SettingsRoutes extends RestRouteManager
+class SettingsRoutes extends Rest
 {
     protected int $count;
     public function __construct()
     {
-        $this->cache_name = 'user_settings';
+        $this->cacheName = 'user_settings';
         parent::__construct();
-        $this->action = 'dash-';
-        $this->operation_type = 'user_settings';
+//        $this->action = 'dash-';
+//        $this->operation_type = 'user_settings';
         $this->count = 1;
         add_filter(BASE.'handle_bulk_operation', [$this, 'processOperation'], 10, 3);
     }
@@ -33,12 +35,11 @@
      */
     public function registerRoutes():void
     {
-        register_rest_route($this->namespace, '/settings', [
-            [
-                'methods' => 'POST',
-                'callback' => [$this, 'saveSettings'],
-                'permission_callback' => [$this, 'checkPermission']
-            ]]);
+		Route::for('settings')
+			->post([$this, 'saveSettings'])
+			->auth(PermissionHandler::combine(['admin', ['actionNonce' => 'dash-']]))
+			->rateLimit(20)
+			->register();
     }
 
     /**
@@ -52,17 +53,14 @@
         $data = $request->get_params();
 		error_log('User: '.print_r($data['user'], true));
         error_log('Settings routes data: '.print_r($data, true));
-        $user_id = (int)$data['user'];
-        if (!$this->userCheck($user_id)) {
-            return new WP_REST_Response([
-                'success'   => false,
-                'message'   => 'Looks like you are not who you say you are. Bot?'
-            ]);
+        $user_id = absint($data['user']??0);
+        if ($user_id === 0) {
+            return $this->unauthorized();
         }
 
 
         $fields = JVB()->getFields('user');
-        $meta = new MetaSanitizer();
+        $meta = new Sanitizer();
         $add = [];
         global $types;
         foreach ($data as $name => $value) {
@@ -96,9 +94,7 @@
             ]
         );
 
-        // Return standardized response
-        return new WP_REST_Response([
-            'success' =>true,
+        return $this->success([
             'message' => 'Request received and queued',
             'status' => 'queued'
         ]);
@@ -119,9 +115,9 @@
 
 
         $user_id = $operation->user_id;
-        $meta = new MetaManager($user_id, 'user');
+        $meta = Meta::forUser($user_id);
         $results = [];
-		$tempMeta = new MetaManager(null, 'options');
+		$tempMeta = Meta::forOptions('options');
         foreach ($data as $name => $value) {
             if ($name == 'notification_preferences') {
                 return $this->saveNotificationPreferences($user_id, $value);
@@ -141,14 +137,15 @@
 
             if ($name !== 'digest_override') { // digest_override should always reset to 'off'
 				if(array_key_exists($name, JVB_OPTIONS)) {
-					$results[] = $tempMeta->updateValue($name, $value);
+					$results[] = $tempMeta->set($name, $value);
 				} else {
-					$results[] = $meta->updateValue($name, $value);
+					$results[] = $meta->set($name, $value);
 				}
 
             }
             $this->cache->flush();
         }
+
         return [
             'success'   => true,
             'result'   => $results,
@@ -163,6 +160,7 @@
      */
     protected function saveNotificationPreferences(int $user_id, array $data):array|WP_Error
     {
+		//TODO: This should be in with Notifications.php manager
         //TODO: Check what cache we are using to store user's preferences for the daily/weekly/monthly sendouts
         global $wpdb;
         $table = $wpdb->prefix . BASE . 'notification_preferences';

--
Gitblit v1.10.0