PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
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 +156 -174 1.1.83.3.1 View file →
@@ -1,8 +1,12 @@
1 1 <?php
2 2
3 3 namespace BitCode\BitForm;
4 4
5 +if (!defined('ABSPATH')) {
6 + exit;
7 +}
8 +
5 9 /**
6 10 * Main class for the plugin.
7 11 *
8 12 * @since 1.0.0-alpha
@@ -7,214 +11,192 @@
7 11 *
8 12 * @since 1.0.0-alpha
9 13 */
10 14
11 -use BitCode\BitForm\Admin\Admin_Bar;
12 15 use BitCode\BitForm\Core\Database\DB;
16 +use BitCode\BitForm\Core\Database\FormModel;
17 +use BitCode\BitForm\Core\Fallback\FormFallback;
18 +use BitCode\BitForm\Core\Hooks\Hooks;
13 19 use BitCode\BitForm\Core\Util\Activation;
14 -use BitCode\BitForm\Core\Form\FormHandler;
15 -use BitCode\BitForm\Core\Ajax\AjaxService;
16 20 use BitCode\BitForm\Core\Util\Deactivation;
17 21 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;
22 +use BitCode\BitForm\Widgets\RegisterBitFormElementorWidget;
24 23
25 24 final class Plugin
26 25 {
26 + /**
27 + * Main instance of the plugin.
28 + *
29 + * @since 1.0.0-alpha
30 + * @var Plugin|null
31 + */
32 + private static $instance = null;
27 33
28 - /**
29 - * Main instance of the plugin.
30 - *
31 - * @since 1.0.0-alpha
32 - * @var Plugin|null
33 - */
34 - private static $instance = null;
34 + /**
35 + * Registers the plugin with WordPress.
36 + *
37 + * @since 1.0.0-alpha
38 + */
39 + public function register()
40 + {
41 + add_action('plugins_loaded', [$this, 'init_plugin']);
42 + add_action('init', [$this, 'localization_setup']);
43 + (new Activation())->activate();
44 + (new Deactivation())->register();
45 + (new Uninstallation())->register();
46 + }
35 47
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 + }
57 + }
58 + return $options;
59 + }
36 60
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();
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 + }
48 73 }
74 + return [$formContent, $updated];
75 + }
49 76
77 + public function optionFallBack()
78 + {
79 + $formModel = new FormModel();
80 + $forms = $formModel->get(
81 + ['id', 'form_content']
82 + );
50 83
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']);
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 + }
70 97 }
98 + }
71 99
72 - public function register_api()
73 - {
74 - $routes = new Routes();
75 - $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;
76 109 }
77 110
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 - }
111 + global $bitforms_db_version;
112 + $installed_db_version = get_option('bitforms_db_version');
113 + if ($installed_db_version !== $bitforms_db_version) {
114 + DB::migrate();
93 115 }
116 + }
94 117
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 - }
118 + /**
119 + * Plugin action links
120 + *
121 + * @param array $links
122 + *
123 + * @return array
124 + */
125 + public function init_plugin()
126 + {
127 + $this->update_tables();
128 + $currentBitFormVersion = BITFORMS_VERSION;
129 + $installedBitFormVersion = get_option('bitforms_version');
130 + if ($currentBitFormVersion !== $installedBitFormVersion) {
131 + (new FormFallback())->resetJsGeneratedPageIds();
111 132 }
133 + Hooks::init_hooks();
134 + $this->initWidgets();
135 + do_action('bitform_loaded');
136 + }
112 137
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 - }
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 + }
133 149
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 - }
150 + public function plugin_action_links($links)
151 + {
152 + $links[] = '<a href="https://bitapps.pro/docs/bit-form/" target="_blank">' . __('Docs', 'bit-form') . '</a>';
143 153
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 - }
154 + return $links;
155 + }
168 156
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;
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;
181 168 }
182 169
170 + static::$instance = new static($main_file);
171 + static::$instance->register();
172 + return true;
173 + }
183 174
184 - public function init_plugin()
185 - {
186 - $this->init_hooks();
187 - $this->update_tables();
188 - do_action('bitform_loaded');
175 + private function initWidgets()
176 + {
177 + if (defined('ELEMENTOR_VERSION')) {
178 + new RegisterBitFormElementorWidget();
189 179 }
180 + }
190 181
182 + /**
183 + * Registers the bundled translations directory for the `bit-form` text domain.
184 + */
185 + public function localization_setup()
186 + {
191 187 /**
192 - * Retrieves the main instance of the plugin.
188 + * Filters whether Bit Form loads its bundled translations at all.
193 189 *
194 - * @since 1.0.0-alpha
190 + * Returning false leaves every Free string untranslated — the same filter gates
191 + * the React admin bundle in Admin_Bar. Pro has its own
192 + * `bitformpro_filter_allow_translation`.
195 193 *
196 - * @return BITFORM Plugin main instance.
194 + * @param bool $allow Whether to load translations. Default true.
197 195 */
198 - public static function instance()
199 - {
200 - return static::$instance;
196 + if (!apply_filters('bitform_filter_allow_translation', true)) {
197 + return;
201 198 }
202 199
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 - }
200 + load_plugin_textdomain('bit-form', false, \dirname(BITFORMS_PLUGIN_BASENAME) . '/languages');
201 + }
220 202 }