From 2bb9aaaf24b794b528e3894ee9f9c42ca6d7fe93 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 01 Jan 2026 21:08:58 +0000
Subject: [PATCH] =FeedRoutes: extractTaxonomies added
---
inc/blocks/FormBlock.php | 40 ++++++++++++++++++++++++++++++----------
1 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/inc/blocks/FormBlock.php b/inc/blocks/FormBlock.php
index 369ce77..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')) {
@@ -35,8 +36,7 @@
public function __construct()
{
- $this->cache = new CacheManager('form_blocks', HOUR_IN_SECONDS);
-
+ $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,12 +47,35 @@
// 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()
{
register_block_type($this->path, [
- 'render_callback' => [$this, 'render']
+ 'render_callback' => [$this, 'render'],
+ 'style' => 'jvb-icons-forms',
]);
}
@@ -263,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);
}
/**
@@ -289,6 +312,8 @@
foreach ($form_config['fields'] as $field_name => $field_config) {
$meta->render('form', $field_name, $field_config);
}
+ $submit_text = $form_config['submit'] ?? 'Submit';
+ echo '<button type="submit" class="button primary">' . esc_html($submit_text) . '</button>';
}
}
@@ -389,7 +414,7 @@
*/
protected function renderTurnstile(): void
{
- if (!jvbSiteUsesCloudflare()) {
+ if (!Features::hasIntegration('cloudflare')) {
return;
}
@@ -435,11 +460,6 @@
];
}
- error_log('Form Localization: '.print_r([
- 'formTypes' => $form_types,
- 'availableForms' => $this->forms,
- 'nonce' => wp_create_nonce('jvbForm')
- ], true));
wp_localize_script('jvb-forms-editor-script', 'jvbFormsData', [
'formTypes' => $form_types,
'availableForms' => $this->forms,
--
Gitblit v1.10.0