PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.16.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.16.2
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 +145 -179 1.22.16.2 View file →
@@ -7,214 +7,180 @@
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;
24 20
25 21 final class Plugin
26 22 {
23 + /**
24 + * Main instance of the plugin.
25 + *
26 + * @since 1.0.0-alpha
27 + * @var Plugin|null
28 + */
29 + private static $instance = null;
27 30
28 - /**
29 - * Main instance of the plugin.
30 - *
31 - * @since 1.0.0-alpha
32 - * @var Plugin|null
33 - */
34 - private static $instance = null;
31 + /**
32 + * Registers the plugin with WordPress.
33 + *
34 + * @since 1.0.0-alpha
35 + */
36 + public function register()
37 + {
38 + add_action('plugins_loaded', [$this, 'init_plugin']);
39 + (new Activation())->activate();
40 + (new Deactivation())->register();
41 + (new Uninstallation())->register();
35 42
43 + $this->initWpTelemetry();
44 + }
36 45
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();
46 + private function commaReplace($options, $lbl, $val)
47 + {
48 + foreach ($options as $key => $option) {
49 + if (!empty($option[$lbl]) && !empty($option[$val])) {
50 + $options[$key][$val] = str_replace(',', '_', $option[$val]);
51 + }
52 + if (!empty($option[$lbl]) && empty($option[$val])) {
53 + $options[$key][$val] = str_replace(',', '_', $option[$lbl]);
54 + }
48 55 }
56 + return $options;
57 + }
49 58
59 + private function replaceOptionSeparator($formContent)
60 + {
61 + $updated = false;
62 + foreach ($formContent['fields'] as $key => $field) {
63 + if ('check' === $field['typ']) {
64 + $formContent['fields'][$key]['opt'] = $this->commaReplace($field['opt'], 'lbl', 'val');
65 + $updated = true;
66 + }
67 + if ('select' === $field['typ']) {
68 + $formContent['fields'][$key]['opt'] = $this->commaReplace($field['opt'], 'label', 'value');
69 + $updated = true;
70 + }
71 + }
72 + return [$formContent, $updated];
73 + }
50 74
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("bitforms_exec_integrations", array(Integrations::class, 'integrationExecutionHelper'), 1, 5);
60 - // Localize our plugin
61 - add_action('init', array($this, 'localization_setup'));
75 + public function optionFallBack()
76 + {
77 + $formModel = new FormModel();
78 + $forms = $formModel->get(
79 + ['id', 'form_content']
80 + );
62 81
63 - // initialize the classes
64 - add_action('init', array($this, 'init_classes'));
65 -
66 - add_action('init', array($this, 'entryMetaKeyUpdate'));
67 -
68 - add_filter('plugin_action_links_' . plugin_basename(BITFORMS_PLUGIN_MAIN_FILE), array($this, 'plugin_action_links'));
69 - add_action('rest_api_init', [$this, 'register_api']);
82 + foreach ($forms as $form) {
83 + $formContent = json_decode($form->form_content, true);
84 + $optReplaceComma = $this->replaceOptionSeparator($formContent);
85 + if ($optReplaceComma[1]) {
86 + $formModel->update(
87 + [
88 + 'form_content' => wp_json_encode($optReplaceComma[0]),
89 + ],
90 + [
91 + 'id' => $form->id,
92 + ]
93 + );
94 + }
70 95 }
96 + }
71 97
72 - public function register_api()
73 - {
74 - $routes = new Routes();
75 - $routes->register_routes();
98 + /**
99 + * Updates bit form content tables on wp db
100 + *
101 + * @return void
102 + */
103 + public function update_tables()
104 + {
105 + if (!current_user_can('manage_options')) {
106 + return;
76 107 }
77 108
78 - public function entryMetaKeyUpdate()
79 - {
80 - $installed = get_option('bitforms_installed');
81 - $oldversion = null;
82 - if ($installed) {
83 - $oldversion = get_option('bitforms_version');
84 - }
85 - if ($oldversion && version_compare($oldversion, BITFORMS_VERSION, '!=')) {
86 - update_option('bitforms_version', BITFORMS_VERSION);
87 - if (version_compare('1.0.4', $oldversion, '>=')) {
88 - // if version is lower or equal than 1.0.4
89 - $formEntryMetaChange = new FormEntryMetaChange();
90 - $formEntryMetaChange->changeMeta();
91 - }
92 - }
109 + global $bitforms_db_version;
110 + $installed_db_version = get_site_option('bitforms_db_version');
111 + if ($installed_db_version !== $bitforms_db_version) {
112 + DB::migrate();
93 113 }
114 + }
94 115
95 - /**
96 - * Updates bit form content tables on wp db
97 - *
98 - * @return void
99 - */
100 - public function update_tables()
101 - {
102 - if (!current_user_can('manage_options')) {
103 - return;
104 - }
105 -
106 - global $bitforms_db_version;
107 - $installed_db_version = get_site_option("bitforms_db_version");
108 - if ($installed_db_version != $bitforms_db_version) {
109 - DB::migrate();
110 - }
116 + /**
117 + * Plugin action links
118 + *
119 + * @param array $links
120 + *
121 + * @return array
122 + */
123 + public function init_plugin()
124 + {
125 + $currentBitFormVersion = BITFORMS_VERSION;
126 + $installedBitFormVersion = get_option('bitforms_version');
127 + if ($currentBitFormVersion !== $installedBitFormVersion) {
128 + (new FormFallback())->resetJsGeneratedPageIds();
111 129 }
130 + Hooks::init_hooks();
131 + $this->update_tables();
132 + do_action('bitform_loaded');
133 + }
112 134
113 - /**
114 - * Register post type for bitforms
115 - *
116 - * @return void
117 - */
118 - public function registerBitformsPostType()
119 - {
120 - $args = array(
121 - 'label' => __('Bitform Pages', 'bitform'),
122 - 'public' => true,
123 - 'show_ui' => true,
124 - 'show_in_menu' => false,
125 - 'capability_type' => 'page',
126 - 'hierarchical' => false,
127 - 'query_var' => false,
128 - 'supports' => array('title'),
129 - 'show_in_rest' => false
130 - );
131 - register_post_type('bitforms', $args);
132 - }
135 + /**
136 + * Retrieves the main instance of the plugin.
137 + *
138 + * @since 1.0.0-alpha
139 + *
140 + * @return BITFORM Plugin main instance.
141 + */
142 + public static function instance()
143 + {
144 + return static::$instance;
145 + }
133 146
134 - /**
135 - * Initialize plugin for localization
136 - *
137 - * @uses load_plugin_textdomain()
138 - */
139 - public function localization_setup()
140 - {
141 - load_plugin_textdomain('bitform', false, dirname(BITFORMS_PLUGIN_BASENAME) . '/languages');
142 - }
147 + public function plugin_action_links($links)
148 + {
149 + $links[] = '<a href="https://bitapps.pro/docs/bit-form/" target="_blank">' . __('Docs') . '</a>';
143 150
144 - /**
145 - * Instantiate the required classes
146 - *
147 - * @return void
148 - */
149 - public function init_classes()
150 - {
151 - if (Request::Check('admin')) {
152 - (new Admin_Bar())->register();
153 - }
154 - if (Request::Check('ajax')) {
155 - new AjaxService();
156 - }
157 - if (Request::Check('frontend')) {
158 - $formHandler = new FormHandler();
159 - $formHandler->frontend;
160 - }
161 - if (Request::isPluginPage()) {
162 - (new FileDownloadProvider())->register();
163 - }
164 - if (current_user_can('edit_posts')) {
165 - (new GutenBlockProvider())->register();
166 - }
167 - }
151 + return $links;
152 + }
168 153
169 - /**
170 - * Plugin action links
171 - *
172 - * @param array $links
173 - *
174 - * @return array
175 - */
176 - public function plugin_action_links($links)
177 - {
178 - $links[] = '<a href="https://www.bitpress.pro" target="_blank">' . __('Docs', 'bitform') . '</a>';
179 -
180 - return $links;
154 + /**
155 + * Loads the plugin main instance and initializes it.
156 + *
157 + * @param string $main_file Absolute path to the plugin main file.
158 + *
159 + * @return bool True if the plugin main instance could be loaded, false otherwise.
160 + */
161 + public static function load($main_file)
162 + {
163 + if (null !== static::$instance) {
164 + return false;
181 165 }
182 166
167 + static::$instance = new static($main_file);
168 + static::$instance->register();
169 + return true;
170 + }
183 171
184 - public function init_plugin()
185 - {
186 - $this->init_hooks();
187 - $this->update_tables();
188 - do_action('bitform_loaded');
189 - }
172 + private function initWpTelemetry()
173 + {
174 + TelemetryConfig::setSlug(Config::SLUG);
175 + TelemetryConfig::setTitle(Config::TITLE);
176 + TelemetryConfig::setVersion(Config::VERSION);
177 + TelemetryConfig::setPrefix(Config::VAR_PREFIX);
190 178
191 - /**
192 - * Retrieves the main instance of the plugin.
193 - *
194 - * @since 1.0.0-alpha
195 - *
196 - * @return BITFORM Plugin main instance.
197 - */
198 - public static function instance()
199 - {
200 - return static::$instance;
201 - }
179 + TelemetryConfig::setServerBaseUrl('https://wp-api.bitapps.pro/public/');
180 + TelemetryConfig::setTermsUrl('https://bitapps.pro/terms-of-service/');
181 + TelemetryConfig::setPolicyUrl('https://bitapps.pro/privacy-policy/');
202 182
203 - /**
204 - * Loads the plugin main instance and initializes it.
205 - *
206 - * @param string $main_file Absolute path to the plugin main file.
207 - *
208 - * @return bool True if the plugin main instance could be loaded, false otherwise.
209 - */
210 - public static function load($main_file)
211 - {
212 - if (null !== static::$instance) {
213 - return false;
214 - }
215 -
216 - static::$instance = new static($main_file);
217 - static::$instance->register();
218 - return true;
219 - }
183 + Telemetry::report()->addPluginData()->init();
184 + Telemetry::feedback()->init();
185 + }
220 186 }