PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.23
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.23
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.23, at includes/class-tables.php

268 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 user_privacy varchar(255) NULL DEFAULT NULL,
143 uwp_account_username varchar(255) NULL DEFAULT NULL,
144 uwp_account_email varchar(255) NULL DEFAULT NULL,
145 uwp_account_first_name varchar(255) NULL DEFAULT NULL,
146 uwp_account_last_name 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 uwp_account_display_name varchar(255) NULL DEFAULT NULL,
150 PRIMARY KEY (user_id)
151 ) $collate ";
152
153 $user_meta = apply_filters('uwp_before_usermeta_table_create', $user_meta);
154
155 dbDelta($user_meta);
156 }
157
158 /**
159 * Deleting the table whenever a blog is deleted
160 *
161 * @since 1.0.0
162 * @package userswp
163 *
164 * @param array $tables Tables to delete.
165 *
166 * @return array Modified table array to delete
167 */
168 public function drop_tables_on_delete_blog( $tables ) {
169 global $wpdb;
170 $tables[] = $wpdb->prefix . 'uwp_form_fields';
171 $tables[] = $wpdb->prefix . 'uwp_form_extras';
172 $tables[] = $wpdb->prefix . 'uwp_usermeta';
173 return $tables;
174 }
175
176 /**
177 * Returns the table prefix based on the installation type.
178 *
179 * @since 1.0.0
180 * @package userswp
181 *
182 * @return string Table prefix
183 */
184 public function get_table_prefix() {
185 global $wpdb;
186 return $wpdb->prefix;
187 }
188
189 /**
190 * Returns the user meta table prefix based on the installation type.
191 *
192 * @since 1.0.16
193 * @package userswp
194 *
195 * @return string Table prefix
196 */
197 public function get_usermeta_table_prefix() {
198 global $wpdb;
199
200 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
201 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
202 }
203
204 // Network active.
205 if ( is_plugin_active_for_network( 'userswp/userswp.php' ) ) {
206 return $wpdb->base_prefix;
207 } else {
208 return $wpdb->prefix;
209 }
210 }
211
212 /**
213 * Checks whether the column exists in the table.
214 *
215 * @since 1.0.0
216 * @package userswp
217 *
218 * @param string $db Table name.
219 * @param string $column Column name.
220 *
221 * @return bool
222 */
223 public function column_exists($db, $column)
224 {
225 global $wpdb;
226 $exists = false;
227 $columns = $wpdb->get_col("show columns from $db");
228 foreach ($columns as $c) {
229 if ($c == $column) {
230 $exists = true;
231 break;
232 }
233 }
234 return $exists;
235 }
236
237 /**
238 * Adds column if not exist in the table.
239 *
240 * @since 1.0.0
241 * @package userswp
242 *
243 * @param string $db Table name.
244 * @param string $column Column name.
245 * @param string $column_attr Column attributes.
246 *
247 * @return bool|int True when success.
248 */
249 public function add_column_if_not_exist($db, $column, $column_attr = "VARCHAR( 255 ) NOT NULL")
250 {
251 $excluded = uwp_get_excluded_fields();
252
253 $starts_with = "uwp_account_";
254
255 if ((substr($column, 0, strlen($starts_with)) === $starts_with) && !in_array($column, $excluded)) {
256 global $wpdb;
257 $result = 0;// no rows affected
258 if (!$this->column_exists($db, $column)) {
259 if (!empty($db) && !empty($column))
260 $result = $wpdb->query("ALTER TABLE `$db` ADD `$column` $column_attr");
261 }
262 return $result;
263 } else {
264 return true;
265 }
266 }
267
268 }