PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.4
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.4
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
bit-form / includes / Core / Util / Activation.php

Activation.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.4, at includes/Core/Util/Activation.php

121 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Util;
4
5 use BitCode\BitForm\Core\Database\DB;
6
7 /**
8 * Class handling plugin activation.
9 *
10 * @since 1.0.0
11 */
12 final class Activation
13 {
14 public function activate()
15 {
16 add_action('bitforms_activation', array($this, 'install'));
17 }
18
19 public function install()
20 {
21 $installed = get_option('bitforms_installed');
22
23 if (!$installed) {
24 DB::migrate();
25 $this->createUploadDir();
26 update_option('bitforms_installed', time());
27 }
28 update_option('bitforms_version', BITFORMS_VERSION);
29 $this->createUploadDir();
30 $this->createFrontendPages();
31 }
32
33 private function createUploadDir()
34 {
35 if (!file_exists(BITFORMS_UPLOAD_DIR)) {
36 wp_mkdir_p(BITFORMS_UPLOAD_DIR);
37 }
38 if (!file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')) {
39 wp_mkdir_p(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles');
40 }
41 if (file_exists(BITFORMS_UPLOAD_DIR) && !file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . '.htaccess')) {
42 $htaccessFile = fopen(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . '.htaccess', "w");
43 $rules = "
44 <IfDefine php_flag>
45 php_flag engine off
46 </IfDefine>
47 Options -Indexes
48 Order allow,deny
49 Deny from all
50 Require all denied
51 ";
52 fwrite($htaccessFile, $rules);
53 fclose($htaccessFile);
54 }
55 if (file_exists(BITFORMS_UPLOAD_DIR) && !file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . 'index.php')) {
56 $indexFile = fopen(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . 'index.php', "w");
57 $code = "<?php\n";
58 fwrite($indexFile, $code);
59 fclose($indexFile);
60 }
61 if (file_exists(BITFORMS_CONTENT_DIR) && !file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php')) {
62 $indexFile = fopen(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php', "w");
63 $code = "<?php\n";
64 fwrite($indexFile, $code);
65 fclose($indexFile);
66 }
67 }
68
69 private function createFrontendPages()
70 {
71 $args = array(
72 'label' => __('Bitforms Pages', 'bitform'),
73 'public' => true,
74 'show_ui' => true,
75 'show_in_menu' => false,
76 'capability_type' => 'page',
77 'hierarchical' => false,
78 'query_var' => false,
79 'supports' => array('title'),
80 'show_in_rest' => false
81 );
82 register_post_type('bitforms', $args);
83 $routes = get_option('bitforms_routes');
84 $route_value = array();
85 if (!$routes) {
86 $file_route_id = $this->insertPage();
87 if (!is_wp_error($file_route_id)) {
88 $route_value['file'] = $file_route_id;
89 }
90 } elseif (isset($routes['file'])) {
91 if (empty(get_post($routes['file']))) {
92 $file_route_id = $this->insertPage();
93 if (!is_wp_error($file_route_id)) {
94 $route_value['file'] = $file_route_id;
95 }
96 } else {
97 $file_page = array('ID' => $routes['file'], 'post_status' => 'publish');
98 wp_update_post($file_page);
99 }
100 }
101 if (!empty($route_value)) {
102 update_option('bitforms_routes', esc_sql($route_value));
103 }
104 flush_rewrite_rules();
105 }
106
107 private function insertPage()
108 {
109 return wp_insert_post(
110 array(
111 'post_name' => 'bitforms-file',
112 'comment_status' => 'closed',
113 'ping_status' => 'closed',
114 'post_content' => '<!-- wp:shortcode -->[bitforms-frontend-file /]<!-- /wp:shortcode -->',
115 'post_status' => 'publish',
116 'post_type' => 'bitforms'
117 )
118 );
119 }
120 }
121