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 +61 -26 2.10.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 *
@@ -22,12 +28,37 @@
22 28
23 29 public function activate()
24 30 {
25 31 add_action('bitforms_activation', [$this, 'install']);
32 + add_action('wp_initialize_site', [$this, 'initializeNewSite'], 120, 1);
26 33 }
27 34
28 - public function install()
35 + public function install($networkWide)
29 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 + {
30 61 $installed = get_option('bitforms_installed');
31 62
32 63 if (!$installed) {
33 64 DB::migrate();
@@ -34,12 +65,9 @@
34 65 $this->createUploadDir();
35 66 update_option('bitforms_installed', time());
36 67 }
37 68
38 - // $olderVersion = FallBack::getOlderVersion();
39 - // if ($olderVersion === '2.0-beta.1') {
40 - // update_option('bitforms_migrated_to_v2', true);
41 - // }
69 + update_option('bitforms_migrated_to_v2', true);
42 70 $appConfig = get_option('bitform_app_config');
43 71 if (!$appConfig) {
44 72 $config = (object) [];
45 73 $config->delete_table = true;
@@ -44,12 +72,22 @@
44 72 $config = (object) [];
45 73 $config->delete_table = true;
46 74 update_option('bitform_app_config', $config);
47 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 +
48 83 update_option('bitforms_version', BITFORMS_VERSION);
49 84 $this->layoutUpdate();
50 85 $this->createUploadDir();
51 - $this->createFrontendPages();
86 +
87 + if (!defined('WP_TESTS_DOMAIN')) {
88 + $this->createFrontendPages();
89 + }
52 90 }
53 91
54 92 private function createUploadDir()
55 93 {
@@ -59,9 +97,8 @@
59 97 if (!file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')) {
60 98 wp_mkdir_p(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles');
61 99 }
62 100 if (file_exists(BITFORMS_UPLOAD_DIR) && !file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . '.htaccess')) {
63 - $htaccessFile = fopen(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . '.htaccess', 'w');
64 101 $rules = '
65 102 <IfDefine php_flag>
66 103 php_flag engine off
67 104 </IfDefine>
@@ -69,22 +106,15 @@
69 106 Order allow,deny
70 107 Deny from all
71 108 Require all denied
72 109 ';
73 - fwrite($htaccessFile, $rules);
74 - fclose($htaccessFile);
110 + FileHandler::writeFile(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . '.htaccess', $rules);
75 111 }
76 112 if (file_exists(BITFORMS_UPLOAD_DIR) && !file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . 'index.php')) {
77 - $indexFile = fopen(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . 'index.php', 'w');
78 - $code = "<?php\n";
79 - fwrite($indexFile, $code);
80 - fclose($indexFile);
113 + FileHandler::writeFile(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . 'index.php', "<?php\n");
81 114 }
82 115 if (file_exists(BITFORMS_CONTENT_DIR) && !file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php')) {
83 - $indexFile = fopen(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php', 'w');
84 - $code = "<?php\n";
85 - fwrite($indexFile, $code);
86 - fclose($indexFile);
116 + FileHandler::writeFile(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php', "<?php\n");
87 117 }
88 118 }
89 119
90 120 private function getForms()
@@ -208,17 +238,22 @@
208 238
209 239 private function createFrontendPages()
210 240 {
211 241 $args = [
212 - 'label' => __('Bitforms Pages', 'bit-form'),
213 - 'public' => true,
214 - 'show_ui' => true,
215 - 'show_in_menu' => false,
216 - 'capability_type' => 'page',
217 - 'hierarchical' => false,
218 - 'query_var' => false,
219 - 'supports' => ['title'],
220 - '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
221 256 ];
222 257 register_post_type('bitforms', $args);
223 258 $routes = get_option('bitforms_routes');
224 259 $route_value = [];