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 / helpers / misc.php

misc.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.0.23, at includes/helpers/misc.php

1,753 lines 55.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Converts string value to options array.
4 * Used in select, multiselect and radio fields.
5 * Wraps inside optgroup if available.
6 *
7 * @since 1.0.0
8 * @package userswp
9 *
10 * @param string $option_values String option values.
11 * @param bool $translated Do you want to translate the output?
12 *
13 * @return array|null Options array.
14 */
15 function uwp_string_values_to_options($option_values = '', $translated = false)
16 {
17 $options = array();
18 if ($option_values == '') {
19 return NULL;
20 }
21
22 if (strpos($option_values, "{/optgroup}") !== false) {
23 $option_values_arr = explode("{/optgroup}", $option_values);
24
25 foreach ($option_values_arr as $optgroup) {
26 if (strpos($optgroup, "{optgroup}") !== false) {
27 $optgroup_arr = explode("{optgroup}", $optgroup);
28
29 $count = 0;
30 foreach ($optgroup_arr as $optgroup_str) {
31 $count++;
32 $optgroup_str = trim($optgroup_str);
33
34 $optgroup_label = '';
35 if (strpos($optgroup_str, "|") !== false) {
36 $optgroup_str_arr = explode("|", $optgroup_str, 2);
37 $optgroup_label = trim($optgroup_str_arr[0]);
38 if ($translated && $optgroup_label != '') {
39 $optgroup_label = __($optgroup_label, 'userswp');
40 }
41 $optgroup_label = ucfirst($optgroup_label);
42 $optgroup_str = $optgroup_str_arr[1];
43 }
44
45 $optgroup3 = uwp_string_to_options($optgroup_str, $translated);
46
47 if ($count > 1 && $optgroup_label != '' && !empty($optgroup3)) {
48 $optgroup_start = array(array('label' => $optgroup_label, 'value' => NULL, 'optgroup' => 'start'));
49 $optgroup_end = array(array('label' => $optgroup_label, 'value' => NULL, 'optgroup' => 'end'));
50 $optgroup3 = array_merge($optgroup_start, $optgroup3, $optgroup_end);
51 }
52 $options = array_merge($options, $optgroup3);
53 }
54 } else {
55 $optgroup1 = uwp_string_to_options($optgroup, $translated);
56 $options = array_merge($options, $optgroup1);
57 }
58 }
59 } else {
60 $options = uwp_string_to_options($option_values, $translated);
61 }
62
63 return $options;
64 }
65
66 /**
67 * Converts string value to options array.
68 * Used in select, multiselect and radio fields.
69 *
70 * @since 1.0.0
71 * @package userswp
72 *
73 * @param string $input Input String
74 * @param bool $translated Do you want to translate the output?
75 *
76 * @return array Options array.
77 */
78 function uwp_string_to_options($input = '', $translated = false)
79 {
80 $return = array();
81 if ($input != '') {
82 $input = trim($input);
83 $input = rtrim($input, ",");
84 $input = ltrim($input, ",");
85 $input = trim($input);
86 }
87
88 $input_arr = explode(',', $input);
89
90 if (!empty($input_arr)) {
91 foreach ($input_arr as $input_str) {
92 $input_str = trim($input_str);
93
94 if (strpos($input_str, "/") !== false) {
95 $input_str = explode("/", $input_str, 2);
96 $label = trim($input_str[0]);
97 if ($translated && $label != '') {
98 $label = __($label, 'userswp');
99 }
100 $label = ucfirst($label);
101 $value = trim($input_str[1]);
102 } else {
103 if ($translated && $input_str != '') {
104 $input_str = __($input_str, 'userswp');
105 }
106 $label = ucfirst($input_str);
107 $value = $input_str;
108 }
109
110 if ($label != '') {
111 $return[] = array('label' => $label, 'value' => $value, 'optgroup' => NULL);
112 }
113 }
114 }
115
116 return $return;
117 }
118
119
120 /**
121 * Resizes the image.
122 *
123 * @since 1.0.0
124 * @package userswp
125 *
126 * @param string $image Reference a local file
127 * @param int $width Image width
128 * @param int $height Image height
129 * @param float $scale Image scale ratio.
130 *
131 * @return mixed Resized image.
132 */
133 function uwp_resizeImage($image,$width,$height,$scale) {
134 /** @noinspection PhpUnusedLocalVariableInspection */
135 list($imagewidth, $imageheight, $imageType) = getimagesize($image);
136 $imageType = image_type_to_mime_type($imageType);
137 $newImageWidth = ceil($width * $scale);
138 $newImageHeight = ceil($height * $scale);
139 $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
140 $source = false;
141 switch($imageType) {
142 case "image/gif":
143 $source=imagecreatefromgif($image);
144 break;
145 case "image/pjpeg":
146 case "image/jpeg":
147 case "image/jpg":
148 $source=imagecreatefromjpeg($image);
149 break;
150 case "image/png":
151 case "image/x-png":
152 $source=imagecreatefrompng($image);
153 break;
154 }
155 imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
156
157 switch($imageType) {
158 case "image/gif":
159 imagegif($newImage,$image);
160 break;
161 case "image/pjpeg":
162 case "image/jpeg":
163 case "image/jpg":
164 imagejpeg($newImage,$image,90);
165 break;
166 case "image/png":
167 case "image/x-png":
168 imagepng($newImage,$image);
169 break;
170 }
171
172 chmod($image, 0777);
173 return $image;
174 }
175
176 /**
177 * Resizes thumbnail image.
178 *
179 * @since 1.0.0
180 * @package userswp
181 *
182 * @param string $thumb_image_name
183 * @param string $image
184 * @param int $x x-coordinate of source point.
185 * @param int $y y-coordinate of source point.
186 * @param int $src_w Source width.
187 * @param int $src_h Source height.
188 * @param float $scale Image scale ratio.
189 *
190 * @return mixed Resized image.
191 */
192 function uwp_resizeThumbnailImage($thumb_image_name, $image, $x, $y, $src_w, $src_h, $scale){
193 // ignore image createion warnings
194 @ini_set('gd.jpeg_ignore_warning', 1);
195 /** @noinspection PhpUnusedLocalVariableInspection */
196 list($imagewidth, $imageheight, $imageType) = getimagesize($image);
197 $imageType = image_type_to_mime_type($imageType);
198
199 $newImageWidth = ceil($src_w * $scale);
200 $newImageHeight = ceil($src_h * $scale);
201 $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
202 $source = false;
203 switch($imageType) {
204 case "image/gif":
205 $source=imagecreatefromgif($image);
206 break;
207 case "image/pjpeg":
208 case "image/jpeg":
209 case "image/jpg":
210 $source=imagecreatefromjpeg($image);
211 break;
212 case "image/png":
213 case "image/x-png":
214 $source=imagecreatefrompng($image);
215 break;
216 }
217 imagecopyresampled($newImage,$source,0,0,$x,$y,$newImageWidth, $newImageHeight, $src_w, $src_h);
218 switch($imageType) {
219 case "image/gif":
220 imagegif($newImage, $thumb_image_name);
221 break;
222 case "image/pjpeg":
223 case "image/jpeg":
224 case "image/jpg":
225 imagejpeg($newImage, $thumb_image_name, 100);
226 break;
227 case "image/png":
228 case "image/x-png":
229 imagepng($newImage, $thumb_image_name);
230 break;
231 }
232
233 chmod($thumb_image_name, 0777);
234 return $thumb_image_name;
235 }
236
237
238 /**
239 * Logs the error message.
240 *
241 * @since 1.0.0
242 * @package userswp
243 *
244 * @param array|object|string $log Error message.
245 *
246 * @return void
247 */
248 function uwp_error_log($log){
249 /*
250 * A filter to override the WP_DEBUG setting for function uwp_error_log().
251 */
252 $should_log = apply_filters( 'uwp_log_errors', WP_DEBUG);
253 if ( true === $should_log ) {
254 if ( is_array( $log ) || is_object( $log ) ) {
255 error_log( print_r( $log, true ) );
256 } else {
257 error_log( $log );
258 }
259 }
260 }
261
262
263 /**
264 * Prints the users page main content.
265 *
266 * @since 1.0.0
267 * @package userswp
268 *
269 * @return void
270 */
271 function get_uwp_users_list() {
272
273 global $wpdb;
274
275 $keyword = false;
276 if (isset($_GET['uwps']) && $_GET['uwps'] != '') {
277 $keyword = stripslashes(strip_tags($_GET['uwps']));
278 }
279
280 $sort_by = false;
281 if (isset($_GET['uwp_sort_by']) && $_GET['uwp_sort_by'] != '') {
282 $sort_by = strip_tags(esc_sql($_GET['uwp_sort_by']));
283 }
284
285 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
286
287 $number = uwp_get_option('profile_no_of_items', 10);
288
289 $where = '';
290 $where = apply_filters('uwp_users_search_where', $where, $keyword);
291
292 $arg = array(
293 'fields' => 'ID',
294 'meta_query' => array(
295 'relation' => 'OR',
296 array(
297 'key' => 'uwp_mod',
298 'value' => 'email_unconfirmed',
299 'compare' => '=='
300 ),
301 array(
302 'key' => 'uwp_hide_from_listing',
303 'value' => 1,
304 'compare' => '=='
305 )
306 )
307 );
308
309 $inactive_users = new WP_User_Query($arg);
310 $exclude_users = $inactive_users->get_results();
311
312 $excluded_globally = uwp_get_option('users_excluded_from_list');
313 if ( $excluded_globally ) {
314 $users = str_replace(' ', '', $excluded_globally );
315 $users_array = explode(',', $users );
316 $exclude_users = array_merge($exclude_users, $users_array);
317 }
318
319 $exclude_users = apply_filters('uwp_excluded_users_from_list', $exclude_users, $where, $keyword);
320
321 if($exclude_users){
322 $exclude_users_list = implode(',', array_unique($exclude_users));
323 $exclude_query = 'AND '. $wpdb->users.'.ID NOT IN ('.$exclude_users_list.')';
324 } else {
325 $exclude_query = ' ';
326 }
327
328 if ($keyword || $where) {
329 if (empty($where)) {
330 $users = $wpdb->get_results($wpdb->prepare(
331 "SELECT DISTINCT SQL_CALC_FOUND_ROWS $wpdb->users.*
332 FROM $wpdb->users
333 INNER JOIN $wpdb->usermeta
334 ON ( $wpdb->users.ID = $wpdb->usermeta.user_id )
335 WHERE 1=1
336 $exclude_query
337 AND (
338 ( $wpdb->usermeta.meta_key = 'first_name' AND $wpdb->usermeta.meta_value LIKE %s )
339 OR
340 ( $wpdb->usermeta.meta_key = 'last_name' AND $wpdb->usermeta.meta_value LIKE %s )
341 OR
342 user_login LIKE %s
343 OR
344 user_nicename LIKE %s
345 OR
346 display_name LIKE %s
347 OR
348 user_email LIKE %s
349 )
350 ORDER BY display_name ASC
351 LIMIT 0, 20",
352 array(
353 '%' . $keyword . '%',
354 '%' . $keyword . '%',
355 '%' . $keyword . '%',
356 '%' . $keyword . '%',
357 '%' . $keyword . '%',
358 '%' . $keyword . '%'
359 )
360 ));
361 } else {
362 $usermeta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
363
364 $users = $wpdb->get_results(
365 "SELECT DISTINCT SQL_CALC_FOUND_ROWS $wpdb->users.*
366 FROM $wpdb->users
367 INNER JOIN $usermeta_table
368 ON ( $wpdb->users.ID = $usermeta_table.user_id )
369 WHERE 1=1
370 $exclude_query
371 $where
372 ORDER BY display_name ASC
373 LIMIT 0, 20");
374 }
375
376 $total_user = count($users);
377
378 } else {
379
380 $args = array(
381 'number' => (int) $number,
382 'paged' => $paged,
383 'exclude' => $exclude_users,
384 );
385
386
387 if ($sort_by) {
388 switch ($sort_by) {
389 case "newer":
390 $args['orderby'] = 'registered';
391 $args['order'] = 'desc';
392 break;
393 case "older":
394 $args['orderby'] = 'registered';
395 $args['order'] = 'asc';
396 break;
397 case "alpha_asc":
398 $args['orderby'] = 'display_name';
399 $args['order'] = 'asc';
400 break;
401 case "alpha_desc":
402 $args['orderby'] = 'display_name';
403 $args['order'] = 'desc';
404 break;
405
406 }
407 }
408
409 $users_query = new WP_User_Query($args);
410 $users = $users_query->get_results();
411 $total_user = $users_query->get_total();
412
413 }
414
415 $total_pages=ceil($total_user/$number);
416
417 $layout_class = uwp_get_layout_class();
418 ?>
419 <ul class="uwp-users-list-wrap <?php echo $layout_class; ?>" id="uwp_user_items_layout">
420 <?php
421 if ($users) {
422 foreach ($users as $user) {
423 $user_obj = get_user_by('id', $user->ID);
424
425 // exclude logged in user
426 $exclude_loggedin_user = apply_filters('uwp_users_list_exclude_loggedin_user', false);
427 if ($exclude_loggedin_user) {
428 if ($user_obj->ID == get_current_user_id()) {
429 continue;
430 }
431 }
432 ?>
433 <li class="uwp-users-list-user">
434 <div class="uwp-users-list-user-left">
435 <?php do_action('uwp_users_profile_header', $user); ?>
436 </div>
437 <div class="uwp-users-list-user-right">
438 <div class="uwp-users-list-user-name">
439 <h3 class="uwp-user-title" data-user="<?php echo $user_obj->ID; ?>">
440 <a href="<?php echo apply_filters('uwp_profile_link', get_author_posts_url($user_obj->ID), $user_obj->ID); ?>">
441 <?php echo apply_filters('uwp_profile_display_name', $user_obj->display_name); ?>
442 </a>
443 <?php do_action('uwp_users_after_title', $user_obj->ID ); ?>
444 </h3>
445 </div>
446 <div class="uwp-users-list-user-btns">
447 <?php do_action('uwp_profile_buttons', $user_obj ); ?>
448 </div>
449 <div class="uwp-users-list-user-social">
450 <?php do_action('uwp_profile_social', $user_obj ); ?>
451 </div>
452 <div class="uwp-users-list-extra">
453 <?php do_action('uwp_users_extra', $user_obj ); ?>
454 </div>
455 <div class="clfx"></div>
456 </div>
457 </li>
458 <?php
459 }
460 } else {
461 // no users found
462 echo '<div class="uwp-alert-error text-center">';
463 echo __('No Users Found', 'userswp');
464 echo '</div>';
465 }
466 ?>
467 </ul>
468
469 <?php
470 if ($total_pages > 1) {
471 do_action('uwp_profile_pagination', $total_pages);
472 }
473 ?>
474 <?php
475 }
476
477 /**
478 * Gets the custom field info for given key.
479 *
480 * @since 1.0.0
481 * @package userswp
482 *
483 * @param string $htmlvar_name Custom field key.
484 *
485 * @return object Field info.
486 */
487 function uwp_get_custom_field_info($htmlvar_name) {
488 global $wpdb;
489 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
490 $field = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE htmlvar_name = %s", array($htmlvar_name)));
491 return $field;
492 }
493
494
495
496 /**
497 * Returns the Users page layout class based on the setting.
498 *
499 * @since 1.0.0
500 * @package userswp
501 *
502 * @return string Layout class.
503 */
504 function uwp_get_layout_class() {
505 $default_layout = uwp_get_option('users_default_layout', 'list');
506 switch ($default_layout) {
507 case "list":
508 $class = "uwp_listview";
509 break;
510 case "2col":
511 $class = "uwp_gridview uwp_gridview_2col";
512 break;
513 case "3col":
514 $class = "uwp_gridview uwp_gridview_3col";
515 break;
516 case "4col":
517 $class = "uwp_gridview uwp_gridview_4col";
518 break;
519 case "5col":
520 $class = "uwp_gridview uwp_gridview_5col";
521 break;
522 default:
523 $class = "uwp_listview";
524 }
525
526 return $class;
527 }
528
529 add_filter( 'get_user_option_metaboxhidden_nav-menus', 'uwp_always_nav_menu_visibility', 10, 3 );
530
531 /**
532 * Filters nav menu visibility option value.
533 *
534 * @since 1.0.0
535 * @package userswp
536 *
537 * @param mixed $result Value for the user's option.
538 * @param string $option Name of the option being retrieved.
539 * @param WP_User $user WP_User object of the user whose option is being retrieved.
540 *
541 * @return array Filtered value.
542 */
543 function uwp_always_nav_menu_visibility( $result, $option, $user )
544 {
545 if( is_array($result) && in_array( 'add-users-wp-nav-menu', $result ) ) {
546 $result = array_diff( $result, array( 'add-users-wp-nav-menu' ) );
547 }
548
549 return $result;
550 }
551
552 add_filter('user_profile_picture_description', 'uwp_admin_user_profile_picture_description');
553
554 /**
555 * Filters the user profile picture description displayed under the Gravatar.
556 *
557 * @since 1.0.0
558 * @package userswp
559 *
560 * @param string $description Profile picture description.
561 *
562 * @return string Modified description.
563 */
564 function uwp_admin_user_profile_picture_description($description) {
565 if (is_admin() && IS_PROFILE_PAGE) {
566 $user_id = get_current_user_id();
567 $avatar = uwp_get_usermeta($user_id, 'uwp_account_avatar_thumb', '');
568
569 if (!empty($avatar)) {
570 $description = sprintf( __( 'You can change your profile picture on your <a href="%s">Profile Page</a>.', 'userswp' ),
571 uwp_build_profile_tab_url( $user_id ));
572 }
573
574 }
575 return $description;
576 }
577
578 /**
579 * Adds avatar and banner fields in admin side.
580 *
581 * @since 1.0.0
582 * @package userswp
583 *
584 * @param object $user User object.
585 *
586 * @return void
587 */
588 function uwp_admin_edit_banner_fields($user) {
589 global $wpdb;
590
591 $file_obj = new UsersWP_Files();
592
593 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
594 $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE (form_type = 'avatar' OR form_type = 'banner') ORDER BY sort_order ASC");
595 if ($fields) {
596 ?>
597 <div class="uwp-profile-extra uwp_page">
598 <?php do_action('uwp_admin_profile_edit', $user ); ?>
599 <table class="uwp-profile-extra-table form-table">
600 <?php
601 foreach ($fields as $field) {
602
603 // Icon
604 $icon = uwp_get_field_icon( $field->field_icon );
605
606 if ($field->field_type == 'fieldset') {
607 ?>
608 <tr style="margin: 0; padding: 0">
609 <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3 style="margin: 10px 0;">
610 <?php echo $icon.$field->site_title; ?></h3></th>
611 <td></td>
612 </tr>
613 <?php
614 } else { ?>
615 <tr>
616 <th class="uwp-profile-extra-key"><?php echo $icon.$field->site_title; ?></th>
617 <td class="uwp-profile-extra-value">
618 <?php
619 if ($field->htmlvar_name == "uwp_avatar_file") {
620 $value = uwp_get_usermeta($user->ID, "uwp_account_avatar_thumb", "");
621 } elseif ($field->htmlvar_name == "uwp_banner_file") {
622 $value = uwp_get_usermeta($user->ID, "uwp_account_banner_thumb", "");
623 } else {
624 $value = "";
625 }
626 ?>
627 <?php echo $file_obj->uwp_file_upload_preview($field, $value); ?>
628 <?php
629 if ($field->htmlvar_name == "uwp_avatar_file") {
630 if (!empty($value)) {
631 ?>
632 <a class="uwp-profile-modal-form-trigger" data-type="avatar" href="#">
633 <?php echo __("Change Avatar", "userswp"); ?>
634 </a>
635 <?php
636 } else {
637 ?>
638 <a class="uwp-profile-modal-form-trigger" data-type="avatar" href="#">
639 <?php echo __("Upload Avatar", "userswp"); ?>
640 </a>
641 <?php
642 }
643 } elseif ($field->htmlvar_name == "uwp_banner_file") {
644 if (!empty($value)) {
645 ?>
646 <a class="uwp-profile-modal-form-trigger" data-type="banner" href="#">
647 <?php echo __("Change Banner", "userswp"); ?>
648 </a>
649 <?php
650 } else {
651 ?>
652 <a class="uwp-profile-modal-form-trigger" data-type="banner" href="#">
653 <?php echo __("Upload Banner", "userswp"); ?>
654 </a>
655 <?php
656 }
657 }
658 ?>
659 </td>
660 </tr>
661 <?php
662 }
663 }
664 ?>
665 </table>
666 </div>
667 <?php
668 }
669 }
670 add_action('show_user_profile', 'uwp_admin_edit_banner_fields');
671 add_action('edit_user_profile', 'uwp_admin_edit_banner_fields');
672
673 add_filter('admin_body_class', 'uwp_add_admin_body_class');
674 function uwp_add_admin_body_class($classes) {
675 $screen = get_current_screen();
676 if ( 'profile' == $screen->base || 'user-edit' == $screen->base )
677 $classes .= 'uwp_page';
678 return $classes;
679 }
680
681 // Privacy
682 add_filter('uwp_account_page_title', 'uwp_account_privacy_page_title', 10, 2);
683
684 /**
685 * Adds Privacy tab title in Account page.
686 *
687 * @since 1.0.0
688 * @package userswp
689 *
690 * @param string $title Privacy title.
691 * @param string $type Tab type.
692 *
693 * @return string|void Title.
694 */
695 function uwp_account_privacy_page_title($title, $type) {
696 if ($type == 'privacy') {
697 $title = __( 'Privacy', 'userswp' );
698 }
699
700 return $title;
701 }
702
703 add_action('uwp_account_form_display', 'uwp_account_privacy_edit_form_display');
704
705 /**
706 * Adds form html for privacy fields in account page.
707 *
708 * @since 1.0.0
709 * @package userswp
710 *
711 * @param string $type Form type.
712 *
713 * @return void
714 */
715 function uwp_account_privacy_edit_form_display($type) {
716 if ($type == 'privacy') {
717 $make_profile_private = uwp_can_make_profile_private();
718 echo '<div class="uwp-account-form uwp_wc_form">';
719 $extra_where = "AND is_public='2'";
720 $fields = get_account_form_fields($extra_where);
721 $fields = apply_filters('uwp_account_privacy_fields', $fields);
722 $user_id = get_current_user_id();
723 ?>
724 <div class="uwp-profile-extra">
725 <div class="uwp-profile-extra-div form-table">
726 <form class="uwp-account-form uwp_form" method="post">
727 <?php if ($fields) { ?>
728 <div class="uwp-profile-extra-wrap">
729 <div class="uwp-profile-extra-key" style="font-weight: bold;">
730 <?php echo __("Field", "userswp") ?>
731 </div>
732 <div class="uwp-profile-extra-value" style="font-weight: bold;">
733 <?php echo __("Is Public?", "userswp") ?>
734 </div>
735 </div>
736 <?php foreach ($fields as $field) { ?>
737 <div class="uwp-profile-extra-wrap">
738 <div class="uwp-profile-extra-key"><?php echo $field->site_title; ?>
739 <span class="uwp-profile-extra-sep">:</span></div>
740 <div class="uwp-profile-extra-value">
741 <?php
742 $field_name = $field->htmlvar_name . '_privacy';
743 $value = uwp_get_usermeta($user_id, $field_name, false);
744 if ($value === false) {
745 $value = 'yes';
746 }
747 ?>
748 <select name="<?php echo $field_name; ?>" class="uwp_privacy_field"
749 style="margin: 0;">
750 <option value="no" <?php selected($value, "no"); ?>><?php echo __("No", "userswp") ?></option>
751 <option value="yes" <?php selected($value, "yes"); ?>><?php echo __("Yes", "userswp") ?></option>
752 </select>
753 </div>
754 </div>
755 <?php }
756 }
757 $value = get_user_meta($user_id, 'uwp_hide_from_listing', true); ?>
758 <div class="uwp-profile-extra-wrap">
759 <div id="uwp_hide_from_listing" class="uwp_hide_from_listing">
760 <input name="uwp_hide_from_listing" class="" <?php checked($value, "1", true); ?> type="checkbox" value="1"><?php _e('Hide profile from the users listing page.', 'userswp'); ?>
761 </div>
762 </div>
763 <?php
764 do_action('uwp_after_privacy_form_fields', $fields);
765 if ($make_profile_private) {
766 $field_name = 'uwp_make_profile_private';
767 $value = get_user_meta($user_id, $field_name, true);
768 if ($value === false) {
769 $value = '0';
770 }
771 ?>
772 <div id="uwp_make_profile_private" class=" uwp_make_profile_private_row">
773 <input type="hidden" name="uwp_make_profile_private" value="0">
774 <input name="uwp_make_profile_private" class="" <?php checked( $value, "1", true ); ?> type="checkbox" value="1">
775 <?php _e( 'Make the whole profile private', 'userswp' ); ?>
776 </div>
777 <?php
778 }
779 ?>
780 <input type="hidden" name="uwp_privacy_nonce" value="<?php echo wp_create_nonce( 'uwp-privacy-nonce' ); ?>" />
781 <input name="uwp_privacy_submit" value="<?php echo __( 'Submit', 'userswp' ); ?>" type="submit">
782 </form>
783 </div>
784 </div>
785 <?php
786 echo '</div>';
787 }
788 }
789
790 add_action('uwp_account_menu_display', 'uwp_add_account_menu_links');
791
792 /**
793 * Prints "Edit account" page subtab / submenu links. Ex: Privacy
794 *
795 * @since 1.0.0
796 * @package userswp
797 *
798 * @return void
799 */
800 function uwp_add_account_menu_links() {
801
802 if (isset($_GET['type'])) {
803 $type = strip_tags(esc_sql($_GET['type']));
804 } else {
805 $type = 'account';
806 }
807
808 $account_page = uwp_get_page_id('account_page', false);
809 $account_page_link = get_permalink($account_page);
810
811 $account_available_tabs = uwp_account_get_available_tabs();
812
813 if (!is_array($account_available_tabs) && count($account_available_tabs) > 0) {
814 return;
815 }
816
817 echo '<ul class="uwp_account_menu">';
818
819 foreach( $account_available_tabs as $tab_id => $tab ) {
820
821 if ($tab_id == 'account') {
822 $tab_url = $account_page_link;
823 } else {
824 $tab_url = add_query_arg(array(
825 'type' => $tab_id,
826 ), $account_page_link);
827 }
828
829 if (isset($tab['link'])) {
830 $tab_url = $tab['link'];
831 }
832
833 $active = $type == $tab_id ? ' active' : '';
834 ?>
835 <li id="uwp-account-<?php echo $tab_id; ?>">
836 <a class="<?php echo $active; ?>" href="<?php echo esc_url( $tab_url ); ?>">
837 <i class="<?php echo $tab['icon']; ?>"></i> <?php echo $tab['title']; ?>
838 </a>
839 </li>
840 <?php
841 }
842
843 $template = new UsersWP_Templates();
844 $logout_url = $template->uwp_logout_url();
845 echo '<li id="uwp-account-logout"><a class="uwp-account-logout-link" href="'.$logout_url.'"><i class="fas fa-sign-out-alt"></i>'.__('Logout', 'userswp').'</a></li>';
846 echo '</ul>';
847 }
848
849
850
851
852 /**
853 * Updates extras fields sort order.
854 *
855 * @since 1.0.0
856 * @package userswp
857 *
858 * @param array $field_ids Form extras field ids.
859 * @param string $form_type Form type.
860 *
861 * @return array|bool Sorted field ids.
862 */
863 function uwp_form_extras_field_order($field_ids = array(), $form_type = 'register')
864 {
865 global $wpdb;
866 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
867
868 $count = 0;
869 if (!empty($field_ids)):
870 foreach ($field_ids as $id) {
871
872 $cf = trim($id, '_');
873
874 $wpdb->query(
875 $wpdb->prepare(
876 "update " . $extras_table_name . " set
877 sort_order=%d
878 where id= %d",
879 array($count, $cf)
880 )
881 );
882 $count++;
883 }
884
885 return $field_ids;
886 else:
887 return false;
888 endif;
889 }
890
891 /**
892 * Uppercase the first character of each word in a string.
893 *
894 * @since 1.0.0
895 * @package userswp
896 *
897 * @param string $string String to convert.
898 * @param string $charset Charset.
899 *
900 * @return string Converted string.
901 */
902 function uwp_ucwords($string, $charset='UTF-8') {
903 if (function_exists('mb_convert_case')) {
904 return mb_convert_case($string, MB_CASE_TITLE, $charset);
905 } else {
906 return ucwords($string);
907 }
908 }
909
910 /**
911 * Checks whether the column exists in the table.
912 *
913 * @since 1.0.0
914 * @package userswp
915 *
916 * @param string $db Table name.
917 * @param string $column Column name.
918 *
919 * @return bool
920 */
921 function uwp_column_exist($db, $column)
922 {
923 $table = new UsersWP_Tables();
924 return $table->column_exists($db, $column);
925 }
926
927 /**
928 * Adds column if not exist in the table.
929 *
930 * @since 1.0.0
931 * @package userswp
932 *
933 * @param string $db Table name.
934 * @param string $column Column name.
935 * @param string $column_attr Column attributes.
936 *
937 * @return bool|int True when success.
938 */
939 function uwp_add_column_if_not_exist($db, $column, $column_attr = "VARCHAR( 255 ) NOT NULL")
940 {
941 $table = new UsersWP_Tables();
942 return $table->add_column_if_not_exist($db, $column, $column_attr);
943
944 }
945
946 /**
947 * Returns excluded custom fields.
948 *
949 * @since 1.0.0
950 * @package userswp
951 *
952 * @return array Excluded custom fields.
953 */
954 function uwp_get_excluded_fields() {
955 $excluded = array(
956 'uwp_account_password',
957 'uwp_account_confirm_password',
958 );
959 return $excluded;
960 }
961
962 /**
963 * Formats the currency using currency separator.
964 *
965 * @since 1.0.0
966 * @package userswp
967 *
968 * @param string $number Currency number.
969 * @param array|string $cf Custom field info.
970 *
971 * @return string Formatted currency.
972 */
973 function uwp_currency_format_number($number='',$cf=''){
974
975 $cs = isset($cf['extra_fields']) ? maybe_unserialize($cf['extra_fields']) : '';
976
977 $symbol = isset($cs['currency_symbol']) ? $cs['currency_symbol'] : '$';
978 $decimals = isset($cf['decimal_point']) && $cf['decimal_point'] ? $cf['decimal_point'] : 2;
979 $decimal_display = isset($cf['decimal_display']) && $cf['decimal_display'] ? $cf['decimal_display'] : 'if';
980 $decimalpoint = '.';
981
982 if(isset($cs['decimal_separator']) && $cs['decimal_separator']=='comma'){
983 $decimalpoint = ',';
984 }
985
986 $separator = ',';
987
988 if(isset($cs['thousand_separator'])){
989 if($cs['thousand_separator']=='comma'){$separator = ',';}
990 if($cs['thousand_separator']=='slash'){$separator = '\\';}
991 if($cs['thousand_separator']=='period'){$separator = '.';}
992 if($cs['thousand_separator']=='space'){$separator = ' ';}
993 if($cs['thousand_separator']=='none'){$separator = '';}
994 }
995
996 $currency_symbol_placement = isset($cs['currency_symbol_placement']) ? $cs['currency_symbol_placement'] : 'left';
997
998 if($decimals>0 && $decimal_display=='if'){
999 if(is_int($number) || floor( $number ) == $number)
1000 $decimals = 0;
1001 }
1002
1003 $number = number_format($number,$decimals,$decimalpoint,$separator);
1004
1005
1006
1007 if($currency_symbol_placement=='left'){
1008 $number = $symbol . $number;
1009 }else{
1010 $number = $number . $symbol;
1011 }
1012
1013
1014 return $number;
1015 }
1016
1017
1018 /**
1019 * Checks whether the user can make his/her own profile private or not.
1020 *
1021 * @since 1.0.0
1022 * @package userswp
1023 *
1024 * @return bool
1025 */
1026 function uwp_can_make_profile_private() {
1027 $make_profile_private = apply_filters('uwp_user_can_make_profile_private', false);
1028 return $make_profile_private;
1029 }
1030
1031 /**
1032 * Returns available registration status options.
1033 *
1034 * @since 1.0.0
1035 * @package userswp
1036 *
1037 * @return array Registration status options.
1038 */
1039 function uwp_registration_status_options() {
1040 $registration_options = array(
1041 'auto_approve' => __('Auto approve', 'userswp'),
1042 'auto_approve_login' => __('Auto approve + Auto Login', 'userswp'),
1043 'require_email_activation' => __('Require Email Activation', 'userswp'),
1044 );
1045
1046 $registration_options = apply_filters('uwp_registration_status_options', $registration_options);
1047
1048 return $registration_options;
1049 }
1050
1051 /**
1052 * Retrieves a user row based on password reset key and login
1053 *
1054 * @since 1.0.0
1055 * @package userswp
1056 *
1057 * @param string $key Hash to validate sending user's password.
1058 * @param string $login The user login.
1059 *
1060 * @return WP_Error|WP_User User object.
1061 */
1062 function uwp_check_activation_key( $key, $login ) {
1063 $user_data = check_password_reset_key( $key, $login );
1064
1065 return $user_data;
1066 }
1067
1068
1069 add_action('uwp_template_fields', 'uwp_template_fields_terms_check', 100, 1);
1070
1071 /**
1072 * Adds "Accept terms and conditions" checkbox in register form.
1073 *
1074 * @since 1.0.0
1075 * @package userswp
1076 *
1077 * @param string $form_type Form type.
1078 *
1079 * @return void
1080 */
1081 function uwp_template_fields_terms_check($form_type) {
1082 if ($form_type == 'register') {
1083 $terms_page = false;
1084 $reg_terms_page_id = uwp_get_page_id('register_terms_page', false);
1085 $reg_terms_page_id = apply_filters('uwp_reg_terms_page_id', $reg_terms_page_id);
1086 if (!empty($reg_terms_page_id)) {
1087 $terms_page = get_permalink($reg_terms_page_id);
1088 }
1089 if ($terms_page) {
1090 ?>
1091 <div class="uwp-remember-me">
1092 <label style="display: inline-block;font-weight: normal" for="agree_terms">
1093 <input name="agree_terms" id="agree_terms" value="yes" type="checkbox">
1094 <?php echo sprintf( __( 'I Accept <a href="%s" target="_blank">Terms and Conditions</a>.', 'userswp' ), $terms_page); ?>
1095 </label>
1096 </div>
1097 <?php
1098 }
1099 }
1100 }
1101
1102
1103
1104 /**
1105 * Redirects the user to login page when email not confirmed.
1106 *
1107 * @since 1.0.0
1108 * @package userswp
1109 *
1110 * @param string $username Username.
1111 * @param object $user User object.
1112 *
1113 * @return void
1114 */
1115 function uwp_unconfirmed_login_redirect( $username, $user ) {
1116 if (!is_wp_error($user)) {
1117 $mod_value = get_user_meta( $user->ID, 'uwp_mod', true );
1118 if ($mod_value == 'email_unconfirmed') {
1119 if ( !in_array( 'administrator', $user->roles ) ) {
1120 $login_page = uwp_get_page_id('login_page', false);
1121 if ($login_page) {
1122 $redirect_to = add_query_arg(array('uwp_err' => 'act_pending'), get_permalink($login_page));
1123 wp_destroy_current_session();
1124 wp_clear_auth_cookie();
1125 wp_redirect($redirect_to);
1126 exit();
1127 }
1128 }
1129 }
1130 }
1131 }
1132 add_filter( 'wp_login', 'uwp_unconfirmed_login_redirect', 10, 2 );
1133
1134 /**
1135 * Adds notification menu in admin toolbar.
1136 *
1137 * @since 1.0.0
1138 * @package userswp
1139 *
1140 * @return void
1141 */
1142 function uwp_notifications_toolbar_menu() {
1143 global $wp_admin_bar;
1144
1145 if ( ! is_user_logged_in() ) {
1146 return;
1147 }
1148
1149 $available_counts = apply_filters('uwp_notifications_available_counts', array());
1150
1151 if (count($available_counts) == 0) {
1152 return;
1153 }
1154
1155 $total_count = 0;
1156 foreach ($available_counts as $key => $value) {
1157 $total_count = $total_count + $value;
1158 }
1159
1160
1161 $alert_class = (int) $total_count > 0 ? 'pending-count' : 'count';
1162 $menu_title = '<span id="uwp-notification-count" class="' . $alert_class . '">'
1163 . number_format_i18n( $total_count ) . '</span>';
1164 $menu_link = '';
1165
1166 // Add the top-level Notifications button.
1167 $wp_admin_bar->add_menu( array(
1168 'parent' => 'top-secondary',
1169 'id' => 'uwp-notifications',
1170 'title' => $menu_title,
1171 'href' => $menu_link,
1172 ) );
1173
1174 do_action('uwp_notifications_items', $wp_admin_bar);
1175
1176 return;
1177 }
1178 add_action( 'admin_bar_menu', 'uwp_notifications_toolbar_menu', 90 );
1179
1180 /**
1181 * Returns the installation type.
1182 *
1183 * @since 1.0.0
1184 * @package userswp
1185 *
1186 * @return string Installation type.
1187 */
1188 function uwp_get_installation_type() {
1189 // *. Single Site
1190 if (!is_multisite()) {
1191 return "single";
1192 } else {
1193 // Multisite
1194 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
1195 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
1196 }
1197
1198 // Network active.
1199 if ( is_plugin_active_for_network( 'userswp/userswp.php' ) ) {
1200 if (defined('UWP_ROOT_PAGES')) {
1201 if (UWP_ROOT_PAGES == 'all') {
1202 // *. Multisite - Network Active - Pages on all sites
1203 return "multi_na_all";
1204 } else {
1205 // *. Multisite - Network Active - Pages on specific site
1206 return "multi_na_site_id";
1207 }
1208 } else {
1209 // Multi - network active - default
1210 // *. Multisite - Network Active - Pages on main site
1211 return "multi_na_default";
1212 }
1213 } else {
1214 // * Multisite - Not network active
1215 return "multi_not_na";
1216 }
1217 }
1218 }
1219
1220 /**
1221 * Returns the table prefix based on the installation type.
1222 *
1223 * @since 1.0.0
1224 * @package userswp
1225 *
1226 * @return string Table prefix
1227 */
1228 function uwp_get_table_prefix() {
1229 $tables = new UsersWP_Tables();
1230 return $tables->get_table_prefix();
1231 }
1232
1233 /**
1234 * Returns the table prefix based on the installation type.
1235 *
1236 * @since 1.0.16
1237 * @package userswp
1238 *
1239 * @return string Table prefix
1240 */
1241 function get_usermeta_table_prefix() {
1242 $tables = new UsersWP_Tables();
1243 return $tables->get_usermeta_table_prefix();
1244 }
1245
1246
1247
1248 /**
1249 * Converts array to comma separated string.
1250 *
1251 *
1252 * @since 1.0.0
1253 * @package userswp
1254 *
1255 * @param string $key Custom field key.
1256 * @param string $value Custom field value.
1257 *
1258 * @return string Converted custom field value string.
1259 */
1260 function uwp_maybe_serialize($key, $value) {
1261 $field = uwp_get_custom_field_info($key);
1262 if (isset($field->field_type) && $field->field_type == 'multiselect') {
1263 $value = implode(",", $value);
1264 }
1265 return $value;
1266 }
1267
1268 /**
1269 * Converts comma separated string to array.
1270 *
1271 * @since 1.0.0
1272 * @package userswp
1273 *
1274 * @param string $key Custom field key.
1275 * @param string $value Custom field value.
1276 *
1277 * @return array Converted custom field value array.
1278 */
1279 function uwp_maybe_unserialize($key, $value) {
1280 $field = uwp_get_custom_field_info($key);
1281 if (isset($field->field_type) && $field->field_type == 'multiselect') {
1282 $value = explode(",", $value);
1283 }
1284 return $value;
1285 }
1286
1287 /**
1288 * Creates UsersWP related tables.
1289 *
1290 * @since 1.0.0
1291 * @package userswp
1292 *
1293 * @return void
1294 */
1295 function uwp_create_tables()
1296 {
1297 $tables = new UsersWP_Tables();
1298 $tables->uwp_create_tables();
1299 }
1300
1301 /**
1302 * Creates uwp_usermeta table which introduced in version 1.0.1
1303 *
1304 * @since 1.0.0
1305 * @package userswp
1306 *
1307 * @return void
1308 */
1309 function uwp101_create_tables() {
1310 $tables = new UsersWP_Tables();
1311 $tables->uwp101_create_tables();
1312 }
1313
1314 /**
1315 * Returns tye client IP.
1316 *
1317 * @since 1.0.0
1318 * @package userswp
1319 *
1320 * @return string IP address.
1321 */
1322 function uwp_get_ip() {
1323 if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
1324 //check ip from share internet
1325 $ip = $_SERVER['HTTP_CLIENT_IP'];
1326 } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
1327 //to check ip is pass from proxy
1328 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
1329 } else {
1330 $ip = $_SERVER['REMOTE_ADDR'];
1331 }
1332
1333 return apply_filters('uwp_get_ip', $ip);
1334 }
1335
1336 /**
1337 * Checks whether the string starts with the given string.
1338 *
1339 * @since 1.0.0
1340 * @package userswp
1341 *
1342 * @param string $haystack String to compare with.
1343 * @param string $needle String to search for.
1344 *
1345 * @return bool True when success. False when failure.
1346 */
1347 function uwp_str_starts_with($haystack, $needle)
1348 {
1349 $length = strlen($needle);
1350 return (substr($haystack, 0, $length) === $needle);
1351 }
1352
1353 /**
1354 * Checks whether the string ends with the given string.
1355 *
1356 * @since 1.0.0
1357 * @package userswp
1358 *
1359 * @param string $haystack String to compare with.
1360 * @param string $needle String to search for.
1361 *
1362 * @return bool True when success. False when failure.
1363 */
1364 function uwp_str_ends_with($haystack, $needle)
1365 {
1366 $length = strlen($needle);
1367 if ($length == 0) {
1368 return true;
1369 }
1370
1371 return (substr($haystack, -$length) === $needle);
1372 }
1373
1374 /**
1375 * Returns the font awesome icon value for field type.
1376 * Displayed in profile tabs.
1377 *
1378 * @since 1.0.0
1379 * @package userswp
1380 *
1381 * @param string $type Field type.
1382 *
1383 * @return string Font awesome icon value.
1384 */
1385 function uwp_field_type_to_fa_icon($type) {
1386 $field_types = array(
1387 'text' => 'fas fa-minus',
1388 'datepicker' => 'fas fa-calendar-alt',
1389 'textarea' => 'fas fa-bars',
1390 'time' =>'far fa-clock',
1391 'checkbox' =>'far fa-check-square',
1392 'phone' =>'far fa-phone',
1393 'radio' =>'far fa-dot-circle',
1394 'email' =>'far fa-envelope',
1395 'select' =>'far fa-caret-square-down',
1396 'multiselect' =>'far fa-caret-square-down',
1397 'url' =>'fas fa-link',
1398 'file' =>'fas fa-file'
1399 );
1400
1401 if (isset($field_types[$type])) {
1402 return $field_types[$type];
1403 } else {
1404 return "";
1405 }
1406
1407 }
1408
1409 /**
1410 * Check wpml active or not.
1411 *
1412 * @since 1.0.7
1413 *
1414 * @return True if WPML is active else False.
1415 */
1416 function uwp_is_wpml() {
1417 if (class_exists('SitePress') && function_exists('icl_object_id')) {
1418 return true;
1419 }
1420
1421 return false;
1422 }
1423
1424 /**
1425 * Get the element in the WPML current language.
1426 *
1427 * @since 1.0.7
1428 *
1429 * @param int $element_id Use term_id for taxonomies, post_id for posts
1430 * @param string $element_type Use post, page, {custom post type name}, nav_menu, nav_menu_item, category, tag, etc.
1431 * You can also pass 'any', to let WPML guess the type, but this will only work for posts.
1432 * @param bool $return_original_if_missing Optional, default is FALSE. If set to true it will always return a value (the original value, if translation is missing).
1433 * @param string|NULL $ulanguage_code Optional, default is NULL. If missing, it will use the current language.
1434 * If set to a language code, it will return a translation for that language code or
1435 * the original if the translation is missing and $return_original_if_missing is set to TRUE.
1436 *
1437 * @return int|NULL
1438 */
1439 function uwp_wpml_object_id( $element_id, $element_type = 'post', $return_original_if_missing = false, $ulanguage_code = null ) {
1440 if ( uwp_is_wpml() ) {
1441 if ( function_exists( 'wpml_object_id_filter' ) ) {
1442 return apply_filters( 'wpml_object_id', $element_id, $element_type, $return_original_if_missing, $ulanguage_code );
1443 } else {
1444 return icl_object_id( $element_id, $element_type, $return_original_if_missing, $ulanguage_code );
1445 }
1446 }
1447
1448 return $element_id;
1449 }
1450
1451 function uwp_get_default_avatar_uri(){
1452 $default = uwp_get_option('profile_default_profile', '');
1453 if(empty($default)){
1454 $default = USERSWP_PLUGIN_URL."public/assets/images/no_profile.png";
1455 } else {
1456 $default = wp_get_attachment_url($default);
1457 }
1458
1459 return $default;
1460 }
1461
1462 function uwp_refresh_permalinks_on_bad_404() {
1463
1464 global $wp;
1465
1466 if( ! is_404() ) {
1467 return;
1468 }
1469
1470 if( isset( $_GET['uwp-flush'] ) ) {
1471 return;
1472 }
1473
1474 if( false === get_transient( 'uwp_refresh_404_permalinks' ) ) {
1475
1476 flush_rewrite_rules( false );
1477
1478 set_transient( 'uwp_refresh_404_permalinks', 1, HOUR_IN_SECONDS * 12 );
1479
1480 wp_redirect( home_url( add_query_arg( array( 'uwp-flush' => 1 ), $wp->request ) ) ); exit;
1481
1482 }
1483 }
1484 add_action( 'template_redirect', 'uwp_refresh_permalinks_on_bad_404' );
1485
1486 add_filter( 'avatar_defaults', 'uwp_avatar_defaults' , 99999 , 6 );
1487 /*
1488 * Remove get_avatar filter applied by UWP for default avatars in settings
1489 * @param array $avatar_defaults default avatars
1490 * @return array $avatar_defaults default avatars
1491 *
1492 */
1493 function uwp_avatar_defaults($avatar_defaults){
1494 remove_filter('get_avatar', 'uwp_modify_get_avatar', 99999, 6);
1495 return $avatar_defaults;
1496 }
1497
1498 remove_all_filters('get_avatar');
1499 add_filter( 'get_avatar', 'uwp_modify_get_avatar' , 99999 , 6 );
1500 /**
1501 * Modifies get_avatar function to use userswp avatar.
1502 *
1503 * @since 1.0.0
1504 * @package userswp
1505 * @param string $avatar img tag value for the user's avatar.
1506 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
1507 * user email, WP_User object, WP_Post object, or WP_Comment object.
1508 * @param int $size Square avatar width and height in pixels to retrieve.
1509 * @param string $default URL for the default image or a default type. Accepts '404', 'retro', 'monsterid',
1510 * 'wavatar', 'indenticon','mystery' (or 'mm', or 'mysteryman'), 'blank', or 'gravatar_default'.
1511 * Default is the value of the 'avatar_default' option, with a fallback of 'mystery'.
1512 * @param string $alt Alternative text to use in the avatar image tag. Default empty.
1513 * @return string Modified img tag value
1514 */
1515 function uwp_modify_get_avatar( $avatar, $id_or_email, $size, $default, $alt, $args )
1516 {
1517 $user = false;
1518
1519 if (is_numeric($id_or_email)) {
1520
1521 $id = (int)$id_or_email;
1522 $user = get_user_by('id', $id);
1523
1524 } elseif (is_object($id_or_email)) {
1525
1526 if (!empty($id_or_email->user_id)) {
1527 $id = (int)$id_or_email->user_id;
1528 $user = get_user_by('id', $id);
1529 }
1530
1531 } else {
1532 $user = get_user_by('email', $id_or_email);
1533 }
1534
1535 if ($user && is_object($user)) {
1536 $avatar_thumb = uwp_get_usermeta($user->data->ID, 'uwp_account_avatar_thumb', '');
1537 if (!empty($avatar_thumb)) {
1538 $uploads = wp_upload_dir();
1539 $upload_url = $uploads['baseurl'];
1540 if (substr($avatar_thumb, 0, 4) !== "http") {
1541 $avatar_thumb = $upload_url . $avatar_thumb;
1542 }
1543 $avatar = "<img alt='{$alt}' src='{$avatar_thumb}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
1544 } else {
1545 $default = uwp_get_default_avatar_uri();
1546 $args = get_avatar_data($id_or_email, $args);
1547 $url = $args['url'];
1548 $url = remove_query_arg('d', $url);
1549 $url = add_query_arg(array('d' => $default), $url);
1550 if (!$url || is_wp_error($url)) {
1551 return $avatar;
1552 }
1553 $avatar = '<img src="' . $url . '" class="gravatar avatar avatar-' . $size . ' uwp-avatar" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" />';
1554 }
1555
1556 }
1557
1558 return $avatar;
1559 }
1560
1561 /**
1562 * Handles multisite upload dir path
1563 *
1564 * @param $uploads array upload variable array
1565 *
1566 * @return array updated upload variable array.
1567 */
1568 function uwp_handle_multisite_profile_image($uploads){
1569 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
1570 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
1571 }
1572
1573 // Network active.
1574 if ( is_plugin_active_for_network( 'userswp/userswp.php' ) ) {
1575 $main_site = get_network()->site_id;
1576 switch_to_blog( $main_site );
1577 remove_filter( 'upload_dir', 'uwp_handle_multisite_profile_image');
1578 $uploads = wp_upload_dir();
1579 restore_current_blog();
1580 }
1581
1582 return $uploads;
1583 }
1584
1585 /**
1586 * let_to_num function.
1587 *
1588 * This function transforms the php.ini notation for numbers (like '2M') to an integer.
1589 *
1590 * @since 2.0.0
1591 * @param $size
1592 * @return int
1593 */
1594 function uwp_let_to_num( $size ) {
1595 $l = substr( $size, -1 );
1596 $ret = substr( $size, 0, -1 );
1597 switch ( strtoupper( $l ) ) {
1598 case 'P':
1599 $ret *= 1024;
1600 case 'T':
1601 $ret *= 1024;
1602 case 'G':
1603 $ret *= 1024;
1604 case 'M':
1605 $ret *= 1024;
1606 case 'K':
1607 $ret *= 1024;
1608 }
1609 return $ret;
1610 }
1611
1612 function uwp_format_decimal($number, $dp = false, $trim_zeros = false){
1613 $locale = localeconv();
1614 $decimals = array( uwp_get_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] );
1615
1616 // Remove locale from string.
1617 if ( ! is_float( $number ) ) {
1618 $number = str_replace( $decimals, '.', $number );
1619 $number = preg_replace( '/[^0-9\.,-]/', '', uwp_clean( $number ) );
1620 }
1621
1622 if ( false !== $dp ) {
1623 $dp = intval( '' == $dp ? uwp_get_decimal_separator() : $dp );
1624 $number = number_format( floatval( $number ), $dp, '.', '' );
1625 // DP is false - don't use number format, just return a string in our format
1626 } elseif ( is_float( $number ) ) {
1627 // DP is false - don't use number format, just return a string using whatever is given. Remove scientific notation using sprintf.
1628 $number = str_replace( $decimals, '.', sprintf( '%.' . uwp_get_rounding_precision() . 'f', $number ) );
1629 // We already had a float, so trailing zeros are not needed.
1630 $trim_zeros = true;
1631 }
1632
1633 if ( $trim_zeros && strstr( $number, '.' ) ) {
1634 $number = rtrim( rtrim( $number, '0' ), '.' );
1635 }
1636
1637 return $number;
1638 }
1639
1640 /**
1641 * Return the decimal separator.
1642 * @since 1.0.20
1643 * @return string
1644 */
1645 function uwp_get_decimal_separator() {
1646 $separator = apply_filters( 'uwp_decimal_separator', '.' );
1647 return $separator ? stripslashes( $separator ) : '.';
1648 }
1649
1650 /**
1651 * Get rounding precision for internal UWP calculations.
1652 * Will increase the precision of uwp_get_decimal_separator by 2 decimals, unless UWP_ROUNDING_PRECISION is set to a higher number.
1653 *
1654 * @since 1.0.20
1655 * @return int
1656 */
1657 function uwp_get_rounding_precision() {
1658 $precision = uwp_get_decimal_separator() + 2;
1659 if ( absint( UWP_ROUNDING_PRECISION ) > $precision ) {
1660 $precision = absint( UWP_ROUNDING_PRECISION );
1661 }
1662 return $precision;
1663 }
1664
1665 /**
1666 * Clean variables using sanitize_text_field. Arrays are cleaned recursively.
1667 * Non-scalar values are ignored.
1668 *
1669 * @param string|array $var
1670 *
1671 * @return string|array
1672 */
1673 function uwp_clean( $var ) {
1674
1675 if ( is_array( $var ) ) {
1676 return array_map( 'uwp_clean', $var );
1677 } else {
1678 return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
1679 }
1680
1681 }
1682
1683 /**
1684 * Define a constant if it is not already defined.
1685 *
1686 * @since 1.0.21
1687 *
1688 * @param string $name Constant name.
1689 * @param string $value Value.
1690 */
1691 function uwp_maybe_define( $name, $value ) {
1692 if ( ! defined( $name ) ) {
1693 define( $name, $value );
1694 }
1695 }
1696
1697 function uwp_insert_usermeta(){
1698 global $wpdb;
1699 $sort= "user_registered";
1700
1701 $all_users_id = $wpdb->get_col( $wpdb->prepare(
1702 "SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC"
1703 , $sort ));
1704
1705 //we got all the IDs, now loop through them to get individual IDs
1706 foreach ( $all_users_id as $user_id ) {
1707 $user_data = get_userdata($user_id);
1708
1709 $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
1710 $user_meta = array(
1711 'uwp_account_username' => $user_data->user_login,
1712 'uwp_account_email' => $user_data->user_email,
1713 'uwp_account_first_name' => $user_data->first_name,
1714 'uwp_account_last_name' => $user_data->last_name,
1715 'uwp_account_display_name' => $user_data->display_name,
1716 );
1717
1718 $users = $wpdb->get_var($wpdb->prepare("SELECT COUNT(user_id) FROM {$meta_table} WHERE user_id = %d", $user_id));
1719
1720 if(!empty($users)) {
1721 $wpdb->update(
1722 $meta_table,
1723 $user_meta,
1724 array('user_id' => $user_id)
1725 );
1726 } else {
1727 $user_meta['user_id'] = $user_id;
1728 $wpdb->insert(
1729 $meta_table,
1730 $user_meta
1731 );
1732 }
1733 }
1734 }
1735
1736 function uwp_get_localize_data(){
1737 $uwp_localize_data = array(
1738 'uwp_more_char_limit' => '100',
1739 'uwp_more_text' => __('more','userswp'),
1740 'uwp_less_text' => __('less','userswp'),
1741 'uwp_more_ellipses_text' => '...',
1742 );
1743
1744 return apply_filters('uwp_localize_data', $uwp_localize_data);
1745 }
1746
1747 function uwp_is_page_builder(){
1748 if( isset($_GET['elementor-preview']) && $_GET['elementor-preview'] > 0){
1749 return true; // Elementor builder.
1750 }
1751
1752 return false;
1753 }