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

128 lines 3.6 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 set_transient( 'weforms_prevent_tracker_notice', true, DAY_IN_SECONDS * 7 ); // don't wanna show tracking notice in first 7 days
29 update_option( 'weforms_version', WEFORMS_VERSION );
30 }
31
32 /**
33 * Create the table schema
34 *
35 * @return void
36 */
37 public function create_tables() {
38 global $wpdb;
39
40 $collate = '';
41
42 if ( $wpdb->has_cap( 'collation' ) ) {
43 if ( ! empty($wpdb->charset ) ) {
44 $collate .= "DEFAULT CHARACTER SET $wpdb->charset";
45 }
46
47 if ( ! empty($wpdb->collate ) ) {
48 $collate .= " COLLATE $wpdb->collate";
49 }
50 }
51
52 $table_schema = array(
53 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_entries` (
54 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
55 `form_id` bigint(20) unsigned DEFAULT NULL,
56 `user_id` bigint(20) unsigned DEFAULT NULL,
57 `user_ip` int(11) unsigned DEFAULT NULL,
58 `user_device` varchar(50) DEFAULT NULL,
59 `referer` varchar(255) DEFAULT NULL,
60 `status` varchar(10) DEFAULT 'publish',
61 `created_at` datetime DEFAULT NULL,
62 PRIMARY KEY (`id`),
63 KEY `form_id` (`form_id`)
64 ) $collate;",
65
66 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_entrymeta` (
67 `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
68 `weforms_entry_id` bigint(20) unsigned DEFAULT NULL,
69 `meta_key` varchar(255) DEFAULT NULL,
70 `meta_value` longtext,
71 PRIMARY KEY (`meta_id`),
72 KEY `meta_key` (`meta_key`),
73 KEY `entry_id` (`weforms_entry_id`)
74 ) $collate;",
75 );
76
77 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
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', array() );
93 $additional_keys = array(
94 'email_gateway' => 'wordpress',
95 'credit' => false,
96 'recaptcha' => array( 'key' => '', 'secret' => '' )
97 );
98
99 foreach ($additional_keys as $key => $value) {
100 if ( ! isset( $settings[ $key ] ) ) {
101 $settings[ $key ] = $value;
102
103 $requires_update = true;
104 }
105 }
106
107 if ( $requires_update ) {
108 update_option( 'weforms_settings', $settings );
109 }
110 }
111
112 /**
113 * Create a default form
114 *
115 * @return void
116 */
117 public function create_default_form() {
118 $version = get_option( 'weforms_version' );
119
120 // seems like it's already installed
121 if ( $version ) {
122 return;
123 }
124
125 weforms()->templates->create( 'contact' );
126 }
127 }
128