PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / -3.0.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v-3.0.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 2.10.2 All 137 releases
bit-form / includes / Plugin.php

Plugin.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder -3.0.1, at includes/Plugin.php

187 lines 4.4 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;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8
9 /**
10 * Main class for the plugin.
11 *
12 * @since 1.0.0-alpha
13 */
14
15 use BitCode\BitForm\Core\Database\DB;
16 use BitCode\BitForm\Core\Database\FormModel;
17 use BitCode\BitForm\Core\Fallback\FormFallback;
18 use BitCode\BitForm\Core\Hooks\Hooks;
19 use BitCode\BitForm\Core\Util\Activation;
20 use BitCode\BitForm\Core\Util\Deactivation;
21 use BitCode\BitForm\Core\Util\Uninstallation;
22 use BitCode\BitForm\Widgets\RegisterBitFormElementorWidget;
23
24 final class Plugin
25 {
26 /**
27 * Main instance of the plugin.
28 *
29 * @since 1.0.0-alpha
30 * @var Plugin|null
31 */
32 private static $instance = null;
33
34 /**
35 * Registers the plugin with WordPress.
36 *
37 * @since 1.0.0-alpha
38 */
39 public function register()
40 {
41 add_action('plugins_loaded', [$this, 'init_plugin']);
42 // add_action('init', [$this, 'localization_setup']);
43 (new Activation())->activate();
44 (new Deactivation())->register();
45 (new Uninstallation())->register();
46 }
47
48 private function commaReplace($options, $lbl, $val)
49 {
50 foreach ($options as $key => $option) {
51 if (!empty($option[$lbl]) && !empty($option[$val])) {
52 $options[$key][$val] = str_replace(',', '_', $option[$val]);
53 }
54 if (!empty($option[$lbl]) && empty($option[$val])) {
55 $options[$key][$val] = str_replace(',', '_', $option[$lbl]);
56 }
57 }
58 return $options;
59 }
60
61 private function replaceOptionSeparator($formContent)
62 {
63 $updated = false;
64 foreach ($formContent['fields'] as $key => $field) {
65 if ('check' === $field['typ']) {
66 $formContent['fields'][$key]['opt'] = $this->commaReplace($field['opt'], 'lbl', 'val');
67 $updated = true;
68 }
69 if ('select' === $field['typ']) {
70 $formContent['fields'][$key]['opt'] = $this->commaReplace($field['opt'], 'label', 'value');
71 $updated = true;
72 }
73 }
74 return [$formContent, $updated];
75 }
76
77 public function optionFallBack()
78 {
79 $formModel = new FormModel();
80 $forms = $formModel->get(
81 ['id', 'form_content']
82 );
83
84 foreach ($forms as $form) {
85 $formContent = json_decode($form->form_content, true);
86 $optReplaceComma = $this->replaceOptionSeparator($formContent);
87 if ($optReplaceComma[1]) {
88 $formModel->update(
89 [
90 'form_content' => wp_json_encode($optReplaceComma[0]),
91 ],
92 [
93 'id' => $form->id,
94 ]
95 );
96 }
97 }
98 }
99
100 /**
101 * Updates bit form content tables on wp db
102 *
103 * @return void
104 */
105 public function update_tables()
106 {
107 if (!current_user_can('manage_options')) {
108 return;
109 }
110
111 global $bitforms_db_version;
112 $installed_db_version = get_option('bitforms_db_version');
113 if ($installed_db_version !== $bitforms_db_version) {
114 DB::migrate();
115 }
116 }
117
118 /**
119 * Plugin action links
120 *
121 * @param array $links
122 *
123 * @return array
124 */
125 public function init_plugin()
126 {
127 $this->update_tables();
128 $currentBitFormVersion = BITFORMS_VERSION;
129 $installedBitFormVersion = get_option('bitforms_version');
130 if ($currentBitFormVersion !== $installedBitFormVersion) {
131 (new FormFallback())->resetJsGeneratedPageIds();
132 }
133 Hooks::init_hooks();
134 $this->initWidgets();
135 do_action('bitform_loaded');
136 }
137
138 /**
139 * Retrieves the main instance of the plugin.
140 *
141 * @since 1.0.0-alpha
142 *
143 * @return BITFORM Plugin main instance.
144 */
145 public static function instance()
146 {
147 return static::$instance;
148 }
149
150 public function plugin_action_links($links)
151 {
152 $links[] = '<a href="https://bitapps.pro/docs/bit-form/" target="_blank">' . __('Docs', 'bit-form') . '</a>';
153
154 return $links;
155 }
156
157 /**
158 * Loads the plugin main instance and initializes it.
159 *
160 * @param string $main_file Absolute path to the plugin main file.
161 *
162 * @return bool True if the plugin main instance could be loaded, false otherwise.
163 */
164 public static function load($main_file)
165 {
166 if (null !== static::$instance) {
167 return false;
168 }
169
170 static::$instance = new static($main_file);
171 static::$instance->register();
172 return true;
173 }
174
175 private function initWidgets()
176 {
177 if (defined('ELEMENTOR_VERSION')) {
178 new RegisterBitFormElementorWidget();
179 }
180 }
181
182 // public function localization_setup()
183 // {
184 // // load_plugin_textdomain('bit-form', false, dirname(BITFORMS_PLUGIN_BASENAME) . '/languages');
185 // }
186 }
187