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 -166 1.1.13.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,206 +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;
22 +use BitCode\BitForm\Widgets\RegisterBitFormElementorWidget;
23 23
24 24 final class Plugin
25 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;
26 33
27 - /**
28 - * Main instance of the plugin.
29 - *
30 - * @since 1.0.0-alpha
31 - * @var Plugin|null
32 - */
33 - 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 + }
34 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 + }
35 60
36 - /**
37 - * Registers the plugin with WordPress.
38 - *
39 - * @since 1.0.0-alpha
40 - */
41 - public function register()
42 - {
43 - add_action('plugins_loaded', array($this, 'init_plugin'));
44 - (new Activation())->activate();
45 - (new Deactivation())->register();
46 - (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 + }
47 73 }
74 + return [$formContent, $updated];
75 + }
48 76
77 + public function optionFallBack()
78 + {
79 + $formModel = new FormModel();
80 + $forms = $formModel->get(
81 + ['id', 'form_content']
82 + );
49 83
50 - /**
51 - * Initialize the hooks
52 - *
53 - * @return void
54 - */
55 - public function init_hooks()
56 - {
57 - add_action('init', array($this, 'registerBitformsPostType'));
58 - add_action("bitforms_exec_integrations", array(Integrations::class, 'integrationExecutionHelper'), 1, 5);
59 - // Localize our plugin
60 - add_action('init', array($this, 'localization_setup'));
61 -
62 - // initialize the classes
63 - add_action('init', array($this, 'init_classes'));
64 -
65 - add_action('init', array($this, 'entryMetaKeyUpdate'));
66 -
67 - add_filter('plugin_action_links_' . plugin_basename(BITFORMS_PLUGIN_MAIN_FILE), array($this, 'plugin_action_links'));
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 + }
68 97 }
98 + }
69 99
70 - public function entryMetaKeyUpdate()
71 - {
72 - $installed = get_option('bitforms_installed');
73 - $oldversion = null;
74 - if ($installed) {
75 - $oldversion = get_option('bitforms_version');
76 - }
77 - if ($oldversion && version_compare($oldversion, BITFORMS_VERSION, '!=')) {
78 - update_option('bitforms_version', BITFORMS_VERSION);
79 - if (version_compare('1.0.4', $oldversion, '>=')) {
80 - // if version is lower or equal than 1.0.4
81 - $formEntryMetaChange = new FormEntryMetaChange();
82 - $formEntryMetaChange->changeMeta();
83 - }
84 - }
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;
85 109 }
86 110
87 - /**
88 - * Updates bit form content tables on wp db
89 - *
90 - * @return void
91 - */
92 - public function update_tables()
93 - {
94 - if (!current_user_can('manage_options')) {
95 - return;
96 - }
97 -
98 - global $bitforms_db_version;
99 - $installed_db_version = get_site_option("bitforms_db_version");
100 - if ($installed_db_version != $bitforms_db_version) {
101 - DB::migrate();
102 - }
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();
103 115 }
116 + }
104 117
105 - /**
106 - * Register post type for bitforms
107 - *
108 - * @return void
109 - */
110 - public function registerBitformsPostType()
111 - {
112 - $args = array(
113 - 'label' => __('Bitform Pages', 'bitform'),
114 - 'public' => true,
115 - 'show_ui' => true,
116 - 'show_in_menu' => false,
117 - 'capability_type' => 'page',
118 - 'hierarchical' => false,
119 - 'query_var' => false,
120 - 'supports' => array('title'),
121 - 'show_in_rest' => false
122 - );
123 - register_post_type('bitforms', $args);
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();
124 132 }
133 + Hooks::init_hooks();
134 + $this->initWidgets();
135 + do_action('bitform_loaded');
136 + }
125 137
126 - /**
127 - * Initialize plugin for localization
128 - *
129 - * @uses load_plugin_textdomain()
130 - */
131 - public function localization_setup()
132 - {
133 - load_plugin_textdomain('bitform', false, dirname(BITFORMS_PLUGIN_BASENAME) . '/languages');
134 - }
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 + }
135 149
136 - /**
137 - * Instantiate the required classes
138 - *
139 - * @return void
140 - */
141 - public function init_classes()
142 - {
143 - if (Request::Check('admin')) {
144 - (new Admin_Bar())->register();
145 - }
146 - if (Request::Check('ajax')) {
147 - new AjaxService();
148 - }
149 - if (Request::Check('frontend')) {
150 - $formHandler = new FormHandler();
151 - $formHandler->frontend;
152 - }
153 - if (Request::isPluginPage()) {
154 - (new FileDownloadProvider())->register();
155 - }
156 - if (current_user_can('edit_posts')) {
157 - (new GutenBlockProvider())->register();
158 - }
159 - }
150 + public function plugin_action_links($links)
151 + {
152 + $links[] = '<a href="https://bitapps.pro/docs/bit-form/" target="_blank">' . __('Docs', 'bit-form') . '</a>';
160 153
161 - /**
162 - * Plugin action links
163 - *
164 - * @param array $links
165 - *
166 - * @return array
167 - */
168 - public function plugin_action_links($links)
169 - {
170 - $links[] = '<a href="https://www.bitpress.pro" target="_blank">' . __('Docs', 'bitform') . '</a>';
154 + return $links;
155 + }
171 156
172 - 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;
173 168 }
174 169
170 + static::$instance = new static($main_file);
171 + static::$instance->register();
172 + return true;
173 + }
175 174
176 - public function init_plugin()
177 - {
178 - $this->init_hooks();
179 - $this->update_tables();
180 - do_action('bitform_loaded');
175 + private function initWidgets()
176 + {
177 + if (defined('ELEMENTOR_VERSION')) {
178 + new RegisterBitFormElementorWidget();
181 179 }
180 + }
182 181
182 + /**
183 + * Registers the bundled translations directory for the `bit-form` text domain.
184 + */
185 + public function localization_setup()
186 + {
183 187 /**
184 - * Retrieves the main instance of the plugin.
188 + * Filters whether Bit Form loads its bundled translations at all.
185 189 *
186 - * @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`.
187 193 *
188 - * @return BITFORM Plugin main instance.
194 + * @param bool $allow Whether to load translations. Default true.
189 195 */
190 - public static function instance()
191 - {
192 - return static::$instance;
196 + if (!apply_filters('bitform_filter_allow_translation', true)) {
197 + return;
193 198 }
194 199
195 - /**
196 - * Loads the plugin main instance and initializes it.
197 - *
198 - * @param string $main_file Absolute path to the plugin main file.
199 - *
200 - * @return bool True if the plugin main instance could be loaded, false otherwise.
201 - */
202 - public static function load($main_file)
203 - {
204 - if (null !== static::$instance) {
205 - return false;
206 - }
207 -
208 - static::$instance = new static($main_file);
209 - static::$instance->register();
210 - return true;
211 - }
200 + load_plugin_textdomain('bit-form', false, \dirname(BITFORMS_PLUGIN_BASENAME) . '/languages');
201 + }
212 202 }