PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.0.3
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.0.3
4.17.2 4.17.1 4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / Classes / PROFILEPRESS_sql.php
wp-user-avatar / src / Classes Last commit date
Installer 5 years ago AdminNotices.php 4 years ago AjaxHandler.php 4 years ago Autologin.php 4 years ago BuddyPressBbPress.php 5 years ago EditUserProfile.php 4 years ago ExtensionManager.php 4 years ago FileUploader.php 4 years ago FormPreviewHandler.php 5 years ago FormRepository.php 4 years ago FormShortcodeDefaults.php 5 years ago GDPR.php 4 years ago Geolocation.php 4 years ago GlobalSiteAccess.php 4 years ago ImageUploader.php 4 years ago LoginAuth.php 4 years ago Miscellaneous.php 4 years ago ModifyRedirectDefaultLinks.php 4 years ago PPRESS_Session.php 4 years ago PROFILEPRESS_sql.php 4 years ago PasswordReset.php 4 years ago ProfileUrlRewrite.php 4 years ago RegistrationAuth.php 4 years ago SendEmail.php 4 years ago ShortcodeThemeFactory.php 5 years ago UserAvatar.php 4 years ago UserSignupLocationListingPage.php 4 years ago UsernameEmailRestrictLogin.php 4 years ago WPProfileFieldParserTrait.php 4 years ago WelcomeEmailAfterSignup.php 4 years ago default-email-template.php 4 years ago index.php 5 years ago
PROFILEPRESS_sql.php
500 lines
1 <?php
2
3 namespace ProfilePress\Core\Classes;
4
5 use ProfilePress\Core\Base;
6
7 class PROFILEPRESS_sql
8 {
9 /** @param $meta_key
10 * @param $meta_value
11 *
12 * @return bool|int
13 */
14 public static function add_meta_data($meta_key, $meta_value)
15 {
16 global $wpdb;
17
18 $insert = $wpdb->insert(
19 Base::meta_data_db_table(),
20 [
21 'meta_key' => $meta_key,
22 'meta_value' => serialize($meta_value),
23 ],
24 [
25 '%s',
26 '%s',
27 ]
28 );
29
30 return ! $insert ? false : $wpdb->insert_id;
31 }
32
33 /**
34 * @param $meta_id
35 * @param $meta_key
36 * @param $meta_value
37 *
38 * @return false|int
39 */
40 public static function update_meta_value($meta_id, $meta_key, $meta_value)
41 {
42 global $wpdb;
43
44 return $wpdb->update(
45 Base::meta_data_db_table(),
46 ['meta_value' => serialize($meta_value)],
47 ['id' => $meta_id, 'meta_key' => $meta_key],
48 ['%s'],
49 ['%d', '%s']
50 );
51 }
52
53 /**
54 * @param $meta_id
55 * @param $meta_key
56 *
57 * @return bool|mixed
58 */
59 public static function get_meta_value($meta_id, $meta_key)
60 {
61 global $wpdb;
62
63 $table = Base::meta_data_db_table();
64
65 $sql = "SELECT meta_value FROM $table WHERE id= %d AND meta_key = %s";
66
67 // get the profile fields row for the id and save as array
68 $result = $wpdb->get_var($wpdb->prepare($sql, $meta_id, $meta_key));
69
70 return ! is_null($result) ? unserialize($result) : false;
71 }
72
73 public static function get_meta_data_by_key($meta_key)
74 {
75 global $wpdb;
76
77 $table = Base::meta_data_db_table();
78
79 $sql = "SELECT * FROM $table WHERE meta_key = %s";
80
81 $result = $wpdb->get_results($wpdb->prepare($sql, $meta_key), 'ARRAY_A');
82
83 if (empty($result)) return false;
84
85 $output = [];
86 foreach ($result as $key => $meta) {
87 $output[$key] = array_reduce(array_keys($meta), function ($carry, $item) use ($meta) {
88 $carry[$item] = ($item == 'meta_value') ? unserialize($meta[$item]) : $meta[$item];
89
90 return $carry;
91 });
92 }
93
94 return $output;
95 }
96
97 public static function delete_meta_data($meta_id)
98 {
99 global $wpdb;
100
101 $result = $wpdb->delete(Base::meta_data_db_table(), ['id' => $meta_id], ['%d']);
102
103 return $result !== false;
104 }
105
106 public static function delete_meta_data_by_flag($flag)
107 {
108 global $wpdb;
109
110 $result = $wpdb->delete(Base::meta_data_db_table(), ['flag' => $flag], ['%s']);
111
112 return $result !== false;
113 }
114
115 public static function delete_meta_data_by_meta_key($meta_key)
116 {
117 global $wpdb;
118
119 $result = $wpdb->delete(Base::meta_data_db_table(), ['meta_key' => $meta_key], ['%s']);
120
121 return $result !== false;
122 }
123
124 /**
125 * Query for profile placement if user can view the his profile
126 *
127 * @return mixed
128 */
129 public static function get_profile_custom_fields()
130 {
131 if ( ! ExtensionManager::is_premium()) return [];
132
133 global $wpdb;
134
135 return $wpdb->get_results(
136 sprintf("SELECT * FROM %s ORDER BY id", Base::profile_fields_db_table()),
137 'ARRAY_A'
138 );
139 }
140
141 /**
142 * Retrieve the profile field row of an ID
143 *
144 * @param int $id
145 *
146 * @return array
147 */
148 public static function get_profile_custom_field_by_id($id)
149 {
150 global $wpdb;
151
152 if ( ! ExtensionManager::is_premium()) return [];
153
154 $table = Base::profile_fields_db_table();
155
156 return $wpdb->get_row(
157 $wpdb->prepare("SELECT * FROM $table WHERE id = %d", $id),
158 'ARRAY_A'
159 );
160 }
161
162 /**
163 * Retrieve the profile custom field by field key
164 *
165 * @param $field_key
166 *
167 * @return array
168 */
169 public static function get_profile_custom_field_by_key($field_key)
170 {
171 if ( ! ExtensionManager::is_premium()) return [];
172
173 global $wpdb;
174
175 $table = Base::profile_fields_db_table();
176
177 return $wpdb->get_row(
178 $wpdb->prepare("SELECT * FROM $table WHERE field_key = %s", $field_key),
179 'ARRAY_A'
180 );
181 }
182
183 public static function get_profile_custom_fields_by_types($types)
184 {
185 if ( ! ExtensionManager::is_premium()) return [];
186
187 global $wpdb;
188
189 $sql = sprintf("SELECT * FROM %s", Base::profile_fields_db_table());
190
191 $sql .= " WHERE type IN(" . implode(', ', array_fill(0, count($types), '%s')) . ")";
192
193 $sql = call_user_func_array([$wpdb, 'prepare'], array_merge([$sql], $types));
194
195 return $wpdb->get_results($sql);
196 }
197
198 public static function delete_profile_custom_field($id)
199 {
200 global $wpdb;
201
202 $delete_sql = $wpdb->delete(
203 Base::profile_fields_db_table(),
204 ['id' => $id],
205 ['%d']
206 );
207
208 return $delete_sql;
209 }
210
211 /**
212 * Return a list of created custom profile IDs.
213 *
214 * @return array
215 */
216 public static function get_profile_field_ids()
217 {
218 if ( ! ExtensionManager::is_premium()) return [];
219
220 global $wpdb;
221
222 $table = Base::profile_fields_db_table();
223
224 return $wpdb->get_col("SELECT id FROM $table ORDER BY id");
225 }
226
227 /**
228 * Check if a profile field's key exist in the database.
229 *
230 * @param int $field_key
231 *
232 * @return bool
233 */
234 public static function is_profile_field_key_exist($field_key)
235 {
236 if ( ! ExtensionManager::is_premium()) return false;
237
238 global $wpdb;
239
240 $table = Base::profile_fields_db_table();
241
242 $response = $wpdb->get_var(
243 $wpdb->prepare("SELECT id FROM $table WHERE field_key = %s", $field_key)
244 );
245
246 return ! is_null($response);
247 }
248
249 /**
250 * Add custom field to DB
251 *
252 * @param string $label_name
253 * @param string $key
254 * @param string $description
255 * @param string $type
256 * @param string $options
257 *
258 * @return bool|int
259 */
260 public static function add_profile_field($label_name, $key, $description, $type, $options)
261 {
262 global $wpdb;
263
264 $insert = $wpdb->insert(
265 Base::profile_fields_db_table(),
266 array(
267 'label_name' => $label_name,
268 'field_key' => $key,
269 'description' => $description,
270 'type' => $type,
271 'options' => $options,
272 ),
273 array(
274 '%s',
275 '%s',
276 '%s',
277 '%s',
278 '%s',
279 )
280 );
281
282 return ! $insert ? false : $wpdb->insert_id;
283 }
284
285
286 /**
287 * Update custom field in DB
288 *
289 * @param $id
290 * @param string $label_name
291 * @param string $key
292 * @param string $description
293 * @param string $type
294 * @param string $options
295 *
296 * @return bool|int
297 */
298 public static function update_profile_field($id, $label_name, $key, $description, $type, $options)
299 {
300 global $wpdb;
301
302 return $wpdb->update(
303 Base::profile_fields_db_table(),
304 [
305 'label_name' => $label_name,
306 'field_key' => $key,
307 'description' => $description,
308 'type' => $type,
309 'options' => $options,
310 ],
311 ['id' => $id],
312 [
313 '%s',
314 '%s',
315 '%s',
316 '%s',
317 '%s',
318
319 ],
320 ['%d']
321 );
322 }
323
324
325 /***
326 * Mark a select field as multi selectable.
327 *
328 * @param string $key
329 *
330 * @param int $id must have a value.
331 *
332 * @return bool
333 */
334 public static function add_multi_selectable($key, $id = 0)
335 {
336 $old_data = get_option('ppress_cpf_select_multi_selectable', array());
337 $new_data = [$key => $id];
338
339 return update_option(
340 'ppress_cpf_select_multi_selectable',
341 array_merge($old_data, $new_data)
342 );
343 }
344
345 /***
346 * Remove a select field as multi selectable.
347 *
348 * @param string $key
349 *
350 * @return bool
351 */
352 public static function delete_multi_selectable($key)
353 {
354 $old_data = get_option('ppress_cpf_select_multi_selectable', array());
355 unset($old_data[$key]);
356
357 return update_option('ppress_cpf_select_multi_selectable', array_unique($old_data));
358 }
359
360 /**
361 * get radio buttons options of an added custom field
362 */
363 public static function get_field_option_values($field_key)
364 {
365 if ( ! ExtensionManager::is_premium()) return '';
366
367 global $wpdb;
368
369 $table = Base::profile_fields_db_table();
370
371 return $wpdb->get_var(
372 $wpdb->prepare("SELECT options FROM $table WHERE field_key = %s", $field_key)
373 );
374 }
375
376 /**
377 * Get radio buttons options of an added custom field
378 */
379 public static function get_field_label($field_key)
380 {
381 if ( ! ExtensionManager::is_premium()) return '';
382
383 global $wpdb;
384
385 $table = Base::profile_fields_db_table();
386
387 return $wpdb->get_var($wpdb->prepare("SELECT label_name FROM $table WHERE field_key = %s", $field_key));
388 }
389
390 public static function get_field_type($field_key)
391 {
392 if ( ! ExtensionManager::is_premium()) return '';
393
394 global $wpdb;
395
396 $table = Base::profile_fields_db_table();
397
398 return $wpdb->get_var($wpdb->prepare("SELECT type FROM $table WHERE field_key = %s", $field_key));
399 }
400
401 public static function get_contact_info_fields()
402 {
403 return get_option(PPRESS_CONTACT_INFO_OPTION_NAME, []);
404 }
405
406 public static function get_contact_info_field_label($field_key)
407 {
408 return ppress_var(self::get_contact_info_fields(), $field_key);
409 }
410
411 /** One time Passwordless login */
412 public static function passwordless_insert_record($user_id, $token, $expiration)
413 {
414 global $wpdb;
415
416 $table = Base::passwordless_login_db_table();
417
418 // check if a passwordless record already exist for the user
419 // if true update the row else add a new row record.
420 $id = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $table WHERE user_id = %d", $user_id));
421
422 if (is_null($id)) {
423
424 $prepared_statement = $wpdb->prepare(
425 "
426 INSERT INTO $table
427 ( user_id, token, expires )
428 VALUES ( %d, %s, %d )
429 ",
430 array(
431 $user_id,
432 $token,
433 $expiration,
434 )
435 );
436 } else {
437 $prepared_statement = $wpdb->prepare(
438 "
439 UPDATE $table
440 SET token = %s, expires = %d
441 WHERE user_id = %d
442 ",
443 array(
444 $token,
445 $expiration,
446 $user_id,
447 )
448 );
449 }
450
451 return $wpdb->query($prepared_statement);
452 }
453
454 /**
455 * Delete OTP record for a user.
456 *
457 * @param int $user_id
458 *
459 * @return false|int
460 */
461 public static function passwordless_delete_record($user_id)
462 {
463 global $wpdb;
464
465 return $wpdb->delete(Base::passwordless_login_db_table(), array('user_id' => $user_id), array('%d'));
466 }
467
468 /**
469 * Get the passwordless token of a user by ID
470 *
471 * @param int $user_id ID of user
472 *
473 * @return null|string
474 */
475 public static function passwordless_get_user_token($user_id)
476 {
477 global $wpdb;
478
479 $table = Base::passwordless_login_db_table();
480
481 return $wpdb->get_var($wpdb->prepare("SELECT token FROM $table WHERE user_id = %d", $user_id));
482 }
483
484 /**
485 * Get the expiration time
486 *
487 * @param int $user_id
488 *
489 * @return null|string
490 */
491 public static function passwordless_get_expiration($user_id)
492 {
493 global $wpdb;
494
495 $table = Base::passwordless_login_db_table();
496
497 return $wpdb->get_var($wpdb->prepare("SELECT expires FROM $table WHERE user_id = %d", $user_id));
498 }
499 }
500