PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.12
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.12
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 / helpers / misc.php

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

1,461 lines 46.3 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 $exclude_users = apply_filters('uwp_excluded_users_from_list', $exclude_users, $where, $keyword);
313
314 if($exclude_users){
315 $exclude_users_list = implode(',', $exclude_users);
316 $exclude_query = 'AND '. $wpdb->users.'.ID NOT IN ('.$exclude_users_list.')';
317 } else {
318 $exclude_query = ' ';
319 }
320
321 if ($keyword || $where) {
322 if (empty($where)) {
323 $users = $wpdb->get_results($wpdb->prepare(
324 "SELECT DISTINCT SQL_CALC_FOUND_ROWS $wpdb->users.*
325 FROM $wpdb->users
326 INNER JOIN $wpdb->usermeta
327 ON ( $wpdb->users.ID = $wpdb->usermeta.user_id )
328 WHERE 1=1
329 $exclude_query
330 AND (
331 ( $wpdb->usermeta.meta_key = 'first_name' AND $wpdb->usermeta.meta_value LIKE %s )
332 OR
333 ( $wpdb->usermeta.meta_key = 'last_name' AND $wpdb->usermeta.meta_value LIKE %s )
334 OR
335 user_login LIKE %s
336 OR
337 user_nicename LIKE %s
338 OR
339 display_name LIKE %s
340 OR
341 user_email LIKE %s
342 )
343 ORDER BY display_name ASC
344 LIMIT 0, 20",
345 array(
346 '%' . $keyword . '%',
347 '%' . $keyword . '%',
348 '%' . $keyword . '%',
349 '%' . $keyword . '%',
350 '%' . $keyword . '%',
351 '%' . $keyword . '%'
352 )
353 ));
354 } else {
355 $usermeta_table = uwp_get_table_prefix() . 'uwp_usermeta';
356
357 $users = $wpdb->get_results(
358 "SELECT DISTINCT SQL_CALC_FOUND_ROWS $wpdb->users.*
359 FROM $wpdb->users
360 INNER JOIN $usermeta_table
361 ON ( $wpdb->users.ID = $usermeta_table.user_id )
362 WHERE 1=1
363 $exclude_query
364 $where
365 ORDER BY display_name ASC
366 LIMIT 0, 20");
367 }
368
369 $total_user = count($users);
370
371 } else {
372
373 $args = array(
374 'number' => (int) $number,
375 'paged' => $paged,
376 'exclude' => $exclude_users,
377 );
378
379
380 if ($sort_by) {
381 switch ($sort_by) {
382 case "newer":
383 $args['orderby'] = 'registered';
384 $args['order'] = 'desc';
385 break;
386 case "older":
387 $args['orderby'] = 'registered';
388 $args['order'] = 'asc';
389 break;
390 case "alpha_asc":
391 $args['orderby'] = 'display_name';
392 $args['order'] = 'asc';
393 break;
394 case "alpha_desc":
395 $args['orderby'] = 'display_name';
396 $args['order'] = 'desc';
397 break;
398
399 }
400 }
401
402 $users_query = new WP_User_Query($args);
403 $users = $users_query->get_results();
404 $total_user = $users_query->get_total();
405
406 }
407
408 $total_pages=ceil($total_user/$number);
409
410 $layout_class = uwp_get_layout_class();
411 ?>
412 <ul class="uwp-users-list-wrap <?php echo $layout_class; ?>" id="uwp_user_items_layout">
413 <?php
414 if ($users) {
415 foreach ($users as $user) {
416 $user_obj = get_user_by('id', $user->ID);
417
418 // exclude logged in user
419 $exclude_loggedin_user = apply_filters('uwp_users_list_exclude_loggedin_user', false);
420 if ($exclude_loggedin_user) {
421 if ($user_obj->ID == get_current_user_id()) {
422 continue;
423 }
424 }
425 ?>
426 <li class="uwp-users-list-user">
427 <div class="uwp-users-list-user-left">
428 <?php do_action('uwp_users_profile_header', $user); ?>
429 </div>
430 <div class="uwp-users-list-user-right">
431 <div class="uwp-users-list-user-name">
432 <h3 class="uwp-user-title" data-user="<?php echo $user_obj->ID; ?>">
433 <a href="<?php echo apply_filters('uwp_profile_link', get_author_posts_url($user_obj->ID), $user_obj->ID); ?>">
434 <?php echo apply_filters('uwp_profile_display_name', $user_obj->display_name); ?>
435 </a>
436 <?php do_action('uwp_users_after_title', $user_obj->ID ); ?>
437 </h3>
438 </div>
439 <div class="uwp-users-list-user-btns">
440 <?php do_action('uwp_profile_buttons', $user_obj ); ?>
441 </div>
442 <div class="uwp-users-list-user-social">
443 <?php do_action('uwp_profile_social', $user_obj ); ?>
444 </div>
445 <div class="uwp-users-list-extra">
446 <?php do_action('uwp_users_extra', $user_obj ); ?>
447 </div>
448 <div class="clfx"></div>
449 </div>
450 </li>
451 <?php
452 }
453 } else {
454 // no users found
455 echo '<div class="uwp-alert-error text-center">';
456 echo __('No Users Found', 'userswp');
457 echo '</div>';
458 }
459 ?>
460 </ul>
461
462 <?php
463 if ($total_pages > 1) {
464 do_action('uwp_profile_pagination', $total_pages);
465 }
466 ?>
467 <?php
468 }
469
470
471
472 /**
473 * Loads the font-awesome css files.
474 *
475 * @since 1.0.0
476 * @package userswp
477 *
478 * @return void
479 */
480 function uwp_load_font_awesome() {
481 //load font awesome
482 global $wp_styles;
483 if ($wp_styles) {
484 $srcs = array_map('basename', (array) wp_list_pluck($wp_styles->registered, 'src') );
485 if ( in_array('font-awesome.css', $srcs) || in_array('font-awesome.min.css', $srcs) ) {
486 /* echo 'font-awesome.css registered'; */
487 } else {
488 wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css', array(), null);
489 wp_enqueue_style('font-awesome');
490 }
491 } else {
492 wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css', array(), null);
493 wp_enqueue_style('font-awesome');
494 }
495 }
496
497 /**
498 * Gets the custom field info for given key.
499 *
500 * @since 1.0.0
501 * @package userswp
502 *
503 * @param string $htmlvar_name Custom field key.
504 *
505 * @return object Field info.
506 */
507 function uwp_get_custom_field_info($htmlvar_name) {
508 global $wpdb;
509 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
510 $field = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE htmlvar_name = %s", array($htmlvar_name)));
511 return $field;
512 }
513
514
515
516 /**
517 * Returns the Users page layout class based on the setting.
518 *
519 * @since 1.0.0
520 * @package userswp
521 *
522 * @return string Layout class.
523 */
524 function uwp_get_layout_class() {
525 $default_layout = uwp_get_option('users_default_layout', 'list');
526 switch ($default_layout) {
527 case "list":
528 $class = "uwp_listview";
529 break;
530 case "2col":
531 $class = "uwp_gridview uwp_gridview_2col";
532 break;
533 case "3col":
534 $class = "uwp_gridview uwp_gridview_3col";
535 break;
536 case "4col":
537 $class = "uwp_gridview uwp_gridview_4col";
538 break;
539 case "5col":
540 $class = "uwp_gridview uwp_gridview_5col";
541 break;
542 default:
543 $class = "uwp_listview";
544 }
545
546 return $class;
547 }
548
549 add_filter( 'get_user_option_metaboxhidden_nav-menus', 'uwp_always_nav_menu_visibility', 10, 3 );
550
551 /**
552 * Filters nav menu visibility option value.
553 *
554 * @since 1.0.0
555 * @package userswp
556 *
557 * @param mixed $result Value for the user's option.
558 * @param string $option Name of the option being retrieved.
559 * @param WP_User $user WP_User object of the user whose option is being retrieved.
560 *
561 * @return array Filtered value.
562 */
563 function uwp_always_nav_menu_visibility( $result, $option, $user )
564 {
565 if( is_array($result) && in_array( 'add-users-wp-nav-menu', $result ) ) {
566 $result = array_diff( $result, array( 'add-users-wp-nav-menu' ) );
567 }
568
569 return $result;
570 }
571
572 add_filter('user_profile_picture_description', 'uwp_admin_user_profile_picture_description');
573
574 /**
575 * Filters the user profile picture description displayed under the Gravatar.
576 *
577 * @since 1.0.0
578 * @package userswp
579 *
580 * @param string $description Profile picture description.
581 *
582 * @return string Modified description.
583 */
584 function uwp_admin_user_profile_picture_description($description) {
585 if (is_admin() && IS_PROFILE_PAGE) {
586 $user_id = get_current_user_id();
587 $avatar = uwp_get_usermeta($user_id, 'uwp_account_avatar_thumb', '');
588
589 if (!empty($avatar)) {
590 $description = sprintf( __( 'You can change your profile picture on your <a href="%s">Profile Page</a>.', 'userswp' ),
591 uwp_build_profile_tab_url( $user_id ));
592 }
593
594 }
595 return $description;
596 }
597
598 /**
599 * Adds avatar and banner fields in admin side.
600 *
601 * @since 1.0.0
602 * @package userswp
603 *
604 * @param object $user User object.
605 *
606 * @return void
607 */
608 function uwp_admin_edit_banner_fields($user) {
609 global $wpdb;
610
611 $file_obj = new UsersWP_Files();
612
613 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
614 $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE (form_type = 'avatar' OR form_type = 'banner') ORDER BY sort_order ASC");
615 if ($fields) {
616 ?>
617 <div class="uwp-profile-extra uwp_page">
618 <?php do_action('uwp_admin_profile_edit', $user ); ?>
619 <table class="uwp-profile-extra-table form-table">
620 <?php
621 foreach ($fields as $field) {
622
623 // Icon
624 $icon = uwp_get_field_icon( $field->field_icon );
625
626 if ($field->field_type == 'fieldset') {
627 ?>
628 <tr style="margin: 0; padding: 0">
629 <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3 style="margin: 10px 0;">
630 <?php echo $icon.$field->site_title; ?></h3></th>
631 <td></td>
632 </tr>
633 <?php
634 } else { ?>
635 <tr>
636 <th class="uwp-profile-extra-key"><?php echo $icon.$field->site_title; ?></th>
637 <td class="uwp-profile-extra-value">
638 <?php
639 if ($field->htmlvar_name == "uwp_avatar_file") {
640 $value = uwp_get_usermeta($user->ID, "uwp_account_avatar_thumb", "");
641 } elseif ($field->htmlvar_name == "uwp_banner_file") {
642 $value = uwp_get_usermeta($user->ID, "uwp_account_banner_thumb", "");
643 } else {
644 $value = "";
645 }
646 ?>
647 <?php echo $file_obj->uwp_file_upload_preview($field, $value); ?>
648 <?php
649 if ($field->htmlvar_name == "uwp_avatar_file") {
650 if (!empty($value)) {
651 ?>
652 <a class="uwp-profile-modal-form-trigger" data-type="avatar" href="#">
653 <?php echo __("Change Avatar", "userswp"); ?>
654 </a>
655 <?php
656 } else {
657 ?>
658 <a class="uwp-profile-modal-form-trigger" data-type="avatar" href="#">
659 <?php echo __("Upload Avatar", "userswp"); ?>
660 </a>
661 <?php
662 }
663 } elseif ($field->htmlvar_name == "uwp_banner_file") {
664 if (!empty($value)) {
665 ?>
666 <a class="uwp-profile-modal-form-trigger" data-type="banner" href="#">
667 <?php echo __("Change Banner", "userswp"); ?>
668 </a>
669 <?php
670 } else {
671 ?>
672 <a class="uwp-profile-modal-form-trigger" data-type="banner" href="#">
673 <?php echo __("Upload Banner", "userswp"); ?>
674 </a>
675 <?php
676 }
677 }
678 ?>
679 </td>
680 </tr>
681 <?php
682 }
683 }
684 ?>
685 </table>
686 </div>
687 <?php
688 }
689 }
690 //add_action('show_user_profile', 'uwp_admin_edit_banner_fields');
691 //add_action('edit_user_profile', 'uwp_admin_edit_banner_fields');
692
693
694
695 // Privacy
696 add_filter('uwp_account_page_title', 'uwp_account_privacy_page_title', 10, 2);
697
698 /**
699 * Adds Privacy tab title in Account page.
700 *
701 * @since 1.0.0
702 * @package userswp
703 *
704 * @param string $title Privacy title.
705 * @param string $type Tab type.
706 *
707 * @return string|void Title.
708 */
709 function uwp_account_privacy_page_title($title, $type) {
710 if ($type == 'privacy') {
711 $title = __( 'Privacy', 'userswp' );
712 }
713
714 return $title;
715 }
716
717 add_action('uwp_account_form_display', 'uwp_account_privacy_edit_form_display');
718
719 /**
720 * Adds form html for privacy fields in account page.
721 *
722 * @since 1.0.0
723 * @package userswp
724 *
725 * @param string $type Form type.
726 *
727 * @return void
728 */
729 function uwp_account_privacy_edit_form_display($type) {
730 if ($type == 'privacy') {
731 $make_profile_private = uwp_can_make_profile_private();
732 echo '<div class="uwp-account-form uwp_wc_form">';
733 $extra_where = "AND is_public='2'";
734 $fields = get_account_form_fields($extra_where);
735 $fields = apply_filters('uwp_account_privacy_fields', $fields);
736 $user_id = get_current_user_id();
737 ?>
738 <div class="uwp-profile-extra">
739 <div class="uwp-profile-extra-div form-table">
740 <form class="uwp-account-form uwp_form" method="post">
741 <?php if ($fields) { ?>
742 <div class="uwp-profile-extra-wrap">
743 <div class="uwp-profile-extra-key" style="font-weight: bold;">
744 <?php echo __("Field", "userswp") ?>
745 </div>
746 <div class="uwp-profile-extra-value" style="font-weight: bold;">
747 <?php echo __("Is Public?", "userswp") ?>
748 </div>
749 </div>
750 <?php foreach ($fields as $field) { ?>
751 <div class="uwp-profile-extra-wrap">
752 <div class="uwp-profile-extra-key"><?php echo $field->site_title; ?>
753 <span class="uwp-profile-extra-sep">:</span></div>
754 <div class="uwp-profile-extra-value">
755 <?php
756 $field_name = $field->htmlvar_name . '_privacy';
757 $value = uwp_get_usermeta($user_id, $field_name, false);
758 if ($value === false) {
759 $value = 'yes';
760 }
761 ?>
762 <select name="<?php echo $field_name; ?>" class="uwp_privacy_field"
763 style="margin: 0;">
764 <option value="no" <?php selected($value, "no"); ?>><?php echo __("No", "userswp") ?></option>
765 <option value="yes" <?php selected($value, "yes"); ?>><?php echo __("Yes", "userswp") ?></option>
766 </select>
767 </div>
768 </div>
769 <?php }
770 }
771 $value = get_user_meta($user_id, 'uwp_hide_from_listing', true); ?>
772 <div class="uwp-profile-extra-wrap">
773 <div id="uwp_hide_from_listing" class="uwp_hide_from_listing">
774 <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.'); ?>
775 </div>
776 </div>
777 <?php
778 do_action('uwp_after_privacy_form_fields', $fields);
779 if ($make_profile_private) {
780 $field_name = 'uwp_make_profile_private';
781 $value = get_user_meta($user_id, $field_name, true);
782 if ($value === false) {
783 $value = '0';
784 }
785 ?>
786 <div id="uwp_make_profile_private" class=" uwp_make_profile_private_row">
787 <input type="hidden" name="uwp_make_profile_private" value="0">
788 <input name="uwp_make_profile_private" class="" <?php checked( $value, "1", true ); ?> type="checkbox" value="1">
789 <?php _e( 'Make the whole profile private', 'userswp' ); ?>
790 </div>
791 <?php
792 }
793 ?>
794 <input type="hidden" name="uwp_privacy_nonce" value="<?php echo wp_create_nonce( 'uwp-privacy-nonce' ); ?>" />
795 <input name="uwp_privacy_submit" value="<?php echo __( 'Submit', 'userswp' ); ?>" type="submit">
796 </form>
797 </div>
798 </div>
799 <?php
800 echo '</div>';
801 }
802 }
803
804 add_action('uwp_account_menu_display', 'uwp_add_account_menu_links');
805
806 /**
807 * Prints "Edit account" page subtab / submenu links. Ex: Privacy
808 *
809 * @since 1.0.0
810 * @package userswp
811 *
812 * @return void
813 */
814 function uwp_add_account_menu_links() {
815
816 if (isset($_GET['type'])) {
817 $type = strip_tags(esc_sql($_GET['type']));
818 } else {
819 $type = 'account';
820 }
821
822 $account_page = uwp_get_option('account_page', false);
823 $account_page_link = get_permalink($account_page);
824
825 $account_available_tabs = uwp_account_get_available_tabs();
826
827 if (!is_array($account_available_tabs) && count($account_available_tabs) > 0) {
828 return;
829 }
830
831 echo '<ul class="uwp_account_menu">';
832
833 foreach( $account_available_tabs as $tab_id => $tab ) {
834
835 if ($tab_id == 'account') {
836 $tab_url = $account_page_link;
837 } else {
838 $tab_url = add_query_arg(array(
839 'type' => $tab_id,
840 ), $account_page_link);
841 }
842
843 if (isset($tab['link'])) {
844 $tab_url = $tab['link'];
845 }
846
847 $active = $type == $tab_id ? ' active' : '';
848 ?>
849 <li id="uwp-account-<?php echo $tab_id; ?>">
850 <a class="<?php echo $active; ?>" href="<?php echo esc_url( $tab_url ); ?>">
851 <i class="<?php echo $tab['icon']; ?>"></i> <?php echo $tab['title']; ?>
852 </a>
853 </li>
854 <?php
855 }
856
857 $template = new UsersWP_Templates();
858 $logout_url = $template->uwp_logout_url();
859 echo '<li id="uwp-account-logout"><a class="uwp-account-logout-link" href="'.$logout_url.'"><i class="fa fa-sign-out"></i>'.__('Logout', 'userswp').'</a></li>';
860 echo '</ul>';
861 }
862
863
864
865
866 /**
867 * Updates extras fields sort order.
868 *
869 * @since 1.0.0
870 * @package userswp
871 *
872 * @param array $field_ids Form extras field ids.
873 * @param string $form_type Form type.
874 *
875 * @return array|bool Sorted field ids.
876 */
877 function uwp_form_extras_field_order($field_ids = array(), $form_type = 'register')
878 {
879 global $wpdb;
880 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
881
882 $count = 0;
883 if (!empty($field_ids)):
884 foreach ($field_ids as $id) {
885
886 $cf = trim($id, '_');
887
888 $wpdb->query(
889 $wpdb->prepare(
890 "update " . $extras_table_name . " set
891 sort_order=%d
892 where id= %d",
893 array($count, $cf)
894 )
895 );
896 $count++;
897 }
898
899 return $field_ids;
900 else:
901 return false;
902 endif;
903 }
904
905 /**
906 * Uppercase the first character of each word in a string.
907 *
908 * @since 1.0.0
909 * @package userswp
910 *
911 * @param string $string String to convert.
912 * @param string $charset Charset.
913 *
914 * @return string Converted string.
915 */
916 function uwp_ucwords($string, $charset='UTF-8') {
917 if (function_exists('mb_convert_case')) {
918 return mb_convert_case($string, MB_CASE_TITLE, $charset);
919 } else {
920 return ucwords($string);
921 }
922 }
923
924 /**
925 * Checks whether the column exists in the table.
926 *
927 * @since 1.0.0
928 * @package userswp
929 *
930 * @param string $db Table name.
931 * @param string $column Column name.
932 *
933 * @return bool
934 */
935 function uwp_column_exist($db, $column)
936 {
937 $table = new UsersWP_Tables();
938 $table->column_exists($db, $column);
939 }
940
941 /**
942 * Adds column if not exist in the table.
943 *
944 * @since 1.0.0
945 * @package userswp
946 *
947 * @param string $db Table name.
948 * @param string $column Column name.
949 * @param string $column_attr Column attributes.
950 *
951 * @return bool|int True when success.
952 */
953 function uwp_add_column_if_not_exist($db, $column, $column_attr = "VARCHAR( 255 ) NOT NULL")
954 {
955 $table = new UsersWP_Tables();
956 $table->add_column_if_not_exist($db, $column, $column_attr);
957
958 }
959
960 /**
961 * Returns excluded custom fields.
962 *
963 * @since 1.0.0
964 * @package userswp
965 *
966 * @return array Excluded custom fields.
967 */
968 function uwp_get_excluded_fields() {
969 $excluded = array(
970 'uwp_account_password',
971 'uwp_account_confirm_password',
972 );
973 return $excluded;
974 }
975
976 /**
977 * Formats the currency using currency separator.
978 *
979 * @since 1.0.0
980 * @package userswp
981 *
982 * @param string $number Currency number.
983 * @param array|string $cf Custom field info.
984 *
985 * @return string Formatted currency.
986 */
987 function uwp_currency_format_number($number='',$cf=''){
988
989 $cs = isset($cf['extra_fields']) ? maybe_unserialize($cf['extra_fields']) : '';
990
991 $symbol = isset($cs['currency_symbol']) ? $cs['currency_symbol'] : '$';
992 $decimals = isset($cf['decimal_point']) && $cf['decimal_point'] ? $cf['decimal_point'] : 2;
993 $decimal_display = isset($cf['decimal_display']) && $cf['decimal_display'] ? $cf['decimal_display'] : 'if';
994 $decimalpoint = '.';
995
996 if(isset($cs['decimal_separator']) && $cs['decimal_separator']=='comma'){
997 $decimalpoint = ',';
998 }
999
1000 $separator = ',';
1001
1002 if(isset($cs['thousand_separator'])){
1003 if($cs['thousand_separator']=='comma'){$separator = ',';}
1004 if($cs['thousand_separator']=='slash'){$separator = '\\';}
1005 if($cs['thousand_separator']=='period'){$separator = '.';}
1006 if($cs['thousand_separator']=='space'){$separator = ' ';}
1007 if($cs['thousand_separator']=='none'){$separator = '';}
1008 }
1009
1010 $currency_symbol_placement = isset($cs['currency_symbol_placement']) ? $cs['currency_symbol_placement'] : 'left';
1011
1012 if($decimals>0 && $decimal_display=='if'){
1013 if(is_int($number) || floor( $number ) == $number)
1014 $decimals = 0;
1015 }
1016
1017 $number = number_format($number,$decimals,$decimalpoint,$separator);
1018
1019
1020
1021 if($currency_symbol_placement=='left'){
1022 $number = $symbol . $number;
1023 }else{
1024 $number = $number . $symbol;
1025 }
1026
1027
1028 return $number;
1029 }
1030
1031
1032 /**
1033 * Checks whether the user can make his/her own profile private or not.
1034 *
1035 * @since 1.0.0
1036 * @package userswp
1037 *
1038 * @return bool
1039 */
1040 function uwp_can_make_profile_private() {
1041 $make_profile_private = apply_filters('uwp_user_can_make_profile_private', false);
1042 return $make_profile_private;
1043 }
1044
1045 /**
1046 * Returns available registration status options.
1047 *
1048 * @since 1.0.0
1049 * @package userswp
1050 *
1051 * @return array Registration status options.
1052 */
1053 function uwp_registration_status_options() {
1054 $registration_options = array(
1055 'auto_approve' => __('Auto approve', 'userswp'),
1056 'auto_approve_login' => __('Auto approve + Auto Login', 'userswp'),
1057 'require_email_activation' => __('Require Email Activation', 'userswp'),
1058 );
1059
1060 $registration_options = apply_filters('uwp_registration_status_options', $registration_options);
1061
1062 return $registration_options;
1063 }
1064
1065 /**
1066 * Retrieves a user row based on password reset key and login
1067 *
1068 * @since 1.0.0
1069 * @package userswp
1070 *
1071 * @param string $key Hash to validate sending user's password.
1072 * @param string $login The user login.
1073 *
1074 * @return WP_Error|WP_User User object.
1075 */
1076 function uwp_check_activation_key( $key, $login ) {
1077 $user_data = check_password_reset_key( $key, $login );
1078
1079 return $user_data;
1080 }
1081
1082
1083 add_action('uwp_template_fields', 'uwp_template_fields_terms_check', 100, 1);
1084
1085 /**
1086 * Adds "Accept terms and conditions" checkbox in register form.
1087 *
1088 * @since 1.0.0
1089 * @package userswp
1090 *
1091 * @param string $form_type Form type.
1092 *
1093 * @return void
1094 */
1095 function uwp_template_fields_terms_check($form_type) {
1096 if ($form_type == 'register') {
1097 $terms_page = false;
1098 $reg_terms_page_id = uwp_get_option('register_terms_page', '');
1099 $reg_terms_page_id = apply_filters('uwp_reg_terms_page_id', $reg_terms_page_id);
1100 if (!empty($reg_terms_page_id)) {
1101 $terms_page = get_permalink($reg_terms_page_id);
1102 }
1103 if ($terms_page) {
1104 ?>
1105 <div class="uwp-remember-me">
1106 <label style="display: inline-block;font-weight: normal" for="agree_terms">
1107 <input name="agree_terms" id="agree_terms" value="yes" type="checkbox">
1108 <?php echo sprintf( __( 'I Accept <a href="%s" target="_blank">Terms and Conditions</a>.', 'userswp' ), $terms_page); ?>
1109 </label>
1110 </div>
1111 <?php
1112 }
1113 }
1114 }
1115
1116
1117
1118 /**
1119 * Redirects the user to login page when email not confirmed.
1120 *
1121 * @since 1.0.0
1122 * @package userswp
1123 *
1124 * @param string $username Username.
1125 * @param object $user User object.
1126 *
1127 * @return void
1128 */
1129 function uwp_unconfirmed_login_redirect( $username, $user ) {
1130 if (!is_wp_error($user)) {
1131 $mod_value = get_user_meta( $user->ID, 'uwp_mod', true );
1132 if ($mod_value == 'email_unconfirmed') {
1133 if ( !in_array( 'administrator', $user->roles ) ) {
1134 $login_page = uwp_get_option('login_page', false);
1135 if ($login_page) {
1136 $redirect_to = add_query_arg(array('uwp_err' => 'act_pending'), get_permalink($login_page));
1137 wp_destroy_current_session();
1138 wp_clear_auth_cookie();
1139 wp_redirect($redirect_to);
1140 exit();
1141 }
1142 }
1143 }
1144 }
1145 }
1146 add_filter( 'wp_login', 'uwp_unconfirmed_login_redirect', 10, 2 );
1147
1148 /**
1149 * Adds notification menu in admin toolbar.
1150 *
1151 * @since 1.0.0
1152 * @package userswp
1153 *
1154 * @return void
1155 */
1156 function uwp_notifications_toolbar_menu() {
1157 global $wp_admin_bar;
1158
1159 if ( ! is_user_logged_in() ) {
1160 return;
1161 }
1162
1163 $available_counts = apply_filters('uwp_notifications_available_counts', array());
1164
1165 if (count($available_counts) == 0) {
1166 return;
1167 }
1168
1169 $total_count = 0;
1170 foreach ($available_counts as $key => $value) {
1171 $total_count = $total_count + $value;
1172 }
1173
1174
1175 $alert_class = (int) $total_count > 0 ? 'pending-count' : 'count';
1176 $menu_title = '<span id="uwp-notification-count" class="' . $alert_class . '">'
1177 . number_format_i18n( $total_count ) . '</span>';
1178 $menu_link = '';
1179
1180 // Add the top-level Notifications button.
1181 $wp_admin_bar->add_menu( array(
1182 'parent' => 'top-secondary',
1183 'id' => 'uwp-notifications',
1184 'title' => $menu_title,
1185 'href' => $menu_link,
1186 ) );
1187
1188 do_action('uwp_notifications_items', $wp_admin_bar);
1189
1190 return;
1191 }
1192 add_action( 'admin_bar_menu', 'uwp_notifications_toolbar_menu', 90 );
1193
1194 /**
1195 * Returns the installation type.
1196 *
1197 * @since 1.0.0
1198 * @package userswp
1199 *
1200 * @return string Installation type.
1201 */
1202 function uwp_get_installation_type() {
1203 // *. Single Site
1204 if (!is_multisite()) {
1205 return "single";
1206 } else {
1207 // Multisite
1208 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
1209 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
1210 }
1211
1212 // Network active.
1213 if ( is_plugin_active_for_network( 'userswp/userswp.php' ) ) {
1214 if (defined('UWP_ROOT_PAGES')) {
1215 if (UWP_ROOT_PAGES == 'all') {
1216 // *. Multisite - Network Active - Pages on all sites
1217 return "multi_na_all";
1218 } else {
1219 // *. Multisite - Network Active - Pages on specific site
1220 return "multi_na_site_id";
1221 }
1222 } else {
1223 // Multi - network active - default
1224 // *. Multisite - Network Active - Pages on main site
1225 return "multi_na_default";
1226 }
1227 } else {
1228 // * Multisite - Not network active
1229 return "multi_not_na";
1230 }
1231 }
1232 }
1233
1234 /**
1235 * Returns the table prefix based on the installation type.
1236 *
1237 * @since 1.0.0
1238 * @package userswp
1239 *
1240 * @return string Table prefix
1241 */
1242 function uwp_get_table_prefix() {
1243 $tables = new UsersWP_Tables();
1244 return $tables->get_table_prefix();
1245 }
1246
1247
1248
1249 /**
1250 * Converts array to comma separated string.
1251 *
1252 *
1253 * @since 1.0.0
1254 * @package userswp
1255 *
1256 * @param string $key Custom field key.
1257 * @param string $value Custom field value.
1258 *
1259 * @return string Converted custom field value string.
1260 */
1261 function uwp_maybe_serialize($key, $value) {
1262 $field = uwp_get_custom_field_info($key);
1263 if (isset($field->field_type) && $field->field_type == 'multiselect') {
1264 $value = implode(",", $value);
1265 }
1266 return $value;
1267 }
1268
1269 /**
1270 * Converts comma separated string to array.
1271 *
1272 * @since 1.0.0
1273 * @package userswp
1274 *
1275 * @param string $key Custom field key.
1276 * @param string $value Custom field value.
1277 *
1278 * @return array Converted custom field value array.
1279 */
1280 function uwp_maybe_unserialize($key, $value) {
1281 $field = uwp_get_custom_field_info($key);
1282 if (isset($field->field_type) && $field->field_type == 'multiselect') {
1283 $value = explode(",", $value);
1284 }
1285 return $value;
1286 }
1287
1288 /**
1289 * Creates UsersWP related tables.
1290 *
1291 * @since 1.0.0
1292 * @package userswp
1293 *
1294 * @return void
1295 */
1296 function uwp_create_tables()
1297 {
1298 $tables = new UsersWP_Tables();
1299 $tables->uwp_create_tables();
1300 }
1301
1302 /**
1303 * Creates uwp_usermeta table which introduced in version 1.0.1
1304 *
1305 * @since 1.0.0
1306 * @package userswp
1307 *
1308 * @return void
1309 */
1310 function uwp101_create_tables() {
1311 $tables = new UsersWP_Tables();
1312 $tables->uwp101_create_tables();
1313 }
1314
1315 /**
1316 * Returns tye client IP.
1317 *
1318 * @since 1.0.0
1319 * @package userswp
1320 *
1321 * @return string IP address.
1322 */
1323 function uwp_get_ip() {
1324 if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
1325 //check ip from share internet
1326 $ip = $_SERVER['HTTP_CLIENT_IP'];
1327 } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
1328 //to check ip is pass from proxy
1329 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
1330 } else {
1331 $ip = $_SERVER['REMOTE_ADDR'];
1332 }
1333
1334 return apply_filters('uwp_get_ip', $ip);
1335 }
1336
1337 /**
1338 * Checks whether the string starts with the given string.
1339 *
1340 * @since 1.0.0
1341 * @package userswp
1342 *
1343 * @param string $haystack String to compare with.
1344 * @param string $needle String to search for.
1345 *
1346 * @return bool True when success. False when failure.
1347 */
1348 function uwp_str_starts_with($haystack, $needle)
1349 {
1350 $length = strlen($needle);
1351 return (substr($haystack, 0, $length) === $needle);
1352 }
1353
1354 /**
1355 * Checks whether the string ends with the given string.
1356 *
1357 * @since 1.0.0
1358 * @package userswp
1359 *
1360 * @param string $haystack String to compare with.
1361 * @param string $needle String to search for.
1362 *
1363 * @return bool True when success. False when failure.
1364 */
1365 function uwp_str_ends_with($haystack, $needle)
1366 {
1367 $length = strlen($needle);
1368 if ($length == 0) {
1369 return true;
1370 }
1371
1372 return (substr($haystack, -$length) === $needle);
1373 }
1374
1375 /**
1376 * Returns the font awesome icon value for field type.
1377 * Displayed in profile tabs.
1378 *
1379 * @since 1.0.0
1380 * @package userswp
1381 *
1382 * @param string $type Field type.
1383 *
1384 * @return string Font awesome icon value.
1385 */
1386 function uwp_field_type_to_fa_icon($type) {
1387 $field_types = array(
1388 'text' => 'fa fa-minus',
1389 'datepicker' => 'fa fa-calendar',
1390 'textarea' => 'fa fa-bars',
1391 'time' =>'fa fa-clock-o',
1392 'checkbox' =>'fa fa-check-square-o',
1393 'phone' =>'fa fa-phone',
1394 'radio' =>'fa fa-dot-circle-o',
1395 'email' =>'fa fa-envelope-o',
1396 'select' =>'fa fa-caret-square-o-down',
1397 'multiselect' =>'fa fa-caret-square-o-down',
1398 'url' =>'fa fa-link',
1399 'file' =>'fa fa-file'
1400 );
1401
1402 if (isset($field_types[$type])) {
1403 return $field_types[$type];
1404 } else {
1405 return "";
1406 }
1407
1408 }
1409
1410 /**
1411 * Check wpml active or not.
1412 *
1413 * @since 1.0.7
1414 *
1415 * @return True if WPML is active else False.
1416 */
1417 function uwp_is_wpml() {
1418 if (class_exists('SitePress') && function_exists('icl_object_id')) {
1419 return true;
1420 }
1421
1422 return false;
1423 }
1424
1425 /**
1426 * Get the element in the WPML current language.
1427 *
1428 * @since 1.0.7
1429 *
1430 * @param int $element_id Use term_id for taxonomies, post_id for posts
1431 * @param string $element_type Use post, page, {custom post type name}, nav_menu, nav_menu_item, category, tag, etc.
1432 * You can also pass 'any', to let WPML guess the type, but this will only work for posts.
1433 * @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).
1434 * @param string|NULL $ulanguage_code Optional, default is NULL. If missing, it will use the current language.
1435 * If set to a language code, it will return a translation for that language code or
1436 * the original if the translation is missing and $return_original_if_missing is set to TRUE.
1437 *
1438 * @return int|NULL
1439 */
1440 function uwp_wpml_object_id( $element_id, $element_type = 'post', $return_original_if_missing = false, $ulanguage_code = null ) {
1441 if ( uwp_is_wpml() ) {
1442 if ( function_exists( 'wpml_object_id_filter' ) ) {
1443 return apply_filters( 'wpml_object_id', $element_id, $element_type, $return_original_if_missing, $ulanguage_code );
1444 } else {
1445 return icl_object_id( $element_id, $element_type, $return_original_if_missing, $ulanguage_code );
1446 }
1447 }
1448
1449 return $element_id;
1450 }
1451
1452 function uwp_get_default_avatar_uri(){
1453 $default = uwp_get_option('profile_default_profile', '');
1454 if(empty($default)){
1455 $default = USERSWP_PLUGIN_URL."public/assets/images/no_profile.png";
1456 } else {
1457 $default = wp_get_attachment_url($default);
1458 }
1459
1460 return $default;
1461 }