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

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