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
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
← All changes | includes/Plugin.php +157 -208 1.32.21.4 View file →
@@ -7,246 +7,195 @@
7 7 *
8 8 * @since 1.0.0-alpha
9 9 */
10 10
11 -use BitCode\BitForm\Admin\Admin_Bar;
11 +use BitCode\BitForm\BitApps\WPTelemetry\Telemetry\Telemetry;
12 +use BitCode\BitForm\BitApps\WPTelemetry\Telemetry\TelemetryConfig;
12 13 use BitCode\BitForm\Core\Database\DB;
14 +use BitCode\BitForm\Core\Database\FormModel;
15 +use BitCode\BitForm\Core\Fallback\FormFallback;
16 +use BitCode\BitForm\Core\Hooks\Hooks;
13 17 use BitCode\BitForm\Core\Util\Activation;
14 -use BitCode\BitForm\Core\Form\FormHandler;
15 -use BitCode\BitForm\Core\Ajax\AjaxService;
16 18 use BitCode\BitForm\Core\Util\Deactivation;
17 19 use BitCode\BitForm\Core\Util\Uninstallation;
18 -use BitCode\BitForm\Core\Capability\Request;
19 -use BitCode\BitForm\Core\Util\GutenBlockProvider;
20 -use BitCode\BitForm\Core\Integration\Integrations;
21 -use BitCode\BitForm\Core\Util\FileDownloadProvider;
22 -use BitCode\BitForm\Core\Fallback\FormEntryMetaChange;
23 -use BitCode\BitForm\API\Route\Routes;
20 +use BitCode\BitForm\Widgets\RegisterBitFormElementorWidget;
24 21
25 22 final class Plugin
26 23 {
24 + /**
25 + * Main instance of the plugin.
26 + *
27 + * @since 1.0.0-alpha
28 + * @var Plugin|null
29 + */
30 + private static $instance = null;
27 31
28 - /**
29 - * Main instance of the plugin.
30 - *
31 - * @since 1.0.0-alpha
32 - * @var Plugin|null
33 - */
34 - private static $instance = null;
32 + /**
33 + * Registers the plugin with WordPress.
34 + *
35 + * @since 1.0.0-alpha
36 + */
37 + public function register()
38 + {
39 + add_action('plugins_loaded', [$this, 'init_plugin']);
40 + add_action('init', [$this, 'localization_setup']);
41 + (new Activation())->activate();
42 + (new Deactivation())->register();
43 + (new Uninstallation())->register();
35 44
45 + $this->initWpTelemetry();
46 + }
36 47
37 - /**
38 - * Registers the plugin with WordPress.
39 - *
40 - * @since 1.0.0-alpha
41 - */
42 - public function register()
43 - {
44 - add_action('plugins_loaded', array($this, 'init_plugin'));
45 - (new Activation())->activate();
46 - (new Deactivation())->register();
47 - (new Uninstallation())->register();
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 + }
48 57 }
58 + return $options;
59 + }
49 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 + }
50 76
51 - /**
52 - * Initialize the hooks
53 - *
54 - * @return void
55 - */
56 - public function init_hooks()
57 - {
58 - add_action('init', array($this, 'registerBitformsPostType'));
59 - add_action('init', array($this, 'registerCustomPostType'));
60 - add_action("bitforms_exec_integrations", array(Integrations::class, 'integrationExecutionHelper'), 1, 5);
61 - // Localize our plugin
62 - add_action('init', array($this, 'localization_setup'));
77 + public function optionFallBack()
78 + {
79 + $formModel = new FormModel();
80 + $forms = $formModel->get(
81 + ['id', 'form_content']
82 + );
63 83
64 - // initialize the classes
65 - add_action('init', array($this, 'init_classes'));
66 -
67 - add_action('init', array($this, 'entryMetaKeyUpdate'));
68 -
69 - add_filter('plugin_action_links_' . plugin_basename(BITFORMS_PLUGIN_MAIN_FILE), array($this, 'plugin_action_links'));
70 - add_action('rest_api_init', [$this, 'register_api']);
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 + }
71 97 }
98 + }
72 99
73 - public function register_api()
74 - {
75 - $routes = new Routes();
76 - $routes->register_routes();
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;
77 109 }
78 110
79 - public function entryMetaKeyUpdate()
80 - {
81 - $installed = get_option('bitforms_installed');
82 - $oldversion = null;
83 - if ($installed) {
84 - $oldversion = get_option('bitforms_version');
85 - }
86 - if ($oldversion && version_compare($oldversion, BITFORMS_VERSION, '!=')) {
87 - update_option('bitforms_version', BITFORMS_VERSION);
88 - if (version_compare('1.0.4', $oldversion, '>=')) {
89 - // if version is lower or equal than 1.0.4
90 - $formEntryMetaChange = new FormEntryMetaChange();
91 - $formEntryMetaChange->changeMeta();
92 - }
93 - }
111 + global $bitforms_db_version;
112 + $installed_db_version = get_site_option('bitforms_db_version');
113 + if ($installed_db_version !== $bitforms_db_version) {
114 + DB::migrate();
94 115 }
116 + }
95 117
96 - /**
97 - * Updates bit form content tables on wp db
98 - *
99 - * @return void
100 - */
101 - public function update_tables()
102 - {
103 - if (!current_user_can('manage_options')) {
104 - return;
105 - }
106 -
107 - global $bitforms_db_version;
108 - $installed_db_version = get_site_option("bitforms_db_version");
109 - if ($installed_db_version != $bitforms_db_version) {
110 - DB::migrate();
111 - }
118 + /**
119 + * Plugin action links
120 + *
121 + * @param array $links
122 + *
123 + * @return array
124 + */
125 + public function init_plugin()
126 + {
127 + $currentBitFormVersion = BITFORMS_VERSION;
128 + $installedBitFormVersion = get_option('bitforms_version');
129 + if ($currentBitFormVersion !== $installedBitFormVersion) {
130 + (new FormFallback())->resetJsGeneratedPageIds();
112 131 }
132 + Hooks::init_hooks();
133 + $this->update_tables();
134 + $this->initWidgets();
135 + do_action('bitform_loaded');
136 + }
113 137
114 - /**
115 - * Register post type for bitforms
116 - *
117 - * @return void
118 - */
119 - public function registerBitformsPostType()
120 - {
121 - $args = array(
122 - 'label' => __('Bitform Pages', 'bitform'),
123 - 'public' => true,
124 - 'show_ui' => true,
125 - 'show_in_menu' => false,
126 - 'capability_type' => 'page',
127 - 'hierarchical' => false,
128 - 'query_var' => false,
129 - 'supports' => array('title'),
130 - 'show_in_rest' => false
131 - );
132 - register_post_type('bitforms', $args);
133 - }
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 + }
134 149
135 - public function registerCustomPostType()
136 - {
137 - flush_rewrite_rules( false );
138 - $cpts = get_option('bitform_custom_post_types');
139 - if (!empty($cpts)) {
140 - foreach ($cpts as $cpt ) {
141 - $labels = array(
142 - 'name' => _x($cpt->name, 'Post type general name', 'textdomain'),
143 - 'singular_name' => _x($cpt->singular_label, 'Post type singular name', 'textdomain'),
144 - 'menu_name' => _x($cpt->menu_name, 'Admin Menu text', 'textdomain'),
145 - );
146 - $args = array(
147 - 'labels' => $labels,
148 - 'public' => $cpt->public == 1 ? true : false,
149 - 'publicly_queryable' => $cpt->public_queryable == 1 ? true : false,
150 - 'show_ui' => $cpt->show_ui == 1 ? true : false,
151 - 'show_in_menu' => $cpt->show_in_menu == 1 ? true : false,
152 - 'query_var' => true,
153 - 'rewrite' => array('slug' => $cpt->name),
154 - 'capability_type' => 'post',
155 - 'has_archive' => true,
156 - 'hierarchical' => false,
157 - 'show_in_rest' => isset($cpt->show_in_rest) == 1 ? true : false,
158 - 'menu_icon' => $cpt->menu_icon,
159 - 'supports' => array('title','editor', 'author', 'excerpt', 'comments'),
160 - );
161 - register_post_type($cpt->name, $args);
162 - }
163 - }
164 - }
150 + public function plugin_action_links($links)
151 + {
152 + $links[] = '<a href="https://bitapps.pro/docs/bit-form/" target="_blank">' . __('Docs') . '</a>';
165 153
166 - /**
167 - * Initialize plugin for localization
168 - *
169 - * @uses load_plugin_textdomain()
170 - */
171 - public function localization_setup()
172 - {
173 - load_plugin_textdomain('bitform', false, dirname(BITFORMS_PLUGIN_BASENAME) . '/languages');
174 - }
154 + return $links;
155 + }
175 156
176 - /**
177 - * Instantiate the required classes
178 - *
179 - * @return void
180 - */
181 - public function init_classes()
182 - {
183 - if (Request::Check('admin')) {
184 - (new Admin_Bar())->register();
185 - }
186 - if (Request::Check('ajax')) {
187 - new AjaxService();
188 - }
189 - if (Request::Check('frontend')) {
190 - $formHandler = new FormHandler();
191 - $formHandler->frontend;
192 - }
193 - if (Request::isPluginPage()) {
194 - (new FileDownloadProvider())->register();
195 - }
196 - if (current_user_can('edit_posts')) {
197 - (new GutenBlockProvider())->register();
198 - }
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;
199 168 }
200 169
201 - /**
202 - * Plugin action links
203 - *
204 - * @param array $links
205 - *
206 - * @return array
207 - */
208 - public function plugin_action_links($links)
209 - {
210 - $links[] = '<a href="https://www.bitpress.pro" target="_blank">' . __('Docs', 'bitform') . '</a>';
170 + static::$instance = new static($main_file);
171 + static::$instance->register();
172 + return true;
173 + }
211 174
212 - return $links;
175 + private function initWidgets()
176 + {
177 + if (defined('ELEMENTOR_VERSION')) {
178 + new RegisterBitFormElementorWidget();
213 179 }
180 + }
214 181
182 + public function localization_setup()
183 + {
184 + load_plugin_textdomain('bit-form', false, dirname(BITFORMS_PLUGIN_BASENAME) . '/languages');
185 + }
215 186
216 - public function init_plugin()
217 - {
218 - $this->init_hooks();
219 - $this->update_tables();
220 - do_action('bitform_loaded');
221 - }
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);
222 193
223 - /**
224 - * Retrieves the main instance of the plugin.
225 - *
226 - * @since 1.0.0-alpha
227 - *
228 - * @return BITFORM Plugin main instance.
229 - */
230 - public static function instance()
231 - {
232 - return static::$instance;
233 - }
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/');
234 197
235 - /**
236 - * Loads the plugin main instance and initializes it.
237 - *
238 - * @param string $main_file Absolute path to the plugin main file.
239 - *
240 - * @return bool True if the plugin main instance could be loaded, false otherwise.
241 - */
242 - public static function load($main_file)
243 - {
244 - if (null !== static::$instance) {
245 - return false;
246 - }
247 -
248 - static::$instance = new static($main_file);
249 - static::$instance->register();
250 - return true;
251 - }
198 + Telemetry::report()->addPluginData()->init();
199 + Telemetry::feedback()->init();
200 + }
252 201 }