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/Core/Util/Activation.php +89 -31 2.03.3.1 View file →
@@ -1,11 +1,17 @@
1 1 <?php
2 2
3 3 namespace BitCode\BitForm\Core\Util;
4 4
5 +if (!defined('ABSPATH')) {
6 + exit;
7 +}
8 +
9 +use BitCode\BitForm\Admin\Form\Helpers;
5 10 use BitCode\BitForm\Core\Database\DB;
6 11 use BitCode\BitForm\Core\Database\FormModel;
7 12 use WP_Error;
13 +use WP_Site;
8 14
9 15 /**
10 16 * Class handling plugin activation.
11 17 *
@@ -10,20 +16,49 @@
10 16 * Class handling plugin activation.
11 17 *
12 18 * @since 1.0.0
13 19 */
14 -final class Activation {
20 +final class Activation
21 +{
15 22 private static $formModel;
16 23
17 - public function __construct() {
24 + public function __construct()
25 + {
18 26 static::$formModel = new FormModel();
19 27 }
20 28
21 - public function activate() {
29 + public function activate()
30 + {
22 31 add_action('bitforms_activation', [$this, 'install']);
32 + add_action('wp_initialize_site', [$this, 'initializeNewSite'], 120, 1);
23 33 }
24 34
25 - public function install() {
35 + public function install($networkWide)
36 + {
37 + if ($networkWide && \function_exists('is_multisite') && is_multisite()) {
38 + $sites = get_sites(['fields' => 'ids', 'network_id' => get_current_network_id()]);
39 + foreach ($sites as $site) {
40 + switch_to_blog($site);
41 + $this->installOnCurrentBlog();
42 + restore_current_blog();
43 + }
44 + } else {
45 + $this->installOnCurrentBlog();
46 + }
47 + }
48 +
49 + public function initializeNewSite(WP_Site $site)
50 + {
51 + switch_to_blog($site->blog_id);
52 + $plugin = plugin_basename(BITFORMS_PLUGIN_MAIN_FILE);
53 + if (!is_plugin_active_for_network($plugin)) {
54 + do_action('bitforms_activation', false);
55 + }
56 + restore_current_blog();
57 + }
58 +
59 + public function installOnCurrentBlog()
60 + {
26 61 $installed = get_option('bitforms_installed');
27 62
28 63 if (!$installed) {
29 64 DB::migrate();
@@ -29,15 +64,34 @@
29 64 DB::migrate();
30 65 $this->createUploadDir();
31 66 update_option('bitforms_installed', time());
32 67 }
68 +
69 + update_option('bitforms_migrated_to_v2', true);
70 + $appConfig = get_option('bitform_app_config');
71 + if (!$appConfig) {
72 + $config = (object) [];
73 + $config->delete_table = true;
74 + update_option('bitform_app_config', $config);
75 + }
76 + $appSettings = get_option('bitform_app_settings');
77 + if (!$appSettings) {
78 + $appSettings = (object) [];
79 + $appSettings->globalMessages = Helpers::getDefaultGlobalMessages();
80 + update_option('bitform_app_settings', $appSettings);
81 + }
82 +
33 83 update_option('bitforms_version', BITFORMS_VERSION);
34 84 $this->layoutUpdate();
35 85 $this->createUploadDir();
36 - $this->createFrontendPages();
86 +
87 + if (!defined('WP_TESTS_DOMAIN')) {
88 + $this->createFrontendPages();
89 + }
37 90 }
38 91
39 - private function createUploadDir() {
92 + private function createUploadDir()
93 + {
40 94 if (!file_exists(BITFORMS_UPLOAD_DIR)) {
41 95 wp_mkdir_p(BITFORMS_UPLOAD_DIR);
42 96 }
43 97 if (!file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')) {
@@ -43,9 +97,8 @@
43 97 if (!file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')) {
44 98 wp_mkdir_p(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles');
45 99 }
46 100 if (file_exists(BITFORMS_UPLOAD_DIR) && !file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . '.htaccess')) {
47 - $htaccessFile = fopen(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . '.htaccess', 'w');
48 101 $rules = '
49 102 <IfDefine php_flag>
50 103 php_flag engine off
51 104 </IfDefine>
@@ -53,26 +106,20 @@
53 106 Order allow,deny
54 107 Deny from all
55 108 Require all denied
56 109 ';
57 - fwrite($htaccessFile, $rules);
58 - fclose($htaccessFile);
110 + FileHandler::writeFile(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . '.htaccess', $rules);
59 111 }
60 112 if (file_exists(BITFORMS_UPLOAD_DIR) && !file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . 'index.php')) {
61 - $indexFile = fopen(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . 'index.php', 'w');
62 - $code = "<?php\n";
63 - fwrite($indexFile, $code);
64 - fclose($indexFile);
113 + FileHandler::writeFile(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . 'index.php', "<?php\n");
65 114 }
66 115 if (file_exists(BITFORMS_CONTENT_DIR) && !file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php')) {
67 - $indexFile = fopen(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php', 'w');
68 - $code = "<?php\n";
69 - fwrite($indexFile, $code);
70 - fclose($indexFile);
116 + FileHandler::writeFile(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php', "<?php\n");
71 117 }
72 118 }
73 119
74 - private function getForms() {
120 + private function getForms()
121 + {
75 122 $getForms = static::$formModel->get(
76 123 [
77 124 'id',
78 125 'status',
@@ -87,9 +134,10 @@
87 134 );
88 135 return $getForms;
89 136 }
90 137
91 - private function layoutUpdate() {
138 + private function layoutUpdate()
139 + {
92 140 $getForms = $this->getForms();
93 141
94 142 if (is_wp_error($getForms)) {
95 143 return $getForms;
@@ -101,8 +149,11 @@
101 149 $content = json_decode($form->form_content);
102 150 $layout = $content->layout;
103 151 $updated = false;
104 152
153 + if (is_array($layout)) {
154 + continue;
155 + }
105 156 foreach ($layout->lg as $lyIndex => $lg) {
106 157 if ($lg->w < 10) {
107 158 $updated = true;
108 159 $layout->lg[$lyIndex]->h = $lg->h * 20;
@@ -160,9 +211,9 @@
160 211 }
161 212 }
162 213 }
163 214
164 - $getForms[$index]->form_content = json_encode($content);
215 + $getForms[$index]->form_content = wp_json_encode($content);
165 216
166 217 $wpdb->query('START TRANSACTION');
167 218
168 219 if ($updated) {
@@ -184,19 +235,25 @@
184 235 $wpdb->query('COMMIT');
185 236 }
186 237 }
187 238
188 - private function createFrontendPages() {
239 + private function createFrontendPages()
240 + {
189 241 $args = [
190 - 'label' => __('Bitforms Pages', 'bit-form'),
191 - 'public' => true,
192 - 'show_ui' => true,
193 - 'show_in_menu' => false,
194 - 'capability_type' => 'page',
195 - 'hierarchical' => false,
196 - 'query_var' => false,
197 - 'supports' => ['title'],
198 - 'show_in_rest' => false
242 + 'label' => __('Bitforms Pages', 'bit-form'),
243 + 'public' => false,
244 + 'publicly_queryable' => true,
245 + 'exclude_from_search' => true,
246 + 'show_in_nav_menus' => false,
247 + 'show_ui' => true,
248 + 'show_in_menu' => false,
249 + 'capability_type' => 'page',
250 + 'hierarchical' => false,
251 + 'has_archive' => false,
252 + 'query_var' => false,
253 + 'rewrite' => true,
254 + 'supports' => ['title'],
255 + 'show_in_rest' => false
199 256 ];
200 257 register_post_type('bitforms', $args);
201 258 $routes = get_option('bitforms_routes');
202 259 $route_value = [];
@@ -221,9 +278,10 @@
221 278 }
222 279 flush_rewrite_rules();
223 280 }
224 281
225 - private function insertPage() {
282 + private function insertPage()
283 + {
226 284 return wp_insert_post(
227 285 [
228 286 'post_name' => 'bitforms-file',
229 287 'comment_status' => 'closed',