PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.17
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.17
1.2.73 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 All 173 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.17, at includes/class-tables.php

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