PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.3.4
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.3.4
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 / class-templates.php

class-templates.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.3.4, at includes/class-templates.php

1,332 lines 42.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Template related functions
5 *
6 * This class defines all code necessary for UsersWP templates like login. register etc.
7 *
8 * @since 1.0.0
9 * @author GeoDirectory Team <info@wpgeodirectory.com>
10 */
11 class UsersWP_Templates {
12
13 /**
14 * The function is use for Retrieve the name of the highest
15 * priority template file that exists.
16 *
17 * @param string $template_name Template files to search for, in order.
18 * @param string $template_path Optional. Template path. Default null.
19 * @param string $default_path Optional. Default path. Default null.
20 *
21 * @return string Template path.
22 */
23 public static function locate_template( $template_name, $template_path = '', $default_path = '' ) {
24
25 if ( ! $template_path ) {
26 $template_path = uwp_get_theme_template_dir_name();
27 }
28
29 if ( ! $default_path ) {
30 $default_path = uwp_get_templates_dir();
31 }
32
33 // Look within passed path within the theme - this is priority.
34 $template = locate_template(
35 array(
36 untrailingslashit( $template_path ) . '/' . $template_name,
37 $template_name,
38 )
39 );
40
41 // Get default template
42 if ( ! $template ) {
43 $template = untrailingslashit( $default_path ) . '/' . $template_name;
44 }
45
46 // Return what we found.
47 return apply_filters( 'uwp_locate_template', $template, $template_name, $template_path );
48 }
49
50 /**
51 *
52 * Displays default content for UWP pages
53 *
54 * @param $content
55 *
56 * @return string
57 */
58 public static function setup_singular_page_content( $content ) {
59
60 global $post, $wp_query;
61
62 if ( ! is_uwp_page() ) {
63 return $content;
64 }
65
66 if ( ! ( ! empty( $wp_query ) && ! empty( $post ) && ( $post->ID == get_queried_object_id() ) ) ) {
67 return $content;
68 }
69
70 /*
71 * Some page builders need to be able to take control here so we add a filter to bypass it on the fly
72 */
73 if ( apply_filters( 'uwp_bypass_setup_singular_page', false ) ) {
74 return $content;
75 }
76
77 remove_filter( 'the_content', array( __CLASS__, 'setup_singular_page_content' ) );
78
79 if ( in_the_loop() ) {
80
81 if ( $content == '' ) {
82 if ( is_uwp_profile_page() ) {
83 $content = '[uwp_profile]';
84 } elseif ( is_uwp_register_page() ) {
85 $content = '[uwp_register]';
86 } elseif ( is_uwp_login_page() ) {
87 $content = '[uwp_login]';
88 } elseif ( is_uwp_forgot_page() ) {
89 $content = '[uwp_forgot]';
90 } elseif ( is_uwp_change_page() ) {
91 $content = '[uwp_change]';
92 } elseif ( is_uwp_reset_page() ) {
93 $content = '[uwp_reset]';
94 } elseif ( is_uwp_account_page() ) {
95 $content = '[uwp_account]';
96 } elseif ( is_uwp_users_page() ) {
97 $content = '[uwp_users]';
98 } elseif ( is_uwp_users_item_page() ) {
99 $content = UsersWP_Defaults::page_user_list_item_content();
100 } else {
101 // do nothing
102 }
103
104 // run the shortcodes on the content
105 $content = do_shortcode( $content );
106
107 // run block content if its available
108 if ( function_exists( 'do_blocks' ) ) {
109 $content = do_blocks( $content );
110 }
111 }
112
113 }
114
115 // add our filter back
116 add_filter( 'the_content', array( __CLASS__, 'setup_singular_page_content' ) );
117
118
119 return $content;
120 }
121
122 /**
123 *
124 * Returns content for the users list item template
125 *
126 * @return string
127 */
128 public static function users_list_item_template_content() {
129
130 $item_page_id = uwp_get_option( 'user_list_item_page', 0 );
131 $content = get_post_field( 'post_content', $item_page_id );
132
133 /*
134 * Some page builders need to be able to take control here so we add a filter to bypass it on the fly
135 */
136 $bypass_content = apply_filters( 'uwp_bypass_users_list_item_template_content', '', $content, $item_page_id );
137 if ( $bypass_content ) {
138 return $bypass_content;
139 }
140
141 // if the content is blank then we grab the page defaults
142 if ( $content == '' ) {
143 $content = UsersWP_Defaults::page_user_list_item_content();
144 }
145
146 // run the shortcodes on the content
147 $content = do_shortcode( $content );
148
149 // run block content if its available
150 if ( function_exists( 'do_blocks' ) ) {
151 $content = do_blocks( $content );
152 }
153
154
155 return $content;
156 }
157
158 /**
159 * Disable our sub templates access from frontend.
160 *
161 * @global object $post WordPress Post object.
162 *
163 * @since 1.2.1.2
164 */
165 public static function redirect_templates_sub_pages() {
166 global $post;
167 if ( isset( $post->ID ) && ! current_user_can( 'administrator' ) && (
168 $post->ID == uwp_get_page_id( 'user_list_item_page' )
169 ) ) {
170 wp_redirect( home_url(), 301 );
171 exit;
172 }
173 }
174
175 /**
176 * Doing some access checks for UsersWP related pages.
177 *
178 * @return bool
179 * @package userswp
180 * @since 1.0.0
181 */
182 public function access_checks() {
183 global $post;
184
185 if ( ! is_page() ) {
186 return false;
187 }
188
189 if ( uwp_is_page_builder() ) {
190 return false;
191 }
192
193 $current_page_id = $post->ID;
194
195 $register_page = uwp_get_page_id( 'register_page', false );
196 $login_page = uwp_get_page_id( 'login_page', false );
197 $forgot_page = uwp_get_page_id( 'forgot_page', false );
198 $reset_page = uwp_get_page_id( 'reset_page', false );
199
200 $change_page = uwp_get_page_id( 'change_page', false );
201 $account_page = uwp_get_page_id( 'account_page', false );
202
203 if ( ( $register_page && ( (int) $register_page == $current_page_id ) ) ||
204 ( $login_page && ( (int) $login_page == $current_page_id ) ) ||
205 ( $forgot_page && ( (int) $forgot_page == $current_page_id ) ) ||
206 ( $reset_page && ( (int) $reset_page == $current_page_id ) ) ) {
207 if ( is_user_logged_in() ) {
208 $redirect_page_id = uwp_get_page_id( 'account_page', false );
209
210 if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
211 $redirect_to = esc_url_raw( $_REQUEST['redirect_to'] );
212 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) {
213 $redirect_to = get_permalink( $redirect_page_id );
214 } else {
215 $redirect_to = home_url( '/' );
216 }
217
218 $redirect_to = apply_filters( 'uwp_logged_in_redirect', $redirect_to );
219 wp_safe_redirect( $redirect_to );
220 exit();
221 }
222 } elseif ( $account_page && ( (int) $account_page == $current_page_id ) ||
223 ( $change_page && ( (int) $change_page == $current_page_id ) ) ) {
224 if ( ! is_user_logged_in() ) {
225 if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
226 $redirect_to = esc_url( $_REQUEST['redirect_to'] );
227 $login_page = add_query_arg(
228 array(
229 'redirect_to' => $redirect_to,
230 ),
231 get_permalink($login_page)
232 );
233 } else {
234 $login_page = get_permalink($login_page);
235 }
236
237 wp_safe_redirect( $login_page );
238 exit();
239 } else {
240 $can_user_can_edit_account = apply_filters( 'uwp_user_can_edit_own_profile', true, get_current_user_id() );
241 if ( ! $can_user_can_edit_account && ( (int) $account_page == $current_page_id ) ) {
242 wp_safe_redirect( home_url( '/' ) );
243 exit();
244 }
245 }
246 } else {
247 return false;
248 }
249
250 return false;
251 }
252
253 /**
254 * If auto generated password, redirects to change password page.
255 *
256 * @return void
257 * @package userswp
258 * @since 1.0.0
259 */
260 public function change_default_password_redirect() {
261 if ( ! is_user_logged_in() ) {
262 return;
263 }
264 if ( 1 == uwp_get_option( 'change_disable_password_nag' ) ) {
265 return;
266 }
267
268 if ( uwp_is_page_builder() ) {
269 return;
270 }
271
272 $change_page = uwp_get_page_id( 'change_page', false );
273 $password_nag = get_user_option( 'default_password_nag', get_current_user_id() );
274
275 if ( $password_nag ) {
276 if ( is_page() ) {
277 global $post;
278 $current_page_id = $post->ID;
279 if ( $change_page && ( (int) $change_page == $current_page_id ) ) {
280 return;
281 }
282 }
283 if ( $change_page ) {
284 wp_safe_redirect( get_permalink( $change_page ) );
285 exit();
286 }
287 }
288 }
289
290 /**
291 * Redirects /profile to /profile/{username} for loggedin users.
292 *
293 * @return void
294 * @package userswp
295 * @since 1.0.0
296 */
297 public function profile_redirect() {
298 if ( uwp_is_page_builder() ) {
299 return;
300 }
301
302 if ( is_page() ) {
303 global $wp_query, $post;
304 $current_page_id = $post->ID;
305 $profile_page = uwp_get_page_id( 'profile_page', false );
306 if ( $profile_page && ( (int) $profile_page == $current_page_id ) ) {
307
308 if ( isset( $wp_query->query_vars['uwp_profile'] ) ) {
309 //must be profile page
310 $url_type = apply_filters( 'uwp_profile_url_type', 'slug' );
311 $author_slug = $wp_query->query_vars['uwp_profile'];
312 if ( $url_type == 'id' ) {
313 $user = get_user_by( 'id', $author_slug );
314 } else {
315 $user = get_user_by( 'slug', $author_slug );
316 }
317
318 if ( ! isset( $user->ID ) ) {
319 global $wp_query;
320 $wp_query->set_404();
321 status_header( 404 );
322 }
323
324 } else {
325 if ( is_user_logged_in() ) {
326 $user_id = get_current_user_id();
327 $obj = new UsersWP_Profile();
328 $profile_url = $obj->get_profile_link( get_author_posts_url( $user_id ), $user_id );
329 wp_safe_redirect( $profile_url );
330 exit();
331 } else {
332 $redirect_to = apply_filters( 'uwp_no_login_profile_redirect', home_url( '/' ) );
333 wp_safe_redirect( $redirect_to );
334 exit();
335 }
336
337 }
338
339 }
340 }
341 }
342
343 /**
344 * Redirects user to a predefined page after logging out.
345 *
346 * @return void
347 * @package userswp
348 * @since 1.0.0
349 */
350 public function logout_redirect() {
351 $redirect_page_id = uwp_get_page_id( 'logout_redirect_to' );
352 if ( isset( $_REQUEST['redirect_to'] ) ) {
353 $redirect_to = esc_url( $_REQUEST['redirect_to'] );
354 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) {
355 $redirect_to = get_permalink( $redirect_page_id );
356 } else {
357 $redirect_to = home_url( '/' );
358 }
359 $redirect_to = apply_filters( 'uwp_logout_redirect', $redirect_to );
360 wp_safe_redirect( $redirect_to );
361 exit();
362 }
363
364 /**
365 * Redirects wp-login.php to UsersWP login page.
366 *
367 * @return void
368 * @package userswp
369 * @since 1.0.0
370 */
371 public function wp_login_redirect() {
372 global $pagenow;
373 if ( 'wp-login.php' == $pagenow && ! isset( $_REQUEST['action'] ) ) {
374 $login_page_id = uwp_get_page_id( 'login_page', false );
375 $block_wp_login = uwp_get_option( 'block_wp_login', '' );
376 if ( $login_page_id && $block_wp_login == '1' ) {
377 $redirect_to = get_permalink( $login_page_id );
378 if ( $redirect_to ) {
379 $redirect_to = add_query_arg( 'redirect_to', admin_url(), $redirect_to );
380 }
381 wp_safe_redirect( $redirect_to );
382 exit();
383 }
384 }
385 }
386
387 /**
388 * Redirects wp-login.php?action=register to UsersWP registration page.
389 *
390 * @return void
391 * @package userswp
392 * @since 1.0.0
393 */
394 public function wp_register_redirect() {
395
396 global $pagenow;
397 if ( 'wp-login.php' == $pagenow && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'register' ) {
398 $reg_page_id = uwp_get_page_id( 'register_page' );
399 $block_wp_reg = uwp_get_option( 'wp_register_redirect' );
400 if ( $reg_page_id && $block_wp_reg == '1' ) {
401
402 $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : '';
403 $redirect_to = get_permalink( $reg_page_id );
404 if ( $redirect ) {
405 $redirect_to = add_query_arg( 'redirect_to', $redirect, $redirect_to );
406 }
407 wp_safe_redirect( $redirect_to );
408 exit();
409 }
410 }
411 }
412
413 /**
414 * Changes the login url to the UWP login page.
415 *
416 * @param $login_url string The URL for login.
417 * @param $redirect string The URL to redirect back to upon successful login.
418 * @param $force_reauth bool Whether to force reauthorization, even if a cookie is present.
419 *
420 * @return string The login url.
421 * @package userswp
422 *
423 * @since 1.0.12
424 */
425 public function wp_login_url( $login_url, $redirect, $force_reauth ) {
426 global $pagenow;
427
428 if ( class_exists( 'Jetpack' ) && 'wp-login.php' == $pagenow && Jetpack::is_module_active( 'sso' ) ) {
429 return $login_url; // Do not change the URL for Jetpack SSO
430 }
431
432 $login_page_id = uwp_get_page_id( 'login_page', false );
433 $redirect_page_id = uwp_get_page_id( 'login_redirect_to' );
434 if ( ( ! is_admin() || wp_doing_ajax() ) && $login_page_id ) {
435 $login_page = get_permalink( $login_page_id );
436 if ( $redirect ) {
437 $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_page );
438 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 1 && wp_get_referer() ) {
439 $redirect_to = esc_url( wp_get_referer() );
440 $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page );
441 } elseif ( isset( $redirect_page_id ) && $redirect_page_id > 0 ) {
442 $redirect_to = get_permalink( $redirect_page_id );
443 $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page );
444 } else {
445 $login_url = $login_page;
446 }
447 }
448
449 return $login_url;
450 }
451
452 /**
453 * Changes the register url with the UWP register page.
454 *
455 * @param $register_url string The URL for register.
456 *
457 * @return string The register url.
458 * @since 1.0.22
459 *
460 */
461 public function wp_register_url( $register_url ) {
462 $register_page_id = uwp_get_page_id( 'register_page' );
463 $redirect_page_id = uwp_get_page_id( 'register_redirect_to' );
464
465 $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : '';
466 if ( isset( $register_page_id ) && $register_page_id > 0 ) {
467 $register_page = get_permalink( $register_page_id );
468 if ( $register_url && isset( $redirect ) && ! empty( $redirect ) ) {
469 $register_url = add_query_arg( 'redirect_to', $redirect, $register_page );
470 } elseif ( (int) $redirect_page_id > 0 ) {
471 $redirect_to = get_permalink( $redirect_page_id );
472 $register_url = add_query_arg( 'redirect_to', $redirect_to, $register_page );
473 } else {
474 $register_url = $register_page;
475 }
476 }
477
478 return $register_url;
479 }
480
481 /**
482 * Changes the lost password url with the UWP page.
483 *
484 * @param $lostpassword_url string The URL for lost password.
485 *
486 * @return string The lost password page url.
487 */
488 public function wp_lostpassword_url( $lostpassword_url ) {
489 $forgot_page_url = uwp_get_forgot_page_url();
490
491 if ( is_multisite() && isset( $_GET['redirect_to'] ) && false !== strpos( wp_unslash( $_GET['redirect_to'] ), network_admin_url() ) ) {
492 return $lostpassword_url;
493 }
494
495 $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : '';
496 if ( $forgot_page_url ) {
497 if ( $forgot_page_url && isset( $redirect ) && ! empty( $redirect ) ) {
498 $lostpassword_url = add_query_arg( 'redirect_to', $redirect, $forgot_page_url );
499 } else {
500 $lostpassword_url = $forgot_page_url;
501 }
502 }
503
504 return $lostpassword_url;
505 }
506
507 /**
508 * Prints html for form fields of that particular form.
509 *
510 * @param string $form_type Form type.
511 *
512 * @return void
513 * @since 1.0.0
514 * @package userswp
515 */
516 public function template_fields( $form_type, $args = array() ) {
517
518 global $wpdb;
519 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
520 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
521
522 $form_id = ! empty( $args['id'] ) ? (int) $args['id'] : uwp_get_option('register_modal_form', 1);
523 if ( $form_type == 'register' ) {
524 $fields = get_register_form_fields($form_id);
525 $form_limit = ! empty( $args['limit'] ) ? $args['limit'] : '';
526 if(isset($form_limit) && !is_array($form_limit)){
527 $form_limit = explode(',', $form_limit);
528 }
529
530 if(isset($form_limit) && !empty($form_limit) && count($form_limit) > 1){
531
532 $form_limit = array_map('uwp_clean', $form_limit);
533 $form_limit = array_map('trim', $form_limit);
534 $options = uwp_get_register_forms_dropdown_options($form_limit);
535 $id = wp_doing_ajax() ? "uwp-form-select-ajax" : 'uwp-form-select';
536
537
538 ?>
539 <div class="btn-group btn-group-sm mb-2" role="group" id="<?php echo $id; ?>">
540 <?php
541 $options = array_chunk( $options, 5, true );
542 $current_url = uwp_current_page_url();
543 if ( isset( $options[0] ) && ! empty( $options[0] ) && count( $options[0] ) > 1 ) {
544 foreach ( $options[0] as $id => $val ) {
545 $active = $form_id == $id ? 'active' : '';
546 $url = esc_url_raw( add_query_arg( array( 'uwp_form_id' => $id ), $current_url ) );
547 echo aui()->button( array(
548 'type' => 'a',
549 'href' => $url,
550 'class' => 'btn btn-secondary '.$active,
551 'content' => esc_attr( $val ),
552 'extra_attributes' => array('data-form_id'=>$id)
553 ) );
554 }
555 }elseif(count( $options[0] ) == 1){
556 $form_id = key($options[0]);
557 }
558
559 if ( isset( $options[1] ) && ! empty( $options[1] ) && count( $options[1] ) > 0 ) {
560 foreach ( $options[1] as $id => $val ) {
561 $active = $form_id == $id ? 'active' : '';
562 $url = esc_url_raw( add_query_arg( array( 'uwp_form_id' => $id ), $current_url ) );
563 ?>
564 <div class="btn-group" role="group">
565 <button id="uwp-form-select-dropdown" type="button" class="btn btn-secondary dropdown-toggle"
566 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
567 <?php _e('More', 'userswp'); ?>
568 </button>
569 <div class="dropdown-menu mt-3" aria-labelledby="uwp-form-select">
570 <?php
571 echo aui()->button( array(
572 'type' => 'a',
573 'href' => $url,
574 'class' => 'dropdown-item ' . $active,
575 'content' => esc_attr( $val ),
576 'extra_attributes' => array('data-form_id'=>$id)
577 ) );
578 ?>
579 </div>
580 </div>
581 <?php
582 }
583 }
584 ?>
585 </div>
586 <?php
587 }
588 } elseif ( $form_type == 'account' ) {
589 $fields = get_account_form_fields();
590 } elseif ( $form_type == 'change' ) {
591 $fields = get_change_form_fields();
592 } else {
593 $fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' ORDER BY sort_order ASC", array( $form_type ) ) );
594 }
595
596 if ( ! empty( $fields ) ) {
597 foreach ( $fields as $field ) {
598
599 if ( $form_type == 'account' ) {
600 if ( $field->htmlvar_name == 'display_name' ) {
601 if ( $field->is_active != '1' ) {
602 continue;
603 }
604 }
605 if ( $field->htmlvar_name == 'bio' ) {
606 if ( $field->is_active != '1' ) {
607 continue;
608 }
609 }
610 }
611
612 if ( $form_type == 'register' ) {
613 if ( $field->is_active != '1' ) {
614 continue;
615 }
616 $count = $wpdb->get_var( $wpdb->prepare( "select count(*) from " . $extras_table_name . " where site_htmlvar_name=%s AND form_type = %s AND form_id=%d", array(
617 $field->htmlvar_name,
618 $form_type,
619 $form_id
620 ) ) );
621 if ( $count == 1 ) {
622 $this->template_fields_html( $field, $form_type );
623 }
624 } else {
625 $this->template_fields_html( $field, $form_type );
626 }
627 }
628 }
629 }
630
631 /**
632 * Prints field html based on field type.
633 *
634 * @param object $field Field info.
635 * @param string $form_type Form type.
636 * @param int|bool $user_id User ID.
637 *
638 * @return void
639 * @since 1.0.0
640 * @package userswp
641 */
642 public function template_fields_html( $field, $form_type, $user_id = false ) {
643 if ( ! $user_id ) {
644 $user_id = get_current_user_id();
645 }
646
647 $value = $this->get_default_form_value( $field );
648 if ( $form_type == 'account' ) {
649 $user_data = get_userdata( $user_id );
650
651 if ( $field->htmlvar_name == 'email' ) {
652 $value = $user_data->user_email;
653 } elseif ( $field->htmlvar_name == 'password' ) {
654 $value = '';
655 $field->is_required = 0;
656 } elseif ( $field->htmlvar_name == 'confirm_password' ) {
657 $value = '';
658 $field->is_required = 0;
659 } else {
660 $value = uwp_get_usermeta( $user_id, $field->htmlvar_name, false );
661 if ( $value != '0' && ! $value ) {
662 $value = $this->get_default_form_value( $field );
663 }
664 }
665
666 }
667
668 if ( ! isset( $value ) ) {
669 $value = "";
670 }
671
672 if ( isset( $_POST[ $field->htmlvar_name ] ) && $field->field_type != 'password' ) {
673 $value = isset( $_POST[ $field->htmlvar_name ] ) ? $_POST[ $field->htmlvar_name ] : ''; //@todo: Used to pre fill form when validation fails, need to find better solution
674 }
675
676 if ( 'checkbox' == $field->field_type ) {
677 if ( in_array( $value, array( 'true', 'on', 1 ) ) ) {
678 $value = 1;
679 } else {
680 $value = 0;
681 }
682 }
683
684 $field = apply_filters( "uwp_form_input_field_{$field->field_type}", $field, $value, $form_type );
685
686 $html = apply_filters( "uwp_form_input_html_{$field->field_type}", "", $field, $value, $form_type );
687
688 if ( empty( $html ) ) {
689
690 $design_style = uwp_get_option( "design_style", "bootstrap" );
691 $bs_form_group = $design_style ? "form-group" : "";
692 $bs_sr_only = $design_style ? "sr-only" : "";
693 $bs_form_control = $design_style ? "form-control" : "";
694
695 ?>
696 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
697 class="<?php if ( $field->is_required ) {
698 echo 'required_field';
699 } ?> uwp_form_row clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
700 <?php
701
702 $label = $site_title = uwp_get_form_label( $field );
703 if ( ! is_admin() ) { ?>
704 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
705 <?php echo ( trim( $site_title ) ) ? $site_title : '&nbsp;'; ?>
706 <?php if ( $field->is_required ) {
707 echo '<span>*</span>';
708 } ?>
709 </label>
710 <?php } ?>
711
712 <input name="<?php echo esc_attr($field->htmlvar_name); ?>"
713 class="<?php echo esc_attr($field->css_class); ?> <?php echo esc_attr( $bs_form_control ); ?>"
714 placeholder="<?php echo uwp_get_field_placeholder( $field ); ?>"
715 title="<?php echo esc_attr($label); ?>"
716 <?php if ( $field->for_admin_use == 1 ) {
717 echo 'readonly="readonly"';
718 } ?>
719 <?php if ( $field->is_required == 1 ) {
720 echo 'required="required"';
721 } ?>
722 type="<?php echo esc_attr($field->field_type); ?>"
723 value="<?php echo esc_html( $value ); ?>">
724
725 </div>
726 <?php
727 } else {
728 echo $html;
729 }
730 }
731
732 /**
733 * Returns default value based on field type.
734 *
735 * @param object $field Field info.
736 *
737 * @return string Field default value.
738 * @since 1.0.0
739 * @package userswp
740 */
741 public function get_default_form_value( $field ) {
742 if ( $field->field_type == 'url' ) {
743 if ( substr( $field->default_value, 0, 4 ) === "http" ) {
744 $value = $field->default_value;
745 } else {
746 $value = "";
747 }
748 } else {
749 $value = $field->default_value;
750 }
751
752 return $value;
753 }
754
755 /**
756 * Display redirect to input of that particular form.
757 *
758 * @param string $form_type Form type.
759 *
760 * @return void
761 * @since 1.0.21
762 * @package userswp
763 */
764 public function template_extra_fields( $form_type, $args = array() ) {
765 if ( $form_type == 'login' ) {
766 $redirect_to = '';
767 if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) {
768 $redirect_to = $args['redirect_to'];
769 } elseif ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
770 $redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) );
771 } else {
772 if ( - 1 == uwp_get_option( 'login_redirect_to', - 1 ) ) {
773 $referer = wp_get_referer();
774 if ( isset( $referer ) && ! empty( $referer ) ) {
775 $redirect_to = $referer;
776 } else {
777 $redirect_to = home_url();
778 }
779 }
780 }
781
782 if ( $redirect_to ) {
783 echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>';
784 }
785
786 echo '<input type="hidden" name="uwp_login_nonce" value="' . wp_create_nonce( 'uwp-login-nonce' ) . '" />';
787 } elseif ( $form_type == 'register' ) {
788 $redirect_to = '';
789 $form_id = ! empty( $args['id'] ) ? $args['id'] : 1;
790 if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) {
791 $redirect_to = $args['redirect_to'];
792 } else {
793 $redirect_to_value = uwp_get_register_form_by( $form_id, 'redirect_to');
794 if(!$redirect_to_value){
795 $redirect_to_value = uwp_get_option( 'register_redirect_to', - 1 );
796 }
797
798 if ( - 1 == $redirect_to_value) {
799 $referer = wp_get_referer();
800 if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
801 $redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) );
802 } else if ( isset( $referer ) && ! empty( $referer ) ) {
803 $redirect_to = $referer;
804 } else {
805 $redirect_to = home_url();
806 }
807 }
808 }
809
810 if ( $redirect_to ) {
811 echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>';
812 }
813
814 $hash = substr( hash( 'SHA256', AUTH_KEY . site_url() ), 0, 25 );
815 echo '<input type="hidden" name="uwp_register_hash" value="' . $hash . '" style="display:none !important; visibility:hidden !important;" />';
816 echo '<input type="hidden" name="uwp_register_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />';
817 echo '<input type="hidden" name="uwp_register_nonce" value="' . wp_create_nonce( 'uwp-register-nonce' ) . '" />';
818 echo '<input type="hidden" name="uwp_register_form_id" value="' . absint($form_id) . '">';
819 } elseif ( $form_type == 'change' ) {
820 echo '<input type="hidden" name="uwp_change_nonce" value="' . wp_create_nonce( 'uwp-change-nonce' ) . '" />';
821 } elseif ( $form_type == 'forgot' ) {
822 echo '<input type="hidden" name="uwp_forgot_nonce" value="' . wp_create_nonce( 'uwp-forgot-nonce' ) . '" />';
823 } elseif ( $form_type == 'reset' ) {
824 if ( isset( $_GET['key'] ) && isset( $_GET['login'] ) ) {
825 echo '<input type="hidden" name="uwp_reset_username" value="' . esc_attr( $_GET['login'] ) . '" />';
826 echo '<input type="hidden" name="uwp_reset_key" value="' . esc_attr( $_GET['key'] ) . '" />';
827 }
828 echo '<input type="hidden" name="uwp_reset_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />';
829 echo '<input type="hidden" name="uwp_reset_nonce" value="' . wp_create_nonce( 'uwp-reset-nonce' ) . '" />';
830 }
831 }
832
833 /**
834 * Modifies the author page content with UsersWP profile content.
835 *
836 * @param string $content Original page content.
837 *
838 * @return string Modified page content.
839 * @since 1.0.0
840 * @package userswp
841 */
842 public function author_page_content( $content ) {
843 if ( is_author() && 1 != uwp_get_option( 'uwp_disable_author_link' ) && apply_filters( 'uwp_use_author_page_content', true ) ) {
844 return do_shortcode( '[uwp_profile]' );
845 } else {
846 return $content;
847 }
848
849 }
850
851 /**
852 * Modifies the menu item visibility based on UsersWP page type.
853 *
854 * @param object $menu_item Menu item info.
855 *
856 * @return object Modified menu item.
857 * @since 1.0.0
858 * @package userswp
859 */
860 public function setup_nav_menu_item( $menu_item ) {
861
862 if ( is_admin() ) {
863 return $menu_item;
864 }
865
866 // Prevent a notice error when using the customizer
867 $menu_classes = $menu_item->classes;
868
869 if ( is_array( $menu_classes ) ) {
870 $menu_classes = implode( ' ', $menu_item->classes );
871 $str = 'users-wp-menu ';
872 if ( strpos( $menu_classes, 'users-wp-menu ' ) !== false ) {
873 $menu_classes = str_replace( $str, '', $menu_classes );
874 }
875
876 $menu_classes = explode( " ", $menu_classes );
877 }
878
879 $register_slug = uwp_get_page_slug( 'register_page' );
880 $login_slug = uwp_get_page_slug( 'login_page' );
881 $change_slug = uwp_get_page_slug( 'change_page' );
882 $account_slug = uwp_get_page_slug( 'account_page' );
883 $profile_slug = uwp_get_page_slug( 'profile_page' );
884 $forgot_slug = uwp_get_page_slug( 'forgot_page' );
885 $logout_slug = "logout";
886
887 $register_class = "users-wp-{$register_slug}-nav";
888 $login_class = "users-wp-{$login_slug}-nav";
889 $change_class = "users-wp-{$change_slug}-nav";
890 $account_class = "users-wp-{$account_slug}-nav";
891 $profile_class = "users-wp-{$profile_slug}-nav";
892 $forgot_class = "users-wp-{$forgot_slug}-nav";
893 $logout_class = "users-wp-{$logout_slug}-nav";
894
895 if ( ! empty( $menu_classes ) ) {
896 foreach ( $menu_classes as $menu_class ) {
897 switch ( $menu_class ) {
898 case $register_class:
899 if ( is_user_logged_in() ) {
900 $menu_item->_invalid = true;
901 } else {
902 $menu_item->url = uwp_get_page_id( 'register_page', true );
903 }
904 break;
905 case $login_class:
906 if ( is_user_logged_in() ) {
907 $menu_item->_invalid = true;
908 } else {
909 $menu_item->url = uwp_get_page_id( 'login_page', true );
910 }
911 break;
912 case $account_class:
913 if ( ! is_user_logged_in() ) {
914 $menu_item->_invalid = true;
915 } else {
916 $menu_item->url = uwp_get_page_id( 'account_page', true );
917 }
918 break;
919 case $profile_class:
920 if ( ! is_user_logged_in() ) {
921 $menu_item->_invalid = true;
922 } else {
923 $menu_item->url = uwp_get_page_id( 'profile_page', true );
924 }
925 break;
926 case $change_class:
927 if ( ! is_user_logged_in() ) {
928 $menu_item->_invalid = true;
929 } else {
930 $menu_item->url = uwp_get_page_id( 'change_page', true );
931 }
932 break;
933 case $forgot_class:
934 if ( is_user_logged_in() ) {
935 $menu_item->_invalid = true;
936 } else {
937 $menu_item->url = uwp_get_page_id( 'forgot_page', true );
938 }
939 break;
940 case $logout_class:
941 if ( ! is_user_logged_in() ) {
942 $menu_item->_invalid = true;
943 } else {
944 $menu_item->url = $this->uwp_logout_url();
945 }
946 break;
947 }
948 }
949 }
950
951 $menu_item = apply_filters( 'uwp_setup_nav_menu_item', $menu_item, $menu_classes );
952
953 return $menu_item;
954
955 }
956
957 /**
958 * Returns the logout url by adding redirect page link.
959 *
960 * @param null $custom_redirect Redirect page link.
961 *
962 * @return string Logout url.
963 * @since 1.0.0
964 * @package userswp
965 */
966 public function uwp_logout_url( $custom_redirect = null ) {
967
968 $redirect = null;
969
970 $user = get_userdata(get_current_user_id());
971 if($user && isset($user->roles[0])){
972 $user_role = $user->roles[0];
973 $redirect_page_id = uwp_get_option( 'logout_redirect_to_'.$user_role );
974 }
975
976 if ( ! empty( $custom_redirect ) ) {
977 $redirect = esc_url( $custom_redirect );
978 } else if ( isset($redirect_page_id) && !empty($redirect_page_id) ) {
979 if ( uwp_is_wpml() ) {
980 $wpml_page_id = uwp_wpml_object_id( $redirect_page_id, 'page', true, ICL_LANGUAGE_CODE );
981 if ( ! empty( $wpml_page_id ) ) {
982 $redirect_page_id = $wpml_page_id;
983 }
984 }
985 $redirect = get_permalink( $redirect_page_id );
986 }
987
988 return wp_logout_url( apply_filters( 'uwp_logout_url', $redirect, $custom_redirect ) );
989
990 }
991
992 /**
993 * Adds the UsersWP body class to body tag.
994 *
995 * @param array $classes Existing class array.
996 *
997 * @return array Modified class array.
998 * @since 1.0.0
999 * @package userswp
1000 */
1001 public function add_body_class( $classes ) {
1002
1003 if ( is_uwp_page() ) {
1004 $classes[] = 'uwp_page';
1005
1006 if ( is_uwp_page( 'register_page' ) ) {
1007 $classes[] = 'uwp_register_page';
1008 } elseif ( is_uwp_page( 'login_page' ) ) {
1009 $classes[] = 'uwp_login_page';
1010 } elseif ( is_uwp_page( 'forgot_page' ) ) {
1011 $classes[] = 'uwp_forgot_page';
1012 } elseif ( is_uwp_page( 'change_page' ) ) {
1013 $classes[] = 'uwp_change_page';
1014 } elseif ( is_uwp_page( 'reset_page' ) ) {
1015 $classes[] = 'uwp_reset_page';
1016 } elseif ( is_uwp_page( 'account_page' ) ) {
1017 $classes[] = 'uwp_account_page';
1018 } elseif ( is_uwp_page( 'profile_page' ) ) {
1019 $classes[] = 'uwp_profile_page';
1020 } elseif ( is_uwp_page( 'users_page' ) ) {
1021 $classes[] = 'uwp_users_page';
1022 }
1023 }
1024
1025 return $classes;
1026 }
1027
1028 /**
1029 *
1030 * Returns content for author box
1031 *
1032 * @param $content
1033 *
1034 * @return string
1035 */
1036 public function author_box_page_content( $content ) {
1037
1038 global $post;
1039
1040 if ( is_single() ) {
1041
1042 $author_box_enable_disable = uwp_get_option( 'author_box_enable_disable', 1 );
1043
1044 if ( 1 == $author_box_enable_disable ) {
1045
1046 $author_box_display_post_types = uwp_get_option( 'author_box_display_post_types' );
1047
1048 if ( ! empty( $post->post_type ) && in_array( $post->post_type, (array) $author_box_display_post_types ) ) {
1049
1050 $author_box_display_content = uwp_get_option( 'author_box_display_content' );
1051
1052 if ( ! empty( $author_box_display_content ) && 'above_content' === $author_box_display_content ) {
1053 $content = do_shortcode( '[uwp_author_box]' ) . $content;
1054 } else {
1055 $content = $content . do_shortcode( '[uwp_author_box]' );
1056 }
1057
1058 // run block content if its available
1059 if ( function_exists( 'do_blocks' ) ) {
1060 $content = do_blocks( $content );
1061 }
1062 }
1063
1064 }
1065
1066 }
1067
1068 return $content;
1069 }
1070
1071 /**
1072 * Adds form html for privacy fields in account page.
1073 *
1074 * @param string $type Form type.
1075 *
1076 * @return void
1077 * @since 1.0.0
1078 * @package userswp
1079 *
1080 */
1081 public function privacy_edit_form_display( $type ) {
1082 if ( $type == 'privacy' ) {
1083 $make_profile_private = uwp_can_make_profile_private();
1084 echo '<div class="uwp-account-form">';
1085 $extra_where = "AND is_public='2'";
1086 $fields = get_account_form_fields( $extra_where );
1087 $fields = apply_filters( 'uwp_account_privacy_fields', $fields );
1088 $user_id = get_current_user_id();
1089 $design_style = uwp_get_option( "design_style", "bootstrap" );
1090 $bs_form_group = $design_style ? "form-group row" : "";
1091 $bs_form_control = $design_style ? "form-control" : "";
1092 $bs_btn_class = $design_style ? "btn btn-primary btn-block text-uppercase" : "";
1093 ?>
1094 <div class="uwp-profile-extra">
1095 <div class="uwp-profile-extra-div form-table">
1096 <form class="uwp-account-form uwp_form" method="post">
1097 <?php if ( $fields ) { ?>
1098 <div class="uwp-profile-extra-wrap <?php echo $bs_form_group; ?>">
1099 <div class="uwp-profile-extra-key col" style="font-weight: bold;">
1100 <?php _e( "Field", "userswp" ) ?>
1101 </div>
1102 <div class="uwp-profile-extra-value col" style="font-weight: bold;">
1103 <?php _e( "Is Public?", "userswp" ) ?>
1104 </div>
1105 </div>
1106 <?php foreach ( $fields as $field ) { ?>
1107 <div class="uwp-profile-extra-wrap <?php echo $bs_form_group; ?>">
1108 <div class="uwp-profile-extra-key col"><?php echo $field->site_title; ?>
1109 <span class="uwp-profile-extra-sep">:</span></div>
1110 <div class="uwp-profile-extra-value col">
1111 <?php
1112 $field_name = $field->htmlvar_name . '_privacy';
1113 $value = uwp_get_usermeta( $user_id, $field_name, false );
1114 if ( $value === false ) {
1115 $value = 'yes';
1116 }
1117 ?>
1118 <select name="<?php echo $field_name; ?>"
1119 class="uwp_privacy_field aui-select2 <?php echo $bs_form_control; ?>"
1120 style="margin: 0;">
1121 <option value="no" <?php selected( $value, "no" ); ?>><?php echo __( "No", "userswp" ) ?></option>
1122 <option value="yes" <?php selected( $value, "yes" ); ?>><?php echo __( "Yes", "userswp" ) ?></option>
1123 </select>
1124 </div>
1125 </div>
1126 <?php }
1127 }
1128
1129 global $wpdb;
1130 $tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs';
1131 $tabs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $tabs_table_name . " WHERE form_type=%s AND user_decided = 1 ORDER BY sort_order ASC", 'profile-tabs' ) );
1132
1133 if ( $tabs ) { ?>
1134 <div class="uwp-profile-extra-wrap <?php echo $bs_form_group; ?>">
1135 <div class="uwp-profile-extra-key col" style="font-weight: bold;">
1136 <?php _e( "Tab Name", "userswp" ) ?>
1137 </div>
1138 <div class="uwp-profile-extra-value col" style="font-weight: bold;">
1139 <?php _e( "Privacy", "userswp" ) ?>
1140 </div>
1141 </div>
1142 <?php }
1143
1144 foreach ( $tabs as $tab ) { ?>
1145 <div class="uwp-profile-extra-wrap <?php echo $bs_form_group; ?>">
1146 <div class="uwp-profile-extra-key col"><?php _e( $tab->tab_name, 'userswp' ); ?>
1147 <span class="uwp-profile-extra-sep">:</span></div>
1148 <div class="uwp-profile-extra-value col">
1149 <?php
1150 $field_name = $tab->tab_key . '_tab_privacy';
1151 $value = uwp_get_usermeta( $user_id, $field_name, '' );
1152
1153 $privacy_options = array(
1154 0 => __( "Anyone", "userswp" ),
1155 1 => __( "Logged in", "userswp" ),
1156 2 => __( "Author only", "userswp" ),
1157 );
1158
1159 // Admin default
1160 $admin_privacy = isset( $tab->tab_privacy ) ? absint( $tab->tab_privacy ) : 0;
1161 $privacy_options = apply_filters( 'uwp_tab_privacy_options', $privacy_options, $tab );
1162
1163 if ( empty( $value ) ) {
1164 $value = $admin_privacy;
1165 }
1166 ?>
1167 <select name="<?php echo $field_name; ?>"
1168 class="uwp_tab_privacy_field aui-select2 <?php echo $bs_form_control; ?>"
1169 style="margin: 0;">
1170 <?php
1171 foreach ( $privacy_options as $key => $val ) {
1172
1173 $default = '';
1174 if ( $admin_privacy == $key ) {
1175 $default = __( ' (Default)', 'userswp' );
1176 }
1177 echo '<option value="' . $key . '"' . selected( $value, $key, false ) . '>' . $val . $default . '</option>';
1178 }
1179 ?>
1180 </select>
1181 </div>
1182 </div>
1183 <?php }
1184
1185 $value = get_user_meta( $user_id, 'uwp_hide_from_listing', true ); ?>
1186 <div class="uwp-profile-extra-wrap">
1187 <div id="uwp_hide_from_listing" class="uwp_hide_from_listing">
1188 <input name="uwp_hide_from_listing" class="" <?php checked( $value, "1", true ); ?>
1189 type="checkbox"
1190 value="1"><?php _e( 'Hide profile from the users listing page.', 'userswp' ); ?>
1191 </div>
1192 </div>
1193 <?php
1194 do_action( 'uwp_after_privacy_form_fields', $fields );
1195 if ( $make_profile_private ) {
1196 $field_name = 'uwp_make_profile_private';
1197 $value = get_user_meta( $user_id, $field_name, true );
1198 if ( $value === false ) {
1199 $value = '0';
1200 }
1201 ?>
1202 <div id="uwp_make_profile_private" class=" uwp_make_profile_private_row">
1203 <input type="hidden" name="uwp_make_profile_private" value="0">
1204 <input name="uwp_make_profile_private" class="" <?php checked( $value, "1", true ); ?>
1205 type="checkbox" value="1">
1206 <?php _e( 'Make the whole profile private', 'userswp' ); ?>
1207 </div>
1208 <?php
1209 }
1210 ?>
1211 <input type="hidden" name="uwp_privacy_nonce"
1212 value="<?php echo wp_create_nonce( 'uwp-privacy-nonce' ); ?>"/>
1213 <input name="uwp_privacy_submit" class="<?php echo $bs_btn_class; ?>"
1214 value="<?php echo __( 'Submit', 'userswp' ); ?>" type="submit">
1215 </form>
1216 </div>
1217 </div>
1218 <?php
1219 echo '</div>';
1220 }
1221 }
1222
1223 /**
1224 * Redirects the user to login page when email not confirmed.
1225 *
1226 * @param string $username Username.
1227 * @param object $user User object.
1228 *
1229 * @return void
1230 * @package userswp
1231 *
1232 * @since 1.0.0
1233 */
1234 public function unconfirmed_login_redirect( $username, $user ) {
1235 if ( ! is_wp_error( $user ) ) {
1236 $mod_value = get_user_meta( $user->ID, 'uwp_mod', true );
1237 if ( $mod_value == 'email_unconfirmed' ) {
1238 if ( ! in_array( 'administrator', $user->roles ) ) {
1239 $login_page = uwp_get_page_id( 'login_page', false );
1240 if ( $login_page ) {
1241 $redirect_to = add_query_arg( array(
1242 'uwp_err' => 'act_pending',
1243 'user_id' => $user->ID
1244 ), get_permalink( $login_page ) );
1245 wp_destroy_current_session();
1246 wp_clear_auth_cookie();
1247 if ( wp_doing_ajax() ) {
1248 global $userswp;
1249 $message = $userswp->notices->form_notice_by_key( 'act_pending', false, $user->ID );
1250 wp_send_json_error( $message );
1251 } else {
1252 wp_redirect( $redirect_to );
1253 }
1254 exit();
1255 }
1256 }
1257 }
1258 }
1259 }
1260
1261 /**
1262 * Oxygen override theme template.
1263 *
1264 * @since 1.2.2.15
1265 *
1266 * @param string $located Located template.
1267 * @param string $template_name Template name.
1268 * @param array $located Template args.
1269 * @param string $template_path Template path.
1270 * @param string $default_path Template default path.
1271 * @return string Located template.
1272 */
1273 public function oxygen_override_template( $located, $template_name, $args, $template_path, $default_path ) {
1274 if ( $_located = $this->oxygen_locate_template( $template_name ) ) {
1275 $located = $_located;
1276 }
1277
1278 return $located;
1279 }
1280
1281 /**
1282 * Oxygen locate theme template.
1283 *
1284 * @since 1.2.2.15
1285 *
1286 * @param string $template The template.
1287 * @return string The theme template.
1288 */
1289 public function oxygen_locate_template( $template ) {
1290 $located = '';
1291
1292 if ( ! $template ) {
1293 return $located;
1294 }
1295
1296 $has_filter = has_filter( 'template', 'ct_oxygen_template_name' );
1297
1298 // Remove template filter
1299 if ( $has_filter ) {
1300 remove_filter( 'template', 'ct_oxygen_template_name' );
1301 }
1302
1303 $_located = $this->get_theme_template_path() . '/' . $template;
1304
1305 if ( file_exists( $_located ) ) {
1306 $located = $_located;
1307 }
1308
1309 // Add template filter
1310 if ( $has_filter ) {
1311 add_filter( 'template', 'ct_oxygen_template_name' );
1312 }
1313
1314 return $located;
1315 }
1316
1317 /**
1318 * Get the UsersWP templates theme path.
1319 *
1320 * @since 1.2.2.15
1321 *
1322 * @return string Template path.
1323 */
1324 public static function get_theme_template_path() {
1325 $template = get_template();
1326 $theme_root = get_theme_root( $template );
1327
1328 $theme_template_path = $theme_root . '/' . $template . '/' . untrailingslashit( uwp_get_theme_template_dir_name() );
1329
1330 return $theme_template_path;
1331 }
1332 }