PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.4
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.4
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
← All changes | includes/Plugin.php +60 -29 2.02.21.4 View file →
@@ -7,17 +7,21 @@
7 7 *
8 8 * @since 1.0.0-alpha
9 9 */
10 10
11 +use BitCode\BitForm\BitApps\WPTelemetry\Telemetry\Telemetry;
12 +use BitCode\BitForm\BitApps\WPTelemetry\Telemetry\TelemetryConfig;
11 13 use BitCode\BitForm\Core\Database\DB;
12 14 use BitCode\BitForm\Core\Database\FormModel;
15 +use BitCode\BitForm\Core\Fallback\FormFallback;
13 16 use BitCode\BitForm\Core\Hooks\Hooks;
14 17 use BitCode\BitForm\Core\Util\Activation;
15 18 use BitCode\BitForm\Core\Util\Deactivation;
16 -use BitCode\BitForm\Core\Util\FrontendHelpers;
17 19 use BitCode\BitForm\Core\Util\Uninstallation;
20 +use BitCode\BitForm\Widgets\RegisterBitFormElementorWidget;
18 21
19 -final class Plugin {
22 +final class Plugin
23 +{
20 24 /**
21 25 * Main instance of the plugin.
22 26 *
23 27 * @since 1.0.0-alpha
@@ -29,34 +33,21 @@
29 33 * Registers the plugin with WordPress.
30 34 *
31 35 * @since 1.0.0-alpha
32 36 */
33 - public function register() {
37 + public function register()
38 + {
34 39 add_action('plugins_loaded', [$this, 'init_plugin']);
35 - add_action('init', [$this, 'checkIfFirstHttpRequest']);
40 + add_action('init', [$this, 'localization_setup']);
36 41 (new Activation())->activate();
37 42 (new Deactivation())->register();
38 43 (new Uninstallation())->register();
39 - }
40 44
41 - public function checkIfFirstHttpRequest() {
42 - $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
43 - $referrerQueryParams = FrontendHelpers::parseQueryParams($referrer);
44 - $pageBuilderQueryParams = FrontendHelpers::$pageBuilderList;
45 - $referrerMatchesWithPageBuilder = array_intersect_assoc($referrerQueryParams, $pageBuilderQueryParams);
46 - if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($referrer) && 0 === count($referrerMatchesWithPageBuilder)) {
47 - delete_transient('is_page_builder');
48 - delete_transient('bf_frontend_form_ids');
49 - $currentUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
50 - $currentUrlQueryParams = FrontendHelpers::parseQueryParams($currentUrl);
51 - $currentUrlMatchesWithPageBuilder = array_intersect_assoc($currentUrlQueryParams, $pageBuilderQueryParams);
52 - if (0 !== count($currentUrlMatchesWithPageBuilder)) {
53 - set_transient('is_page_builder', true);
54 - }
55 - }
45 + $this->initWpTelemetry();
56 46 }
57 47
58 - private function commaReplace($options, $lbl, $val) {
48 + private function commaReplace($options, $lbl, $val)
49 + {
59 50 foreach ($options as $key => $option) {
60 51 if (!empty($option[$lbl]) && !empty($option[$val])) {
61 52 $options[$key][$val] = str_replace(',', '_', $option[$val]);
62 53 }
@@ -66,9 +57,10 @@
66 57 }
67 58 return $options;
68 59 }
69 60
70 - private function replaceOptionSeparator($formContent) {
61 + private function replaceOptionSeparator($formContent)
62 + {
71 63 $updated = false;
72 64 foreach ($formContent['fields'] as $key => $field) {
73 65 if ('check' === $field['typ']) {
74 66 $formContent['fields'][$key]['opt'] = $this->commaReplace($field['opt'], 'lbl', 'val');
@@ -81,9 +73,10 @@
81 73 }
82 74 return [$formContent, $updated];
83 75 }
84 76
85 - public function optionFallBack() {
77 + public function optionFallBack()
78 + {
86 79 $formModel = new FormModel();
87 80 $forms = $formModel->get(
88 81 ['id', 'form_content']
89 82 );
@@ -108,9 +101,10 @@
108 101 * Updates bit form content tables on wp db
109 102 *
110 103 * @return void
111 104 */
112 - public function update_tables() {
105 + public function update_tables()
106 + {
113 107 if (!current_user_can('manage_options')) {
114 108 return;
115 109 }
116 110
@@ -127,11 +121,18 @@
127 121 * @param array $links
128 122 *
129 123 * @return array
130 124 */
131 - public function init_plugin() {
125 + public function init_plugin()
126 + {
127 + $currentBitFormVersion = BITFORMS_VERSION;
128 + $installedBitFormVersion = get_option('bitforms_version');
129 + if ($currentBitFormVersion !== $installedBitFormVersion) {
130 + (new FormFallback())->resetJsGeneratedPageIds();
131 + }
132 132 Hooks::init_hooks();
133 133 $this->update_tables();
134 + $this->initWidgets();
134 135 do_action('bitform_loaded');
135 136 }
136 137
137 138 /**
@@ -140,14 +141,16 @@
140 141 * @since 1.0.0-alpha
141 142 *
142 143 * @return BITFORM Plugin main instance.
143 144 */
144 - public static function instance() {
145 + public static function instance()
146 + {
145 147 return static::$instance;
146 148 }
147 149
148 - public function plugin_action_links($links) {
149 - $links[] = '<a href="https://docs.form.bitapps.pro" target="_blank">' . __('Docs') . '</a>';
150 + public function plugin_action_links($links)
151 + {
152 + $links[] = '<a href="https://bitapps.pro/docs/bit-form/" target="_blank">' . __('Docs') . '</a>';
150 153
151 154 return $links;
152 155 }
153 156
@@ -157,9 +160,10 @@
157 160 * @param string $main_file Absolute path to the plugin main file.
158 161 *
159 162 * @return bool True if the plugin main instance could be loaded, false otherwise.
160 163 */
161 - public static function load($main_file) {
164 + public static function load($main_file)
165 + {
162 166 if (null !== static::$instance) {
163 167 return false;
164 168 }
165 169
@@ -165,6 +169,33 @@
165 169
166 170 static::$instance = new static($main_file);
167 171 static::$instance->register();
168 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 + private function initWpTelemetry()
188 + {
189 + TelemetryConfig::setSlug(Config::SLUG);
190 + TelemetryConfig::setTitle(Config::TITLE);
191 + TelemetryConfig::setVersion(Config::VERSION);
192 + TelemetryConfig::setPrefix(Config::VAR_PREFIX);
193 +
194 + TelemetryConfig::setServerBaseUrl('https://wp-api.bitapps.pro/public/');
195 + TelemetryConfig::setTermsUrl('https://bitapps.pro/terms-of-service/');
196 + TelemetryConfig::setPolicyUrl('https://bitapps.pro/privacy-policy/');
197 +
198 + Telemetry::report()->addPluginData()->init();
199 + Telemetry::feedback()->init();
169 200 }
170 201 }