PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.1.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.1.0
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 2.10.2 All 137 releases
bit-form / includes / Widgets / BitformBricksWidget.php

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

140 lines 3.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 use BitCode\BitForm\GlobalHelper;
6
7 if (!defined('ABSPATH')) {
8 exit;
9 }
10
11 /**
12 * BitformBricksWidget class.
13 *
14 * @package BitCode\BitForm\Widgets
15 *
16 * @since
17 *
18 * @version
19 *
20 * @description
21 * This class is used to create a Bitform widget for Bricks Builder.
22 * It extends the \Bricks\Element class and implements the necessary methods to register the widget.
23 *
24 * @see https://academy.bricksbuilder.io/article/create-your-own-elements/
25 */
26 class BitformBricksWidget extends \Bricks\Element
27 {
28 public $category = 'general';
29 public $name = 'Bit Form';
30 public $icon = 'ti-layout-cta-left';
31
32 public $tag = 'form';
33
34 public function get_label()
35 {
36 return esc_html__('Bit Form', 'bit-form');
37 }
38
39 public function get_keywords()
40 {
41 return [
42 'bitform',
43 'bitforms',
44 'form',
45 'bitform widget',
46 'form widget',
47 'contact forms',
48 'bricks form',
49 'bit form',
50 'form builder',
51 'shortcode',
52 ];
53 }
54
55 // Set builder controls
56 public function set_controls()
57 {
58 $options = [];
59 if (is_callable([GlobalHelper::class, 'getForms'])) {
60 $forms = GlobalHelper::getForms();
61 if (is_array($forms)) {
62 $options = $forms;
63 }
64 }
65 $this->controls['form-list'] = [
66 'label' => esc_html__('Form list', 'bit-form'),
67 'type' => 'select',
68 'options' => $options,
69 'inline' => true,
70 'clearable' => false,
71 ];
72 }
73
74 public function enqueue_scripts()
75 {
76 // for custom script
77 }
78
79 private function getStyleContent($formId)
80 {
81 if (!file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')) {
82 return '';
83 }
84 $cssFile = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . "bitform-{$formId}-formid" . '.css';
85 if (!file_exists($cssFile)) {
86 return '';
87 }
88 $style = file_get_contents($cssFile);
89 return false === $style ? '' : (string) $style;
90 }
91
92 public function render()
93 {
94 $rootAttributes = (string) $this->render_attributes('_root');
95 $allowedRootHtml = [
96 'div' => [
97 'id' => true,
98 'class' => true,
99 'style' => true,
100 'data-*' => true,
101 'aria-*' => true,
102 'role' => true,
103 'tabindex' => true,
104 ],
105 ];
106 echo wp_kses('<div ' . $rootAttributes . '>', $allowedRootHtml);
107
108 if (empty($this->settings['form-list'])) {
109 echo wp_kses_post(
110 $this->render_element_placeholder([
111 'icon-class' => esc_attr($this->icon),
112 'title' => esc_html__('No form selected', 'bit-form'),
113 'description' => esc_html__('Please select a form from the Form List available in the Bit Form element settings.', 'bit-form'),
114
115 // Legacy attribute
116 'text' => esc_html__('No form selected', 'bit-form'),
117 ])
118 );
119 }
120
121 if (!empty($this->settings['form-list'])) {
122 $formId = $this->settings['form-list'];
123 $cssContent = $this->getStyleContent($formId);
124 if ('' !== $cssContent) {
125 $styleHandle = 'bitform-bricks-' . sanitize_key((string) $formId);
126 if (!wp_style_is($styleHandle, 'registered')) {
127 wp_register_style($styleHandle, false, [], BITFORMS_VERSION);
128 }
129 if (!wp_style_is($styleHandle, 'enqueued')) {
130 wp_enqueue_style($styleHandle);
131 }
132 wp_add_inline_style($styleHandle, $cssContent);
133 }
134 echo do_shortcode('[bitform id="' . esc_attr($formId) . '"]');
135 }
136
137 echo '</div>';
138 }
139 }
140