PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.15
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.15
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / includes / class-tables.php

class-tables.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.0.15, at includes/class-tables.php

266 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UsersWP table related functions
4 *
5 * @since 1.0.0
6 * @author GeoDirectory Team <info@wpgeodirectory.com>
7 */
8 class UsersWP_Tables {
9
10 /**
11 * Creates UsersWP related tables.
12 *
13 * @since 1.0.0
14 * @package userswp
15 *
16 * @return void
17 */
18 public function uwp_create_tables()
19 {
20
21 global $wpdb;
22
23 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
24
25 $wpdb->hide_errors();
26
27 $collate = '';
28 if ($wpdb->has_cap('collation')) {
29 if (!empty($wpdb->charset)) $collate = "DEFAULT CHARACTER SET $wpdb->charset";
30 if (!empty($wpdb->collate)) $collate .= " COLLATE $wpdb->collate";
31 }
32
33 /**
34 * Include any functions needed for upgrades.
35 *
36 * @since 1.0.0
37 */
38 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
39
40 $form_fields = "CREATE TABLE " . $table_name . " (
41 id int(11) NOT NULL AUTO_INCREMENT,
42 form_type varchar(100) NULL,
43 data_type varchar(100) NULL,
44 field_type varchar(255) NOT NULL COMMENT 'text,checkbox,radio,select,textarea',
45 field_type_key varchar(255) NOT NULL,
46 site_title varchar(255) NULL DEFAULT NULL,
47 form_label varchar(255) NULL DEFAULT NULL,
48 help_text varchar(255) NULL DEFAULT NULL,
49 htmlvar_name varchar(255) NULL DEFAULT NULL,
50 default_value text NULL DEFAULT NULL,
51 sort_order int(11) NOT NULL,
52 option_values text NULL DEFAULT NULL,
53 is_active enum( '0', '1' ) NOT NULL DEFAULT '1',
54 for_admin_use enum( '0', '1' ) NOT NULL DEFAULT '0',
55 is_default enum( '0', '1' ) NOT NULL DEFAULT '0',
56 is_dummy enum( '0', '1' ) NOT NULL DEFAULT '0',
57 is_public enum( '0', '1', '2' ) NOT NULL DEFAULT '0',
58 is_required enum( '0', '1' ) NOT NULL DEFAULT '0',
59 is_register_field enum( '0', '1' ) NOT NULL DEFAULT '0',
60 is_search_field enum( '0', '1' ) NOT NULL DEFAULT '0',
61 is_register_only_field enum( '0', '1' ) NOT NULL DEFAULT '0',
62 required_msg varchar(255) NULL DEFAULT NULL,
63 show_in text NULL DEFAULT NULL,
64 user_roles text NULL DEFAULT NULL,
65 extra_fields text NULL DEFAULT NULL,
66 field_icon varchar(255) NULL DEFAULT NULL,
67 css_class varchar(255) NULL DEFAULT NULL,
68 decimal_point varchar( 10 ) NOT NULL,
69 validation_pattern varchar( 255 ) NOT NULL,
70 validation_msg text NULL DEFAULT NULL,
71 PRIMARY KEY (id)
72 ) $collate";
73
74 $form_fields = apply_filters('uwp_before_form_field_table_create', $form_fields);
75
76 dbDelta($form_fields);
77
78 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
79
80 $form_extras = "CREATE TABLE " . $extras_table_name . " (
81 id int(11) NOT NULL AUTO_INCREMENT,
82 form_type varchar(255) NOT NULL,
83 field_type varchar(255) NOT NULL COMMENT 'text,checkbox,radio,select,textarea',
84 site_htmlvar_name varchar(255) NOT NULL,
85 sort_order int(11) NOT NULL,
86 is_default enum( '0', '1' ) NOT NULL DEFAULT '0',
87 is_dummy enum( '0', '1' ) NOT NULL DEFAULT '0',
88 expand_custom_value int(11) NULL DEFAULT NULL,
89 searching_range_mode int(11) NULL DEFAULT NULL,
90 expand_search int(11) NULL DEFAULT NULL,
91 front_search_title varchar(255) CHARACTER SET utf8 NULL DEFAULT NULL,
92 first_search_value int(11) NULL DEFAULT NULL,
93 first_search_text varchar(255) CHARACTER SET utf8 NULL DEFAULT NULL,
94 last_search_text varchar(255) CHARACTER SET utf8 NULL DEFAULT NULL,
95 search_min_value int(11) NULL DEFAULT NULL,
96 search_max_value int(11) NULL DEFAULT NULL,
97 search_diff_value int(11) NULL DEFAULT NULL,
98 search_condition varchar(100) NULL DEFAULT NULL,
99 field_input_type varchar(255) NULL DEFAULT NULL,
100 field_data_type varchar(255) NULL DEFAULT NULL,
101 PRIMARY KEY (id)
102 ) $collate AUTO_INCREMENT=1 ;";
103
104 $form_extras = apply_filters('uwp_before_form_extras_table_create', $form_extras);
105
106 dbDelta($form_extras);
107
108
109 // Table for storing userswp usermeta
110 $usermeta_table_name = uwp_get_table_prefix() . 'uwp_usermeta';
111 $user_meta = "CREATE TABLE " . $usermeta_table_name . " (
112 user_id int(20) NOT NULL,
113 user_ip varchar(20) NULL DEFAULT NULL,
114 user_privacy varchar(255) NULL DEFAULT NULL,
115 uwp_account_username varchar(255) NULL DEFAULT NULL,
116 uwp_account_email varchar(255) NULL DEFAULT NULL,
117 uwp_account_first_name varchar(255) NULL DEFAULT NULL,
118 uwp_account_last_name varchar(255) NULL DEFAULT NULL,
119 uwp_account_bio varchar(255) NULL DEFAULT NULL,
120 uwp_account_avatar_thumb varchar(255) NULL DEFAULT NULL,
121 uwp_account_banner_thumb varchar(255) NULL DEFAULT NULL,
122 PRIMARY KEY (user_id)
123 ) $collate ";
124
125 $user_meta = apply_filters('uwp_before_usermeta_table_create', $user_meta);
126
127 dbDelta($user_meta);
128
129 }
130
131 /**
132 * Creates uwp_usermeta table which introduced in version 1.0.1
133 *
134 * @since 1.0.0
135 * @package userswp
136 *
137 * @return void
138 */
139 public function uwp101_create_tables() {
140 global $wpdb;
141
142
143 $wpdb->hide_errors();
144
145 $collate = '';
146 if ($wpdb->has_cap('collation')) {
147 if (!empty($wpdb->charset)) $collate = "DEFAULT CHARACTER SET $wpdb->charset";
148 if (!empty($wpdb->collate)) $collate .= " COLLATE $wpdb->collate";
149 }
150
151 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
152
153
154 // Table for storing userswp usermeta
155 $usermeta_table_name = uwp_get_table_prefix() . 'uwp_usermeta';
156 $user_meta = "CREATE TABLE " . $usermeta_table_name . " (
157 user_id int(20) NOT NULL,
158 user_ip varchar(20) NULL DEFAULT NULL,
159 uwp_account_username varchar(255) NULL DEFAULT NULL,
160 uwp_account_email varchar(255) NULL DEFAULT NULL,
161 uwp_account_first_name varchar(255) NULL DEFAULT NULL,
162 uwp_account_last_name varchar(255) NULL DEFAULT NULL,
163 uwp_account_bio varchar(255) NULL DEFAULT NULL,
164 uwp_account_avatar_thumb varchar(255) NULL DEFAULT NULL,
165 uwp_account_banner_thumb varchar(255) NULL DEFAULT NULL,
166 PRIMARY KEY (user_id)
167 ) $collate ";
168
169 $user_meta = apply_filters('uwp_before_usermeta_table_create', $user_meta);
170
171 dbDelta($user_meta);
172 }
173
174 /**
175 * Deleting the table whenever a blog is deleted
176 *
177 * @since 1.0.0
178 * @package userswp
179 *
180 * @param array $tables Tables to delete.
181 *
182 * @return array Modified table array to delete
183 */
184 public function drop_tables_on_delete_blog( $tables ) {
185 global $wpdb;
186 $tables[] = $wpdb->prefix . 'uwp_form_fields';
187 $tables[] = $wpdb->prefix . 'uwp_form_extras';
188 $tables[] = $wpdb->prefix . 'uwp_usermeta';
189 return $tables;
190 }
191
192 /**
193 * Returns the table prefix based on the installation type.
194 *
195 * @since 1.0.0
196 * @package userswp
197 *
198 * @return string Table prefix
199 */
200 public function get_table_prefix() {
201 global $wpdb;
202 $install_type = uwp_get_installation_type();
203 if ($install_type == "multi_not_na") {
204 return $wpdb->prefix;
205 } else {
206 return $wpdb->base_prefix;
207 }
208 }
209
210 /**
211 * Checks whether the column exists in the table.
212 *
213 * @since 1.0.0
214 * @package userswp
215 *
216 * @param string $db Table name.
217 * @param string $column Column name.
218 *
219 * @return bool
220 */
221 public function column_exists($db, $column)
222 {
223 global $wpdb;
224 $exists = false;
225 $columns = $wpdb->get_col("show columns from $db");
226 foreach ($columns as $c) {
227 if ($c == $column) {
228 $exists = true;
229 break;
230 }
231 }
232 return $exists;
233 }
234
235 /**
236 * Adds column if not exist in the table.
237 *
238 * @since 1.0.0
239 * @package userswp
240 *
241 * @param string $db Table name.
242 * @param string $column Column name.
243 * @param string $column_attr Column attributes.
244 *
245 * @return bool|int True when success.
246 */
247 public function add_column_if_not_exist($db, $column, $column_attr = "VARCHAR( 255 ) NOT NULL")
248 {
249 $excluded = uwp_get_excluded_fields();
250
251 $starts_with = "uwp_account_";
252
253 if ((substr($column, 0, strlen($starts_with)) === $starts_with) && !in_array($column, $excluded)) {
254 global $wpdb;
255 $result = 0;// no rows affected
256 if (!$this->column_exists($db, $column)) {
257 if (!empty($db) && !empty($column))
258 $result = $wpdb->query("ALTER TABLE `$db` ADD `$column` $column_attr");
259 }
260 return $result;
261 } else {
262 return true;
263 }
264 }
265
266 }