PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.7.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.7.0
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 +128 -213 1.32.7.0 View file →
@@ -7,246 +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\Form as 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('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'));
63 -
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']);
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 + }
71 67 }
68 + return [$formContent, $updated];
69 + }
72 70
73 - public function register_api()
74 - {
75 - $routes = new Routes();
76 - $routes->register_routes();
77 - }
71 + public function optionFallBack()
72 + {
73 + $formModel = new FormModel();
74 + $forms = $formModel->get(
75 + ['id', 'form_content']
76 + );
78 77
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 - }
94 - }
95 -
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 - }
112 - }
113 -
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
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 + ]
131 89 );
132 - register_post_type('bitforms', $args);
90 + }
133 91 }
92 + }
134 93
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 - }
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;
164 103 }
165 104
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');
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();
174 109 }
110 + }
175 111
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 - }
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();
199 125 }
126 + Hooks::init_hooks();
127 + $this->update_tables();
128 + do_action('bitform_loaded');
129 + }
200 130
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>';
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 + }
211 142
212 - return $links;
213 - }
143 + public function plugin_action_links($links)
144 + {
145 + $links[] = '<a href="https://docs.form.bitapps.pro" target="_blank">' . __('Docs') . '</a>';
214 146
147 + return $links;
148 + }
215 149
216 - public function init_plugin()
217 - {
218 - $this->init_hooks();
219 - $this->update_tables();
220 - 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;
221 161 }
222 162
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 - }
234 -
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 - }
163 + static::$instance = new static($main_file);
164 + static::$instance->register();
165 + return true;
166 + }
252 167 }