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

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