From fff721dd185f5b97f7ae7a6e64189e55887ff590 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 05 Jul 2026 18:36:57 +0000
Subject: [PATCH] =Cleaning up the Square integration (still a bit more to do yet). Also majorly overhauled /rest/ files to ignore a rest request 'user' paramater, and rely on get_current_user_id() instead.

---
 inc/integrations/Integrations.php |   65 ++++++++------------------------
 1 files changed, 17 insertions(+), 48 deletions(-)

diff --git a/inc/integrations/Integrations.php b/inc/integrations/Integrations.php
index cb08b13..761e6a0 100644
--- a/inc/integrations/Integrations.php
+++ b/inc/integrations/Integrations.php
@@ -28,6 +28,8 @@
  */
 abstract class Integrations
 {
+	//Flag to allow for custom settings (defaults, etc) for an integration in the dashboard
+	public static bool $hasExtraOptions = false;
 	/**
 	 * Queue types
 	 * These types match with IntegrationExecutor
@@ -175,7 +177,7 @@
 	protected bool $is_healthy = true;
 	protected bool $handleWebhooks = false;
 
-	public function __construct(?int $userID = null)
+	protected function __construct(?int $userID = null)
 	{
 		$this->cacheName = $this->cacheName ?: $this->service_name;
 		$this->userID = $userID;
@@ -207,6 +209,13 @@
 		}
 
 		add_filter('jvbShouldRenderMeta', [$this, 'checkRenderField'], 10, 4);
+
+
+	}
+
+	protected function addFilters():bool
+	{
+		return is_null($this->userID);
 	}
 
 	protected function setContentTypes():void
@@ -1422,51 +1431,6 @@
 	}
 
 
-	/**
-	 * Switch user context
-	 */
-	public function switchUser(int $user_id): void
-	{
-		if ($this->userID === $user_id) {
-			return;
-		}
-
-		// Clean up current context
-		$this->cleanup();
-
-		// Switch context
-		$this->userID = $user_id;
-		$this->credentials = [];
-		$this->resetTokenRefreshFlag();  // ADD THIS LINE
-
-		$this->ensureInitialized();
-	}
-
-	public function getAsUser(int $user_id) {
-		return new $this($user_id);
-	}
-
-	/**
-	 * Clean up resources
-	 */
-	protected function cleanup(): void
-	{
-		// Clear sensitive data
-		$this->credentials = [];
-
-		// Clear request history
-		$this->request_history = [];
-	}
-
-	/**
-	 * Destructor - ensure cleanup
-	 */
-	public function __destruct()
-	{
-		$this->cleanup();
-	}
-
-
 	/***************************************************************
 		ERROR HANDLING
 	 ***************************************************************/
@@ -2716,11 +2680,16 @@
 
 	public static function title():string
 	{
-		return (new static())->getTitle();
+		return static::getInstance()->getTitle();
 	}
 	public static function icon():string
 	{
-		return (new static())->getIcon();
+		return static::getInstance()->getIcon();
+	}
+
+	public static function hasExtraOptions():bool
+	{
+		return static::getInstance()::$hasExtraOptions;
 	}
 
 	/*********************************************************************

--
Gitblit v1.10.0