From 9f86429a1252b45c95b7c62fbaa1b82de3723997 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 05 Jan 2026 18:16:07 +0000
Subject: [PATCH] =Complete TaxonomySelector.js and TaxonomyCreator.js refactor

---
 inc/blocks/FormBlock.php |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/inc/blocks/FormBlock.php b/inc/blocks/FormBlock.php
index b8f4ed9..edffbe7 100644
--- a/inc/blocks/FormBlock.php
+++ b/inc/blocks/FormBlock.php
@@ -5,6 +5,7 @@
 use JVBase\meta\MetaManager;
 use JVBase\managers\CloudflareTurnstile;
 use Exception;
+use JVBase\utility\Features;
 use WP_Block;
 
 if (!defined('ABSPATH')) {
@@ -36,7 +37,6 @@
 	public function __construct()
 	{
 		$this->cache = CacheManager::for('form_blocks', 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()
@@ -264,7 +286,7 @@
 		}
 
 		echo '<form id="' . esc_attr($form_id) . '" data-form-id="'.esc_attr($type).'" data-save="form" data-noautosave>';
-		wp_nonce_field('jvb_form_' . $type);
+//		wp_nonce_field('jvb_form_' . $type);
 	}
 
 	/**
@@ -392,7 +414,7 @@
 	 */
 	protected function renderTurnstile(): void
 	{
-		if (!jvbSiteUsesCloudflare()) {
+		if (!Features::hasIntegration('cloudflare')) {
 			return;
 		}
 

--
Gitblit v1.10.0