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

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