PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.1.1
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.1.1
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.1.1, at includes/class-installer.php

140 lines 4.2 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
17 $this->create_tables();
18 $this->maybe_set_default_settings();
19 $this->create_default_form();
20
21 $installed = get_option( 'weforms_installed' );
22
23 if ( ! $installed ) {
24 update_option( 'weforms_installed', time() );
25 }
26
27 set_transient( 'weforms_activation_redirect', true, 30 );
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 = array(
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 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_payments` (
76 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
77 `form_id` bigint(20) unsigned DEFAULT NULL,
78 `entry_id` bigint(20) unsigned DEFAULT NULL,
79 `user_id` bigint(20) unsigned DEFAULT NULL,
80 `total` float(20) unsigned DEFAULT NULL,
81 `gatewat` varchar(50) DEFAULT NULL,
82 `transaction_id` varchar(50) DEFAULT NULL,
83 `status` varchar(10) DEFAULT 'completed',
84 `created_at` datetime DEFAULT NULL,
85 PRIMARY KEY (`id`),
86 KEY `form_id` (`form_id`)
87 ) $collate;",
88 );
89
90 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
91 foreach ( $table_schema as $table ) {
92 dbDelta( $table );
93 }
94 }
95
96 /**
97 * Set the required default settings key if not present
98 *
99 * This is required for setting up the component settings data
100 *
101 * @return void
102 */
103 public function maybe_set_default_settings() {
104 $requires_update = false;
105 $settings = get_option( 'weforms_settings', array() );
106 $additional_keys = array(
107 'email_gateway' => 'wordpress',
108 'credit' => false,
109 'recaptcha' => array( 'key' => '', 'secret' => '' )
110 );
111
112 foreach ($additional_keys as $key => $value) {
113 if ( ! isset( $settings[ $key ] ) ) {
114 $settings[ $key ] = $value;
115
116 $requires_update = true;
117 }
118 }
119
120 if ( $requires_update ) {
121 update_option( 'weforms_settings', $settings );
122 }
123 }
124
125 /**
126 * Create a default form
127 *
128 * @return void
129 */
130 public function create_default_form() {
131 $version = get_option( 'weforms_version' );
132
133 // seems like it's already installed
134 if ( $version ) {
135 return;
136 }
137
138 weforms()->templates->create( 'contact' );
139 }
140 }