From b38f03c0e7218762d90fa5092696b127f24f36db Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 25 Jan 2026 07:07:26 +0000
Subject: [PATCH] =Some logical flaws in Queue.php, Queue.js, ContentExecutor.php, UploadExecutor.php - particularly with timeline ordering, frontend queue updates, etc

---
 inc/blocks/FormBlock.php |   58 +++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/inc/blocks/FormBlock.php b/inc/blocks/FormBlock.php
index b8f4ed9..3e8a892 100644
--- a/inc/blocks/FormBlock.php
+++ b/inc/blocks/FormBlock.php
@@ -1,10 +1,11 @@
 <?php
 namespace JVBase\blocks;
 
-use JVBase\managers\CacheManager;
+use JVBase\managers\Cache;
 use JVBase\meta\MetaManager;
 use JVBase\managers\CloudflareTurnstile;
 use Exception;
+use JVBase\utility\Features;
 use WP_Block;
 
 if (!defined('ABSPATH')) {
@@ -18,8 +19,8 @@
  */
 class FormBlock
 {
-	protected static FormBlock|null $instance = null;
-	protected CacheManager $cache;
+	protected static ?FormBlock $instance = null;
+	protected Cache $cache;
 	protected array $forms;
 	protected string $form_contact;
 
@@ -35,8 +36,7 @@
 
 	public function __construct()
 	{
-		$this->cache = CacheManager::for('form_blocks', WEEK_IN_SECONDS);
-
+		$this->cache = Cache::for('forms', WEEK_IN_SECONDS);
 		// Initialize forms from filter
 		$this->forms = $this->registerForms();
 		$this->form_contact = apply_filters('jvb_form_contact', '');
@@ -47,6 +47,28 @@
 		// Register forms data for the block editor
 		add_action('enqueue_block_editor_assets', [$this, 'localizeFormsData']);
 		add_action('init', [$this, 'registerBlock']);
+		add_filter('render_block', [$this, 'maybeEnqueueScripts'], 10, 2);
+	}
+
+	/**
+	 * Enqueue scripts when rendering form block
+	 */
+	public function maybeEnqueueScripts(string $block_content, array $block): string
+	{
+		// Only process our form blocks
+		if ($block['blockName'] !== 'jvb/forms') {
+			return $block_content;
+		}
+
+		// Enqueue Turnstile if needed
+		if (Features::forSite()->hasIntegration('cloudflare')) {
+			$cloudflare = JVB()->connect('cloudflare');
+			if ($cloudflare->isSetUp()) {
+				$cloudflare->enqueueTurnstileScripts();
+			}
+		}
+
+		return $block_content;
 	}
 
 	public function registerBlock()
@@ -94,9 +116,7 @@
 			'sections' => []
 		];
 
-		$config = array_merge($defaults, $config);
-
-		return $config;
+		return array_merge($defaults, $config);
 	}
 
 	/**
@@ -111,16 +131,12 @@
 		}
 
 		$cache_key = $this->cache->generateKey($block);
-		$cached = $this->cache->get($cache_key);
-		$cached = false;
-		if ($cached) {
-			return $cached;
-		}
-
-		$rendered = $this->renderForm($form_type, $block);
-
-		$this->cache->set($cache_key, $rendered);
-		return $rendered;
+		return $this->cache->remember(
+			$cache_key,
+			function() use ($form_type, $block) {
+				return $this->renderForm($form_type, $block);
+			}
+		);
 	}
 
 	/**
@@ -263,8 +279,8 @@
 			}
 		}
 
-		echo '<form id="' . esc_attr($form_id) . '" data-form-id="'.esc_attr($type).'" data-save="form" data-noautosave>';
-		wp_nonce_field('jvb_form_' . $type);
+		echo '<form id="' . esc_attr($form_id) . '" data-form-id="'.esc_attr($type).'" data-save="form">';
+//		wp_nonce_field('jvb_form_' . $type);
 	}
 
 	/**
@@ -392,7 +408,7 @@
 	 */
 	protected function renderTurnstile(): void
 	{
-		if (!jvbSiteUsesCloudflare()) {
+		if (!Features::hasIntegration('cloudflare')) {
 			return;
 		}
 

--
Gitblit v1.10.0