PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
bit-form / includes / Widgets / RegisterGutenBlock.php

RegisterGutenBlock.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.3.1, at includes/Widgets/RegisterGutenBlock.php

106 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Widgets;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8
9 use BitCode\BitForm\Core\Form\FormHandler;
10
11 final class RegisterGutenBlock
12 {
13 public function register()
14 {
15 if (!function_exists('register_block_type')) {
16 return;
17 }
18
19 // self::gutenbergBlock();
20
21 add_action('enqueue_block_editor_assets', function () {
22 wp_enqueue_script(
23 'bitforms-gutenberg-block',
24 BITFORMS_ROOT_URI . '/assets/gutenberg-shortcode-block.js',
25 [],
26 BITFORMS_VERSION,
27 true
28 );
29
30 $formHandler = FormHandler::getInstance();
31 $all_forms = $formHandler->admin->getAllForm();
32 $bitformsForms = apply_filters(
33 'bitforms_localize_block_script',
34 [
35 'forms' => $all_forms
36 ]
37 );
38
39 $bitformsForms['ajaxUrl'] = admin_url('admin-ajax.php');
40 $bitformsForms['nonce'] = wp_create_nonce('bitforms_save');
41
42 wp_localize_script('bitforms-gutenberg-block', 'bitformsBlock', $bitformsForms);
43 });
44 }
45
46 public function shortcodeBlock()
47 {
48 wp_enqueue_script(
49 'bitforms-gutenberg-block',
50 BITFORMS_ROOT_URI . '/assets/gutenberg-shortcode-block.js',
51 [],
52 BITFORMS_VERSION,
53 true
54 );
55
56 $formHandler = FormHandler::getInstance();
57 $all_forms = $formHandler->admin->getAllForm();
58 $bitformsForms = apply_filters(
59 'bitforms_localize_block_script',
60 [
61 'forms' => $all_forms
62 ]
63 );
64
65 wp_localize_script('bitforms-gutenberg-block', 'bitformsBlock', $bitformsForms);
66 }
67
68 public static function gutenbergBlock()
69 {
70 // TODO: Attention: This function is temporary block.
71 // if (!function_exists('register_block_type')) {
72 // return;
73 // }
74
75 register_block_type('bitforms/form-shortcode', [
76 'render_callback' => function ($attributes, $content) {
77 $formId = $attributes['formID'] ?? '';
78 // error_log('form id' . $formId);
79 // error_log('content' . $content);
80
81 if (empty($formId)) {
82 return '';
83 }
84
85 // $formHandler = FormHandler::getInstance();
86 // $form = $formHandler->admin->getForm($formId);
87 // if (empty($form)) {
88 // return '';
89 // }
90
91 if ($content) {
92 return $content;
93 }
94 $shortCode = '[bitform id=\'' . esc_attr($formId) . '\']';
95 return do_shortcode($shortCode);
96 },
97 'attributes' => [
98 'formId' => [
99 'type' => 'string',
100 'default' => '',
101 ],
102 ],
103 ]);
104 }
105 }
106