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

172 lines 5.3 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 if ( ! function_exists( 'weforms_get_contactform_template_fields' ) ) {
139 require_once dirname( __FILE__ ) . '/functions-template-contact-form.php';
140 }
141
142 $form_post_data = array(
143 'post_title' => __( 'Contact Form', 'weforms' ),
144 'post_type' => 'wpuf_contact_form',
145 'post_status' => 'publish',
146 'post_author' => get_current_user_id()
147 );
148
149 $form_id = wp_insert_post( $form_post_data );
150
151 if ( is_wp_error( $form_id ) ) {
152 return;
153 }
154
155 update_post_meta( $form_id, 'wpuf_form_settings', weforms_get_contactform_template_settings() );
156 update_post_meta( $form_id, 'notifications', weforms_get_contactform_template_notification() );
157
158 $form_fields = weforms_get_contactform_template_fields();
159
160 if ( $form_fields ) {
161 foreach ($form_fields as $menu_order => $field) {
162 wp_insert_post( array(
163 'post_type' => 'wpuf_input',
164 'post_status' => 'publish',
165 'post_content' => maybe_serialize( $field ),
166 'post_parent' => $form_id,
167 'menu_order' => $menu_order
168 ) );
169 }
170 }
171 }
172 }