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