PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.2.2
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.2.2
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 5 years ago FileUploader.php 4 years ago FormPreviewHandler.php 5 years ago FormRepository.php 4 years ago FormShortcodeDefaults.php 5 years ago GDPR.php 5 years ago GlobalSiteAccess.php 4 years ago ImageUploader.php 4 years ago LoginAuth.php 4 years ago Miscellaneous.php 5 years ago ModifyRedirectDefaultLinks.php 4 years ago PPRESS_Session.php 4 years ago PROFILEPRESS_sql.php 5 years ago PasswordReset.php 5 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 5 years ago UsernameEmailRestrictLogin.php 5 years ago WelcomeEmailAfterSignup.php 5 years ago default-email-template.php 5 years ago index.php 5 years ago
PROFILEPRESS_sql.php
473 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 /**
116 * Query for profile placement if user can view the his profile
117 *
118 * @return mixed
119 */
120 public static function get_profile_custom_fields()
121 {
122 global $wpdb;
123
124 return $wpdb->get_results(
125 sprintf("SELECT * FROM %s ORDER BY id", Base::profile_fields_db_table()),
126 'ARRAY_A'
127 );
128 }
129
130 /**
131 * Retrieve the profile field row of an ID
132 *
133 * @param int $id
134 *
135 * @return array
136 */
137 public static function get_profile_custom_field_by_id($id)
138 {
139 global $wpdb;
140
141 $table = Base::profile_fields_db_table();
142
143 return $wpdb->get_row(
144 $wpdb->prepare("SELECT * FROM $table WHERE id = %d", $id),
145 'ARRAY_A'
146 );
147 }
148
149 /**
150 * Retrieve the profile custom field by field key
151 *
152 * @param $field_key
153 *
154 * @return array
155 */
156 public static function get_profile_custom_field_by_key($field_key)
157 {
158 global $wpdb;
159
160 $table = Base::profile_fields_db_table();
161
162 return $wpdb->get_row(
163 $wpdb->prepare("SELECT * FROM $table WHERE field_key = %s", $field_key),
164 'ARRAY_A'
165 );
166 }
167
168 public static function get_profile_custom_fields_by_types($types)
169 {
170 global $wpdb;
171
172 $sql = sprintf("SELECT * FROM %s", Base::profile_fields_db_table());
173
174 $sql .= " WHERE type IN(" . implode(', ', array_fill(0, count($types), '%s')) . ")";
175
176 $sql = call_user_func_array([$wpdb, 'prepare'], array_merge([$sql], $types));
177
178 return $wpdb->get_results($sql);
179 }
180
181 public static function delete_profile_custom_field($id)
182 {
183 global $wpdb;
184
185 $delete_sql = $wpdb->delete(
186 Base::profile_fields_db_table(),
187 ['id' => $id],
188 ['%d']
189 );
190
191 return $delete_sql;
192 }
193
194 /**
195 * Return a list of created custom profile IDs.
196 *
197 * @return array
198 */
199 public static function get_profile_field_ids()
200 {
201 global $wpdb;
202
203 $table = Base::profile_fields_db_table();
204
205 return $wpdb->get_col("SELECT id FROM $table ORDER BY id");
206 }
207
208 /**
209 * Check if a profile field's key exist in the database.
210 *
211 * @param int $field_key
212 *
213 * @return bool
214 */
215 public static function is_profile_field_key_exist($field_key)
216 {
217 global $wpdb;
218
219 $table = Base::profile_fields_db_table();
220
221 $response = $wpdb->get_var(
222 $wpdb->prepare("SELECT id FROM $table WHERE field_key = %s", $field_key)
223 );
224
225 return ! is_null($response);
226 }
227
228 /**
229 * Add custom field to DB
230 *
231 * @param string $label_name
232 * @param string $key
233 * @param string $description
234 * @param string $type
235 * @param string $options
236 *
237 * @return bool|int
238 */
239 public static function add_profile_field($label_name, $key, $description, $type, $options)
240 {
241 global $wpdb;
242
243 $insert = $wpdb->insert(
244 Base::profile_fields_db_table(),
245 array(
246 'label_name' => $label_name,
247 'field_key' => $key,
248 'description' => $description,
249 'type' => $type,
250 'options' => $options,
251 ),
252 array(
253 '%s',
254 '%s',
255 '%s',
256 '%s',
257 '%s',
258 )
259 );
260
261 return ! $insert ? false : $wpdb->insert_id;
262 }
263
264
265 /**
266 * Update custom field in DB
267 *
268 * @param $id
269 * @param string $label_name
270 * @param string $key
271 * @param string $description
272 * @param string $type
273 * @param string $options
274 *
275 * @return bool|int
276 */
277 public static function update_profile_field($id, $label_name, $key, $description, $type, $options)
278 {
279 global $wpdb;
280
281 return $wpdb->update(
282 Base::profile_fields_db_table(),
283 [
284 'label_name' => $label_name,
285 'field_key' => $key,
286 'description' => $description,
287 'type' => $type,
288 'options' => $options,
289 ],
290 ['id' => $id],
291 [
292 '%s',
293 '%s',
294 '%s',
295 '%s',
296 '%s',
297
298 ],
299 ['%d']
300 );
301 }
302
303
304 /***
305 * Mark a select field as multi selectable.
306 *
307 * @param string $key
308 *
309 * @param int $id must have a value.
310 *
311 * @return bool
312 */
313 public static function add_multi_selectable($key, $id = 0)
314 {
315 $old_data = get_option('ppress_cpf_select_multi_selectable', array());
316 $new_data = [$key => $id];
317
318 return update_option(
319 'ppress_cpf_select_multi_selectable',
320 array_merge($old_data, $new_data)
321 );
322 }
323
324 /***
325 * Remove a select field as multi selectable.
326 *
327 * @param string $key
328 *
329 * @return bool
330 */
331 public static function delete_multi_selectable($key)
332 {
333 $old_data = get_option('ppress_cpf_select_multi_selectable', array());
334 unset($old_data[$key]);
335
336 return update_option('ppress_cpf_select_multi_selectable', array_unique($old_data));
337 }
338
339 /**
340 * get radio buttons options of an added custom field
341 */
342 public static function get_field_option_values($field_key)
343 {
344 global $wpdb;
345
346 $table = Base::profile_fields_db_table();
347
348 return $wpdb->get_var(
349 $wpdb->prepare("SELECT options FROM $table WHERE field_key = %s", $field_key)
350 );
351 }
352
353 /**
354 * Get radio buttons options of an added custom field
355 */
356 public static function get_field_label($field_key)
357 {
358 global $wpdb;
359
360 $table = Base::profile_fields_db_table();
361
362 return $wpdb->get_var($wpdb->prepare("SELECT label_name FROM $table WHERE field_key = %s", $field_key));
363 }
364
365 public static function get_field_type($field_key)
366 {
367 global $wpdb;
368
369 $table = Base::profile_fields_db_table();
370
371 return $wpdb->get_var($wpdb->prepare("SELECT type FROM $table WHERE field_key = %s", $field_key));
372 }
373
374 public static function get_contact_info_fields()
375 {
376 return get_option(PPRESS_CONTACT_INFO_OPTION_NAME, []);
377 }
378
379 public static function get_contact_info_field_label($field_key)
380 {
381 return ppress_var(self::get_contact_info_fields(), $field_key);
382 }
383
384 /** One time Passwordless login */
385 public static function passwordless_insert_record($user_id, $token, $expiration)
386 {
387 global $wpdb;
388
389 $table = Base::passwordless_login_db_table();
390
391 // check if a passwordless record already exist for the user
392 // if true update the row else add a new row record.
393 $id = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $table WHERE user_id = %d", $user_id));
394
395 if (is_null($id)) {
396
397 $prepared_statement = $wpdb->prepare(
398 "
399 INSERT INTO $table
400 ( user_id, token, expires )
401 VALUES ( %d, %s, %d )
402 ",
403 array(
404 $user_id,
405 $token,
406 $expiration,
407 )
408 );
409 } else {
410 $prepared_statement = $wpdb->prepare(
411 "
412 UPDATE $table
413 SET token = %s, expires = %d
414 WHERE user_id = %d
415 ",
416 array(
417 $token,
418 $expiration,
419 $user_id,
420 )
421 );
422 }
423
424 return $wpdb->query($prepared_statement);
425 }
426
427 /**
428 * Delete OTP record for a user.
429 *
430 * @param int $user_id
431 *
432 * @return false|int
433 */
434 public static function passwordless_delete_record($user_id)
435 {
436 global $wpdb;
437
438 return $wpdb->delete(Base::passwordless_login_db_table(), array('user_id' => $user_id), array('%d'));
439 }
440
441 /**
442 * Get the passwordless token of a user by ID
443 *
444 * @param int $user_id ID of user
445 *
446 * @return null|string
447 */
448 public static function passwordless_get_user_token($user_id)
449 {
450 global $wpdb;
451
452 $table = Base::passwordless_login_db_table();
453
454 return $wpdb->get_var($wpdb->prepare("SELECT token FROM $table WHERE user_id = %d", $user_id));
455 }
456
457 /**
458 * Get the expiration time
459 *
460 * @param int $user_id
461 *
462 * @return null|string
463 */
464 public static function passwordless_get_expiration($user_id)
465 {
466 global $wpdb;
467
468 $table = Base::passwordless_login_db_table();
469
470 return $wpdb->get_var($wpdb->prepare("SELECT expires FROM $table WHERE user_id = %d", $user_id));
471 }
472 }
473