PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.11
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.11
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / class-installer.php

class-installer.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.6.11, at includes/class-installer.php

129 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The installer class
5 *
6 * @since 1.1.0
7 */
8 class WeForms_Installer {
9
10 /**
11 * The installer class
12 *
13 * @return void
14 */
15 public function install() {
16 $this->create_tables();
17 $this->maybe_set_default_settings();
18 $this->create_default_form();
19
20 $installed = get_option( 'weforms_installed' );
21
22 if ( !$installed ) {
23 update_option( 'weforms_installed', time() );
24 }
25
26 set_transient( 'weforms_activation_redirect', true, 30 );
27 set_transient( 'weforms_prevent_tracker_notice', true, DAY_IN_SECONDS * 7 ); // don't wanna show tracking notice in first 7 days
28 update_option( 'weforms_version', WEFORMS_VERSION );
29 }
30
31 /**
32 * Create the table schema
33 *
34 * @return void
35 */
36 public function create_tables() {
37 global $wpdb;
38
39 $collate = '';
40
41 if ( $wpdb->has_cap( 'collation' ) ) {
42 if ( !empty( $wpdb->charset ) ) {
43 $collate .= "DEFAULT CHARACTER SET $wpdb->charset";
44 }
45
46 if ( !empty( $wpdb->collate ) ) {
47 $collate .= " COLLATE $wpdb->collate";
48 }
49 }
50
51 $table_schema = [
52 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_entries` (
53 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
54 `form_id` bigint(20) unsigned DEFAULT NULL,
55 `user_id` bigint(20) unsigned DEFAULT NULL,
56 `user_ip` int(11) unsigned DEFAULT NULL,
57 `user_device` varchar(50) DEFAULT NULL,
58 `referer` varchar(255) DEFAULT NULL,
59 `status` varchar(10) DEFAULT 'publish',
60 `created_at` datetime DEFAULT NULL,
61 PRIMARY KEY (`id`),
62 KEY `form_id` (`form_id`)
63 ) $collate;",
64
65 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_entrymeta` (
66 `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
67 `weforms_entry_id` bigint(20) unsigned DEFAULT NULL,
68 `meta_key` varchar(255) DEFAULT NULL,
69 `meta_value` longtext,
70 PRIMARY KEY (`meta_id`),
71 KEY `meta_key` (`meta_key`),
72 KEY `entry_id` (`weforms_entry_id`)
73 ) $collate;",
74 ];
75
76 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
77
78 foreach ( $table_schema as $table ) {
79 dbDelta( $table );
80 }
81 }
82
83 /**
84 * Set the required default settings key if not present
85 *
86 * This is required for setting up the component settings data
87 *
88 * @return void
89 */
90 public function maybe_set_default_settings() {
91 $requires_update = false;
92 $settings = get_option( 'weforms_settings', [] );
93 $additional_keys = [
94 'email_gateway' => 'wordpress',
95 'credit' => false,
96 'email_footer' => true,
97 'recaptcha' => [ 'key' => '', 'secret' => '', 'type' => 'v2' ],
98 ];
99
100 foreach ( $additional_keys as $key => $value ) {
101 if ( !isset( $settings[ $key ] ) ) {
102 $settings[ $key ] = $value;
103
104 $requires_update = true;
105 }
106 }
107
108 if ( $requires_update ) {
109 update_option( 'weforms_settings', $settings );
110 }
111 }
112
113 /**
114 * Create a default form
115 *
116 * @return void
117 */
118 public function create_default_form() {
119 $version = get_option( 'weforms_version' );
120
121 // seems like it's already installed
122 if ( $version ) {
123 return;
124 }
125
126 weforms()->templates->create( 'contact' );
127 }
128 }
129