| | |
| | | use JVBase\meta\MetaManager; |
| | | use JVBase\managers\CloudflareTurnstile; |
| | | use Exception; |
| | | use JVBase\utility\Features; |
| | | use WP_Block; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | |
| | | 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', ''); |
| | |
| | | // 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', |
| | | ]); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | protected function renderTurnstile(): void |
| | | { |
| | | if (!jvbSiteUsesCloudflare()) { |
| | | if (!Features::hasIntegration('cloudflare')) { |
| | | return; |
| | | } |
| | | |