From f859e64a57c624ff2daa2b21355f65a49fd4807d Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sat, 29 Aug 2026 03:09:12 +0000
Subject: [PATCH] =Some more tweaks. Mostly on the MenuBlock and adding the Meta.php to WooCommerce Products

---
 inc/managers/CustomTable.php |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/inc/managers/CustomTable.php b/inc/managers/CustomTable.php
index 0f22ad2..d86a631 100644
--- a/inc/managers/CustomTable.php
+++ b/inc/managers/CustomTable.php
@@ -24,6 +24,7 @@
 	private static ?wpdb $wpdb = null;
 	private static string $prefix;
 	protected string $tableName;
+	protected bool $table_exists = false;
 	protected string $definition;
 	protected string $fullTableName;
 	protected bool $useTransactions;
@@ -59,11 +60,16 @@
 	{
 		if (!isset(self::$instances[$tableName])) {
 			self::$instances[$tableName] = new self($tableName, $user, $auth, $useTransactions);
+			self::$instances[$tableName]->setFlags();
 		}
 
 
 		return self::$instances[$tableName];
 	}
+		protected function setFlags():void
+		{
+			$this->table_exists = !is_null(self::$wpdb->get_var("SHOW TABLES LIKE '{$this->fullTableName}'"));
+		}
 
 	public static function destroyInstance(string $tableName):void
 	{
@@ -230,7 +236,7 @@
 		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
 
 		foreach (self::$instances as $instance) {
-			if (!$instance->wpdb->get_var("SHOW TABLES LIKE '{$instance->fullTableName}'")) {
+			if (!$instance->table_exists) {
 				$instance->createTable();
 			}
 		}
@@ -242,7 +248,7 @@
 			error_log('[CustomTable]No definition set for '.$this->tableName);
 			return;
 		}
-		if (self::$wpdb->get_var("SHOW TABLES LIKE '{$this->fullTableName}'")) {
+		if ($this->table_exists) {
 			return;
 		}
 		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
@@ -264,7 +270,7 @@
 			$error_msg = "SQL Error creating table {$this->tableName}: " . self::$wpdb->last_error;
 			error_log($error_msg);
 			error_log("Failed SQL Query: " . $schema);
-		} elseif (self::$wpdb->get_var("SHOW TABLES LIKE '{$this->fullTableName}'")) {
+		} else {
 			error_log("Successfully created table: {$this->fullTableName}");
 		}
 	}

--
Gitblit v1.10.0