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

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