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

1,358 lines 43.7 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', home_url( '/' ) );
332 wp_safe_redirect( $redirect_to );
333 exit();
334 }
335
336 }
337
338 }
339 }
340 }
341
342 /**
343 * Redirects user to a predefined page after logging out.
344 *
345 * @return void
346 * @package userswp
347 * @since 1.0.0
348 */
349 public function logout_redirect() {
350 $redirect_page_id = uwp_get_page_id( 'logout_redirect_to' );
351 if ( isset( $_REQUEST['redirect_to'] ) ) {
352 $redirect_to = esc_url( $_REQUEST['redirect_to'] );
353 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) {
354 $redirect_to = get_permalink( $redirect_page_id );
355 } else {
356 $redirect_to = home_url( '/' );
357 }
358 $redirect_to = apply_filters( 'uwp_logout_redirect', $redirect_to );
359 wp_safe_redirect( $redirect_to );
360 exit();
361 }
362
363 /**
364 * Redirects wp-login.php to UsersWP login page.
365 *
366 * @return void
367 * @package userswp
368 * @since 1.0.0
369 */
370 public function wp_login_redirect() {
371 global $pagenow;
372 if ( 'wp-login.php' == $pagenow && ! isset( $_REQUEST['action'] ) ) {
373 $login_page_id = uwp_get_page_id( 'login_page', false );
374 $block_wp_login = uwp_get_option( 'block_wp_login', '' );
375 if ( $login_page_id && $block_wp_login == '1' ) {
376 $redirect_to = get_permalink( $login_page_id );
377 if ( $redirect_to ) {
378 $redirect_to = add_query_arg( 'redirect_to', admin_url(), $redirect_to );
379 }
380 wp_safe_redirect( $redirect_to );
381 exit();
382 }
383 }
384 }
385
386 /**
387 * Redirects wp-login.php?action=register to UsersWP registration page.
388 *
389 * @return void
390 * @package userswp
391 * @since 1.0.0
392 */
393 public function wp_register_redirect() {
394
395 global $pagenow;
396 if ( 'wp-login.php' == $pagenow && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'register' ) {
397 $reg_page_id = uwp_get_page_id( 'register_page' );
398 $block_wp_reg = uwp_get_option( 'wp_register_redirect' );
399 if ( $reg_page_id && $block_wp_reg == '1' ) {
400
401 $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : '';
402 $redirect_to = get_permalink( $reg_page_id );
403 if ( $redirect ) {
404 $redirect_to = add_query_arg( 'redirect_to', $redirect, $redirect_to );
405 }
406 wp_safe_redirect( $redirect_to );
407 exit();
408 }
409 }
410 }
411
412 /**
413 * Changes the login url to the UWP login page.
414 *
415 * @param $login_url string The URL for login.
416 * @param $redirect string The URL to redirect back to upon successful login.
417 * @param $force_reauth bool Whether to force reauthorization, even if a cookie is present.
418 *
419 * @return string The login url.
420 * @package userswp
421 *
422 * @since 1.0.12
423 */
424 public function wp_login_url( $login_url, $redirect, $force_reauth ) {
425 global $pagenow;
426
427 if ( class_exists( 'Jetpack' ) && 'wp-login.php' == $pagenow && Jetpack::is_module_active( 'sso' ) ) {
428 return $login_url; // Do not change the URL for Jetpack SSO
429 }
430
431 if( did_action('init') === 0 ){
432 return $login_url; // Some plugin calls login link very early.
433 }
434
435 $login_page_id = uwp_get_page_id( 'login_page', false );
436 $redirect_page_id = uwp_get_page_id( 'login_redirect_to' );
437 if ( ( ! is_admin() || wp_doing_ajax() ) && $login_page_id ) {
438 $login_page = get_permalink( $login_page_id );
439 if ( $redirect ) {
440 $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_page );
441 } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 1 && wp_get_referer() ) {
442 $redirect_to = esc_url( wp_get_referer() );
443 $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page );
444 } elseif ( isset( $redirect_page_id ) && $redirect_page_id > 0 ) {
445 $redirect_to = get_permalink( $redirect_page_id );
446 $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page );
447 } else {
448 $login_url = $login_page;
449 }
450 }
451
452 return $login_url;
453 }
454
455 /**
456 * Changes the register url with the UWP register page.
457 *
458 * @param $register_url string The URL for register.
459 *
460 * @return string The register url.
461 * @since 1.0.22
462 *
463 */
464 public function wp_register_url( $register_url ) {
465 $register_page_id = uwp_get_page_id( 'register_page' );
466 $redirect_page_id = uwp_get_page_id( 'register_redirect_to' );
467
468 $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : '';
469 if ( isset( $register_page_id ) && $register_page_id > 0 ) {
470 $register_page = get_permalink( $register_page_id );
471 if ( $register_url && isset( $redirect ) && ! empty( $redirect ) ) {
472 $register_url = add_query_arg( 'redirect_to', $redirect, $register_page );
473 } elseif ( (int) $redirect_page_id > 0 ) {
474 $redirect_to = get_permalink( $redirect_page_id );
475 $register_url = add_query_arg( 'redirect_to', $redirect_to, $register_page );
476 } else {
477 $register_url = $register_page;
478 }
479 }
480
481 return $register_url;
482 }
483
484 /**
485 * Changes the lost password url with the UWP page.
486 *
487 * @param $lostpassword_url string The URL for lost password.
488 *
489 * @return string The lost password page url.
490 */
491 public function wp_lostpassword_url( $lostpassword_url ) {
492 $forgot_page_url = uwp_get_forgot_page_url();
493
494 if ( is_multisite() && isset( $_GET['redirect_to'] ) && false !== strpos( wp_unslash( $_GET['redirect_to'] ), network_admin_url() ) ) {
495 return $lostpassword_url;
496 }
497
498 $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : '';
499 if ( $forgot_page_url ) {
500 if ( $forgot_page_url && isset( $redirect ) && ! empty( $redirect ) ) {
501 $lostpassword_url = add_query_arg( 'redirect_to', $redirect, $forgot_page_url );
502 } else {
503 $lostpassword_url = $forgot_page_url;
504 }
505 }
506
507 return $lostpassword_url;
508 }
509
510 /**
511 * Prints html for form fields of that particular form.
512 *
513 * @param string $form_type Form type.
514 *
515 * @return void
516 * @since 1.0.0
517 * @package userswp
518 */
519 public function template_fields( $form_type, $args = array() ) {
520
521 global $wpdb, $aui_bs5;
522 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
523 $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
524
525 $form_id = ! empty( $args['id'] ) ? (int) $args['id'] : uwp_get_option('register_modal_form', 1);
526 if ( $form_type == 'register' ) {
527 $fields = get_register_form_fields($form_id);
528 $form_limit = ! empty( $args['limit'] ) ? $args['limit'] : '';
529 if(isset($form_limit) && !is_array($form_limit)){
530 $form_limit = explode(',', $form_limit);
531 }
532
533 if(isset($form_limit) && !empty($form_limit) && count($form_limit) > 1){
534
535 $form_limit = array_map('uwp_clean', $form_limit);
536 $form_limit = array_map('trim', $form_limit);
537 $options = uwp_get_register_forms_dropdown_options($form_limit);
538 $id = wp_doing_ajax() ? "uwp-form-select-ajax" : 'uwp-form-select';
539
540
541 ?>
542 <div class="btn-group btn-group-sm mb-2" role="group" id="<?php echo esc_attr( $id ); ?>">
543 <?php
544 $options = array_chunk( $options, 5, true );
545 $current_url = uwp_current_page_url();
546 if ( isset( $options[0] ) && ! empty( $options[0] ) && count( $options[0] ) > 1 ) {
547 foreach ( $options[0] as $id => $val ) {
548 $active = $form_id == $id ? 'active' : '';
549 $url = esc_url_raw( add_query_arg( array( 'uwp_form_id' => $id ), $current_url ) );
550 echo aui()->button( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
551 'type' => 'a',
552 'href' => esc_url( $url ),
553 'class' => 'btn btn-secondary '. esc_attr( $active ),
554 'content' => esc_attr( $val ),
555 'extra_attributes' => array('data-form_id'=> esc_attr( $id ) )
556 ) );
557 }
558 }elseif(count( $options[0] ) == 1){
559 $form_id = key($options[0]);
560 }
561
562 if ( isset( $options[1] ) && ! empty( $options[1] ) && count( $options[1] ) > 0 ) {
563 foreach ( $options[1] as $id => $val ) {
564 $active = $form_id == $id ? 'active' : '';
565 $url = esc_url_raw( add_query_arg( array( 'uwp_form_id' => $id ), $current_url ) );
566 ?>
567 <div class="btn-group" role="group">
568 <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">
569 <?php esc_attr_e('More', 'userswp'); ?>
570 </button>
571 <div class="dropdown-menu mt-3" aria-labelledby="uwp-form-select">
572 <?php
573 echo aui()->button( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
574 'type' => 'a',
575 'href' => esc_url( $url ),
576 'class' => 'dropdown-item ' . esc_attr( $active ),
577 'content' => esc_attr( $val ),
578 'extra_attributes' => array('data-form_id'=> esc_attr( $id ) )
579 ) );
580 ?>
581 </div>
582 </div>
583 <?php
584 }
585 }
586 ?>
587 </div>
588 <?php
589 }
590 } elseif ( $form_type == 'account' ) {
591 $fields = get_account_form_fields();
592 } elseif ( $form_type == 'change' ) {
593 $fields = get_change_form_fields();
594 } else {
595 $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 ) ) );
596 }
597
598 if ( ! empty( $fields ) ) {
599 foreach ( $fields as $field ) {
600
601 if ( $form_type == 'account' ) {
602 if ( $field->htmlvar_name == 'display_name' ) {
603 if ( $field->is_active != '1' ) {
604 continue;
605 }
606 }
607 if ( $field->htmlvar_name == 'bio' ) {
608 if ( $field->is_active != '1' ) {
609 continue;
610 }
611 }
612 }
613
614 if ( $form_type == 'register' ) {
615 if ( $field->is_active != '1' ) {
616 continue;
617 }
618 $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(
619 $field->htmlvar_name,
620 $form_type,
621 $form_id
622 ) ) );
623 if ( $count == 1 ) {
624 $this->template_fields_html( $field, $form_type );
625 }
626 } else {
627 $this->template_fields_html( $field, $form_type );
628 }
629 }
630 }
631 }
632
633 /**
634 * Prints field html based on field type.
635 *
636 * @param object $field Field info.
637 * @param string $form_type Form type.
638 * @param int|bool $user_id User ID.
639 *
640 * @return void
641 * @since 1.0.0
642 * @package userswp
643 */
644 public function template_fields_html( $field, $form_type, $user_id = false ) {
645 if ( ! $user_id ) {
646 $user_id = get_current_user_id();
647 }
648
649 $value = $this->get_default_form_value( $field );
650 if ( $form_type == 'account' ) {
651 $user_data = get_userdata( $user_id );
652
653 if ( $field->htmlvar_name == 'email' ) {
654 $value = $user_data->user_email;
655 } elseif ( $field->htmlvar_name == 'password' ) {
656 $value = '';
657 $field->is_required = 0;
658 } elseif ( $field->htmlvar_name == 'confirm_password' ) {
659 $value = '';
660 $field->is_required = 0;
661 } else {
662 $value = uwp_get_usermeta( $user_id, $field->htmlvar_name, false );
663 if ( $value != '0' && ! $value ) {
664 $value = $this->get_default_form_value( $field );
665 }
666 }
667
668 }
669
670 if ( ! isset( $value ) ) {
671 $value = "";
672 }
673
674 if ( isset( $_POST[ $field->htmlvar_name ] ) && $field->field_type != 'password' ) {
675 $value = isset( $_POST[ $field->htmlvar_name ] ) ? $_POST[ $field->htmlvar_name ] : ''; //@todo: Used to pre fill form when validation fails, need to find better solution
676 }
677
678 if ( 'checkbox' == $field->field_type ) {
679 if ( in_array( $value, array( 'true', 'on', 1 ) ) ) {
680 $value = 1;
681 } else {
682 $value = 0;
683 }
684 }
685
686 $field = apply_filters( "uwp_form_input_field_{$field->field_type}", $field, $value, $form_type );
687
688 $html = apply_filters( "uwp_form_input_html_{$field->field_type}", "", $field, $value, $form_type );
689
690 if ( empty( $html ) ) {
691
692 $design_style = uwp_get_option( "design_style", "bootstrap" );
693 $bs_form_group = $design_style ? "form-group mb-3" : "";
694 $bs_sr_only = $design_style ? "sr-only" : "";
695 $bs_form_control = $design_style ? "form-control" : "";
696
697 ?>
698 <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
699 class="<?php if ( $field->is_required ) {
700 echo 'required_field';
701 } ?> uwp_form_row clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
702 <?php
703
704 $label = $site_title = uwp_get_form_label( $field );
705 if ( ! is_admin() ) { ?>
706 <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
707 <?php echo ( trim( $site_title ) ) ? esc_attr( $site_title ) : '&nbsp;'; ?>
708 <?php if ( $field->is_required ) {
709 echo '<span>*</span>';
710 } ?>
711 </label>
712 <?php } ?>
713
714 <input name="<?php echo esc_attr($field->htmlvar_name); ?>"
715 class="<?php echo esc_attr($field->css_class); ?> <?php echo esc_attr( $bs_form_control ); ?>"
716 placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
717 title="<?php echo esc_attr($label); ?>"
718 <?php if ( $field->for_admin_use == 1 ) {
719 echo 'readonly="readonly"';
720 } ?>
721 <?php if ( $field->is_required == 1 ) {
722 echo 'required="required"';
723 } ?>
724 type="<?php echo esc_attr($field->field_type); ?>"
725 value="<?php echo esc_html( $value ); ?>">
726
727 </div>
728 <?php
729 } else {
730 echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
731 }
732 }
733
734 /**
735 * Returns default value based on field type.
736 *
737 * @param object $field Field info.
738 *
739 * @return string Field default value.
740 * @since 1.0.0
741 * @package userswp
742 */
743 public function get_default_form_value( $field ) {
744 if ( $field->field_type == 'url' ) {
745 if ( substr( $field->default_value, 0, 4 ) === "http" ) {
746 $value = $field->default_value;
747 } else {
748 $value = "";
749 }
750 } else {
751 $value = $field->default_value;
752 }
753
754 return $value;
755 }
756
757 /**
758 * Display redirect to input of that particular form.
759 *
760 * @param string $form_type Form type.
761 *
762 * @return void
763 * @since 1.0.21
764 * @package userswp
765 */
766 public function template_extra_fields( $form_type, $args = array() ) {
767 if ( $form_type == 'login' ) {
768 $redirect_to = '';
769 if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) {
770 $redirect_to = $args['redirect_to'];
771 } elseif ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
772 $redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) );
773 } else {
774 if ( - 1 == uwp_get_option( 'login_redirect_to', - 1 ) ) {
775 $referer = wp_get_referer();
776 if ( isset( $referer ) && ! empty( $referer ) ) {
777 $redirect_to = $referer;
778 } else {
779 $redirect_to = home_url();
780 }
781 }
782 }
783
784 if ( $redirect_to ) {
785 echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>';
786 }
787
788 echo '<input type="hidden" name="uwp_login_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-login-nonce' ) ) . '" />';
789 } elseif ( $form_type == 'register' ) {
790 $redirect_to = '';
791 $form_id = ! empty( $args['id'] ) ? $args['id'] : 1;
792 if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) {
793 $redirect_to = $args['redirect_to'];
794 } else {
795 $redirect_to_value = uwp_get_register_form_by( $form_id, 'redirect_to');
796 if(!$redirect_to_value){
797 $redirect_to_value = uwp_get_option( 'register_redirect_to', - 1 );
798 }
799
800 if ( - 1 == $redirect_to_value) {
801 $referer = wp_get_referer();
802 if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
803 $redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) );
804 } else if ( isset( $referer ) && ! empty( $referer ) ) {
805 $redirect_to = $referer;
806 } else {
807 $redirect_to = home_url();
808 }
809 }
810 }
811
812 if ( $redirect_to ) {
813 echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>';
814 }
815
816 $hash = substr( hash( 'SHA256', AUTH_KEY . site_url() ), 0, 25 );
817 echo '<input type="hidden" name="uwp_register_hash" value="' . esc_html( $hash ) . '" style="display:none !important; visibility:hidden !important;" />';
818 echo '<input type="hidden" name="uwp_register_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />';
819 echo '<input type="hidden" name="uwp_register_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-register-nonce' ) ) . '" />';
820 echo '<input type="hidden" name="uwp_register_form_id" value="' . absint($form_id) . '">';
821 } elseif ( $form_type == 'change' ) {
822 echo '<input type="hidden" name="uwp_change_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-change-nonce' ) ) . '" />';
823 } elseif ( $form_type == 'forgot' ) {
824 echo '<input type="hidden" name="uwp_forgot_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-forgot-nonce' ) ) . '" />';
825 } elseif ( $form_type == 'reset' ) {
826 if ( isset( $_GET['key'] ) && isset( $_GET['login'] ) ) {
827 echo '<input type="hidden" name="uwp_reset_username" value="' . esc_attr( $_GET['login'] ) . '" />';
828 echo '<input type="hidden" name="uwp_reset_key" value="' . esc_attr( $_GET['key'] ) . '" />';
829 }
830 echo '<input type="hidden" name="uwp_reset_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />';
831 echo '<input type="hidden" name="uwp_reset_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-reset-nonce' ) ) . '" />';
832 }
833 }
834
835 /**
836 * Modifies the author page content with UsersWP profile content.
837 *
838 * @param string $content Original page content.
839 *
840 * @return string Modified page content.
841 * @since 1.0.0
842 * @package userswp
843 */
844 public function author_page_content( $content ) {
845 if ( is_author() && 1 != uwp_get_option( 'uwp_disable_author_link' ) && apply_filters( 'uwp_use_author_page_content', true ) ) {
846 return do_shortcode( '[uwp_profile]' );
847 } else {
848 return $content;
849 }
850
851 }
852
853 /**
854 * Modifies the menu item visibility based on UsersWP page type.
855 *
856 * @param object $menu_item Menu item info.
857 *
858 * @return object Modified menu item.
859 * @since 1.0.0
860 * @package userswp
861 */
862 public function setup_nav_menu_item( $menu_item ) {
863
864 if ( is_admin() ) {
865 return $menu_item;
866 }
867
868 // Prevent a notice error when using the customizer
869 $menu_classes = $menu_item->classes;
870
871 if ( is_array( $menu_classes ) ) {
872 $menu_classes = implode( ' ', $menu_item->classes );
873 $str = 'users-wp-menu ';
874 if ( strpos( $menu_classes, 'users-wp-menu ' ) !== false ) {
875 $menu_classes = str_replace( $str, '', $menu_classes );
876 }
877
878 $menu_classes = explode( " ", $menu_classes );
879 }
880
881 $register_slug = uwp_get_page_slug( 'register_page' );
882 $login_slug = uwp_get_page_slug( 'login_page' );
883 $change_slug = uwp_get_page_slug( 'change_page' );
884 $account_slug = uwp_get_page_slug( 'account_page' );
885 $profile_slug = uwp_get_page_slug( 'profile_page' );
886 $forgot_slug = uwp_get_page_slug( 'forgot_page' );
887 $logout_slug = "logout";
888
889 $register_class = "users-wp-{$register_slug}-nav";
890 $login_class = "users-wp-{$login_slug}-nav";
891 $change_class = "users-wp-{$change_slug}-nav";
892 $account_class = "users-wp-{$account_slug}-nav";
893 $profile_class = "users-wp-{$profile_slug}-nav";
894 $forgot_class = "users-wp-{$forgot_slug}-nav";
895 $logout_class = "users-wp-{$logout_slug}-nav";
896
897 if ( ! empty( $menu_classes ) ) {
898 foreach ( $menu_classes as $menu_class ) {
899 switch ( $menu_class ) {
900 case $register_class:
901 if ( is_user_logged_in() ) {
902 $menu_item->_invalid = true;
903 } else {
904 $menu_item->url = uwp_get_page_id( 'register_page', true );
905 }
906 break;
907 case $login_class:
908 if ( is_user_logged_in() ) {
909 $menu_item->_invalid = true;
910 } else {
911 $menu_item->url = uwp_get_page_id( 'login_page', true );
912 }
913 break;
914 case $account_class:
915 if ( ! is_user_logged_in() ) {
916 $menu_item->_invalid = true;
917 } else {
918 $menu_item->url = uwp_get_page_id( 'account_page', true );
919 }
920 break;
921 case $profile_class:
922 if ( ! is_user_logged_in() ) {
923 $menu_item->_invalid = true;
924 } else {
925 $menu_item->url = uwp_get_page_id( 'profile_page', true );
926 }
927 break;
928 case $change_class:
929 if ( ! is_user_logged_in() ) {
930 $menu_item->_invalid = true;
931 } else {
932 $menu_item->url = uwp_get_page_id( 'change_page', true );
933 }
934 break;
935 case $forgot_class:
936 if ( is_user_logged_in() ) {
937 $menu_item->_invalid = true;
938 } else {
939 $menu_item->url = uwp_get_page_id( 'forgot_page', true );
940 }
941 break;
942 case $logout_class:
943 if ( ! is_user_logged_in() ) {
944 $menu_item->_invalid = true;
945 } else {
946 $menu_item->url = $this->uwp_logout_url();
947 }
948 break;
949 }
950 }
951 }
952
953 $menu_item = apply_filters( 'uwp_setup_nav_menu_item', $menu_item, $menu_classes );
954
955 return $menu_item;
956
957 }
958
959 /**
960 * Returns the logout url by adding redirect page link.
961 *
962 * @param null $custom_redirect Redirect page link.
963 *
964 * @return string Logout url.
965 * @since 1.0.0
966 * @package userswp
967 */
968 public function uwp_logout_url( $custom_redirect = null ) {
969
970 $redirect = null;
971
972 $user = get_userdata(get_current_user_id());
973 if($user && isset($user->roles[0])){
974 $user_role = $user->roles[0];
975 $redirect_page_id = uwp_get_option( 'logout_redirect_to_'.$user_role );
976 }
977
978 if ( ! empty( $custom_redirect ) ) {
979 $redirect = esc_url( $custom_redirect );
980 } else if ( isset($redirect_page_id) && !empty($redirect_page_id) ) {
981 if ( uwp_is_wpml() ) {
982 $wpml_page_id = uwp_wpml_object_id( $redirect_page_id, 'page', true, ICL_LANGUAGE_CODE );
983 if ( ! empty( $wpml_page_id ) ) {
984 $redirect_page_id = $wpml_page_id;
985 }
986 }
987 $redirect = get_permalink( $redirect_page_id );
988 }
989
990 return wp_logout_url( apply_filters( 'uwp_logout_url', $redirect, $custom_redirect ) );
991
992 }
993
994 /**
995 * Adds the UsersWP body class to body tag.
996 *
997 * @param array $classes Existing class array.
998 *
999 * @return array Modified class array.
1000 * @since 1.0.0
1001 * @package userswp
1002 */
1003 public function add_body_class( $classes ) {
1004
1005 if ( is_uwp_page() ) {
1006 $classes[] = 'uwp_page';
1007
1008 if ( is_uwp_page( 'register_page' ) ) {
1009 $classes[] = 'uwp_register_page';
1010 } elseif ( is_uwp_page( 'login_page' ) ) {
1011 $classes[] = 'uwp_login_page';
1012 } elseif ( is_uwp_page( 'forgot_page' ) ) {
1013 $classes[] = 'uwp_forgot_page';
1014 } elseif ( is_uwp_page( 'change_page' ) ) {
1015 $classes[] = 'uwp_change_page';
1016 } elseif ( is_uwp_page( 'reset_page' ) ) {
1017 $classes[] = 'uwp_reset_page';
1018 } elseif ( is_uwp_page( 'account_page' ) ) {
1019 $classes[] = 'uwp_account_page';
1020 } elseif ( is_uwp_page( 'profile_page' ) ) {
1021 $classes[] = 'uwp_profile_page';
1022 } elseif ( is_uwp_page( 'users_page' ) ) {
1023 $classes[] = 'uwp_users_page';
1024 }
1025 }
1026
1027 return $classes;
1028 }
1029
1030 /**
1031 *
1032 * Returns content for author box
1033 *
1034 * @param $content
1035 *
1036 * @return string
1037 */
1038 public function author_box_page_content( $content ) {
1039
1040 global $post;
1041
1042 if ( is_single() ) {
1043
1044 $author_box_enable_disable = uwp_get_option( 'author_box_enable_disable', 1 );
1045
1046 if ( 1 == $author_box_enable_disable ) {
1047
1048 $author_box_display_post_types = uwp_get_option( 'author_box_display_post_types' );
1049
1050 if ( ! empty( $post->post_type ) && in_array( $post->post_type, (array) $author_box_display_post_types ) ) {
1051
1052 $author_box_display_content = uwp_get_option( 'author_box_display_content' );
1053
1054 if ( ! empty( $author_box_display_content ) && 'above_content' === $author_box_display_content ) {
1055 $content = do_shortcode( '[uwp_author_box]' ) . $content;
1056 } else {
1057 $content = $content . do_shortcode( '[uwp_author_box]' );
1058 }
1059
1060 // run block content if its available
1061 if ( function_exists( 'do_blocks' ) ) {
1062 $content = do_blocks( $content );
1063 }
1064 }
1065
1066 }
1067
1068 }
1069
1070 return $content;
1071 }
1072
1073 /**
1074 * Adds form html for privacy fields in account page.
1075 *
1076 * @param string $type Form type.
1077 *
1078 * @return void
1079 * @since 1.0.0
1080 * @package userswp
1081 *
1082 */
1083 public function privacy_edit_form_display( $type ) {
1084 if ( $type == 'privacy' ) {
1085 $make_profile_private = uwp_can_make_profile_private();
1086 echo '<div class="uwp-account-form">';
1087 $extra_where = "AND is_public='2'";
1088 $fields = get_account_form_fields( $extra_where );
1089 $fields = apply_filters( 'uwp_account_privacy_fields', $fields );
1090 $user_id = get_current_user_id();
1091 $form_id = uwp_get_register_form_id( $user_id );
1092 $design_style = uwp_get_option( "design_style", "bootstrap" );
1093 $bs_form_group = $design_style ? "form-group mb-3 row" : "";
1094 $bs_form_control = $design_style ? "form-control" : "";
1095 $bs_btn_class = $design_style ? "btn btn-primary btn-block text-uppercase" : "";
1096 ?>
1097 <div class="uwp-profile-extra">
1098 <div class="uwp-profile-extra-div form-table">
1099 <form class="uwp-account-form uwp_form" method="post">
1100 <?php if ( $fields ) { ?>
1101 <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1102 <div class="uwp-profile-extra-key col" style="font-weight: bold;">
1103 <?php esc_attr_e( "Field", "userswp" ) ?>
1104 </div>
1105 <div class="uwp-profile-extra-value col" style="font-weight: bold;">
1106 <?php esc_attr_e( "Is Public?", "userswp" ) ?>
1107 </div>
1108 </div>
1109 <?php foreach ( $fields as $field ) { ?>
1110 <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1111 <div class="uwp-profile-extra-key col"><?php echo esc_attr( $field->site_title ); ?>
1112 <span class="uwp-profile-extra-sep">:</span></div>
1113 <div class="uwp-profile-extra-value col">
1114 <?php
1115 $field_name = $field->htmlvar_name . '_privacy';
1116 $value = uwp_get_usermeta( $user_id, $field_name, false );
1117 if ( $value === false ) {
1118 $value = 'yes';
1119 }
1120 ?>
1121 <select name="<?php echo esc_attr( $field_name ); ?>"
1122 class="uwp_privacy_field aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
1123 style="margin: 0;">
1124 <option value="no" <?php selected( $value, "no" ); ?>><?php esc_attr_e( "No", "userswp" ) ?></option>
1125 <option value="yes" <?php selected( $value, "yes" ); ?>><?php esc_attr_e( "Yes", "userswp" ) ?></option>
1126 </select>
1127 </div>
1128 </div>
1129 <?php }
1130 }
1131
1132 global $wpdb;
1133 $tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs';
1134 $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) ) );
1135
1136 if ( $tabs ) { ?>
1137 <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1138 <div class="uwp-profile-extra-key col" style="font-weight: bold;">
1139 <?php esc_attr_e( "Tab Name", "userswp" ) ?>
1140 </div>
1141 <div class="uwp-profile-extra-value col" style="font-weight: bold;">
1142 <?php esc_attr_e( "Privacy", "userswp" ) ?>
1143 </div>
1144 </div>
1145 <?php }
1146
1147 foreach ( $tabs as $tab ) { ?>
1148 <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1149 <div class="uwp-profile-extra-key col"><?php esc_attr_e( $tab->tab_name, 'userswp' ); ?>
1150 <span class="uwp-profile-extra-sep">:</span></div>
1151 <div class="uwp-profile-extra-value col">
1152 <?php
1153 $field_name = $tab->tab_key . '_tab_privacy';
1154 $value = uwp_get_usermeta( $user_id, $field_name, '' );
1155
1156 $privacy_options = array(
1157 0 => __( "Anyone", "userswp" ),
1158 1 => __( "Logged in", "userswp" ),
1159 2 => __( "Author only", "userswp" ),
1160 );
1161
1162 // Admin default
1163 $admin_privacy = isset( $tab->tab_privacy ) ? absint( $tab->tab_privacy ) : 0;
1164 $privacy_options = apply_filters( 'uwp_tab_privacy_options', $privacy_options, $tab );
1165
1166 if ( empty( $value ) ) {
1167 $value = $admin_privacy;
1168 }
1169 ?>
1170 <select name="<?php echo esc_attr( $field_name ); ?>"
1171 class="uwp_tab_privacy_field aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
1172 style="margin: 0;">
1173 <?php
1174 foreach ( $privacy_options as $key => $val ) {
1175
1176 $default = '';
1177 if ( $admin_privacy == $key ) {
1178 $default = __( ' (Default)', 'userswp' );
1179 }
1180 echo '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key, false ) . '>' . esc_attr( $val . $default ) . '</option>';
1181 }
1182 ?>
1183 </select>
1184 </div>
1185 </div>
1186 <?php }
1187
1188 $value = get_user_meta( $user_id, 'uwp_hide_from_listing', true ); ?>
1189 <div class="uwp-profile-extra-wrap">
1190 <div id="uwp_hide_from_listing" class="uwp_hide_from_listing">
1191 <input name="uwp_hide_from_listing" class="" <?php checked( $value, "1", true ); ?>
1192 type="checkbox"
1193 value="1"><?php esc_attr_e( 'Hide profile from the users listing page.', 'userswp' ); ?>
1194 </div>
1195 </div>
1196 <?php
1197 do_action( 'uwp_after_privacy_form_fields', $fields );
1198 if ( $make_profile_private ) {
1199 $field_name = 'uwp_make_profile_private';
1200 $value = get_user_meta( $user_id, $field_name, true );
1201 if ( $value === false ) {
1202 $value = '0';
1203 }
1204 ?>
1205 <div id="uwp_make_profile_private" class=" uwp_make_profile_private_row">
1206 <input type="hidden" name="uwp_make_profile_private" value="0">
1207 <input name="uwp_make_profile_private" class="" <?php checked( $value, "1", true ); ?>
1208 type="checkbox" value="1">
1209 <?php esc_attr_e( 'Make the whole profile private', 'userswp' ); ?>
1210 </div>
1211 <?php
1212 }
1213 ?>
1214 <input type="hidden" name="uwp_privacy_nonce"
1215 value="<?php echo esc_attr( wp_create_nonce( 'uwp-privacy-nonce' ) ); ?>"/>
1216 <input name="uwp_privacy_submit" class="<?php echo esc_attr( $bs_btn_class ); ?>"
1217 value="<?php esc_attr_e( 'Submit', 'userswp' ); ?>" type="submit">
1218 </form>
1219 </div>
1220 </div>
1221 <?php
1222 echo '</div>';
1223 }
1224 }
1225
1226 /**
1227 * Redirects the user to login page when email not confirmed.
1228 *
1229 * @param string $username Username.
1230 * @param object $user User object.
1231 *
1232 * @return void
1233 * @package userswp
1234 *
1235 * @since 1.0.0
1236 */
1237 public function unconfirmed_login_redirect( $username, $user ) {
1238 if ( ! is_wp_error( $user ) ) {
1239 $mod_value = get_user_meta( $user->ID, 'uwp_mod', true );
1240 if ( $mod_value == 'email_unconfirmed' ) {
1241 if ( ! in_array( 'administrator', $user->roles ) ) {
1242 $login_page = uwp_get_page_id( 'login_page', false );
1243 if ( $login_page ) {
1244 $redirect_to = add_query_arg( array(
1245 'uwp_err' => 'act_pending',
1246 'user_id' => $user->ID
1247 ), get_permalink( $login_page ) );
1248 wp_destroy_current_session();
1249 wp_clear_auth_cookie();
1250 if ( wp_doing_ajax() ) {
1251 global $userswp;
1252 $message = $userswp->notices->form_notice_by_key( 'act_pending', false, $user->ID );
1253 wp_send_json_error( $message );
1254 } else {
1255 wp_redirect( $redirect_to );
1256 }
1257 exit();
1258 }
1259 }
1260 }
1261 }
1262 }
1263
1264 /**
1265 * Oxygen override theme template.
1266 *
1267 * @since 1.2.2.15
1268 *
1269 * @param string $located Located template.
1270 * @param string $template_name Template name.
1271 * @param array $located Template args.
1272 * @param string $template_path Template path.
1273 * @param string $default_path Template default path.
1274 * @return string Located template.
1275 */
1276 public function oxygen_override_template( $located, $template_name, $args, $template_path, $default_path ) {
1277 if ( $_located = $this->oxygen_locate_template( $template_name ) ) {
1278 $located = $_located;
1279 }
1280
1281 return $located;
1282 }
1283
1284 /**
1285 * Oxygen locate theme template.
1286 *
1287 * @since 1.2.2.15
1288 *
1289 * @param string $template The template.
1290 * @return string The theme template.
1291 */
1292 public function oxygen_locate_template( $template ) {
1293 $located = '';
1294
1295 if ( ! $template ) {
1296 return $located;
1297 }
1298
1299 $has_filter = has_filter( 'template', 'ct_oxygen_template_name' );
1300
1301 // Remove template filter
1302 if ( $has_filter ) {
1303 remove_filter( 'template', 'ct_oxygen_template_name' );
1304 }
1305
1306 $_located = $this->get_theme_template_path() . '/' . $template;
1307
1308 if ( file_exists( $_located ) ) {
1309 $located = $_located;
1310 }
1311
1312 // Add template filter
1313 if ( $has_filter ) {
1314 add_filter( 'template', 'ct_oxygen_template_name' );
1315 }
1316
1317 return $located;
1318 }
1319
1320 /**
1321 * Get the UsersWP templates theme path.
1322 *
1323 * @since 1.2.2.15
1324 *
1325 * @return string Template path.
1326 */
1327 public static function get_theme_template_path() {
1328 $template = get_template();
1329 $theme_root = get_theme_root( $template );
1330
1331 $theme_template_path = $theme_root . '/' . $template . '/' . untrailingslashit( uwp_get_theme_template_dir_name() );
1332
1333 return $theme_template_path;
1334 }
1335
1336 /**
1337 * Check & unset the_content hook.
1338 *
1339 * @since 1.2.13
1340 *
1341 * @param string $content The content.
1342 * @return string The post content.
1343 */
1344 public function set_the_content_hook( $content ) {
1345 global $wp_query, $post, $uwp_set_wpautop;
1346
1347 // Prevent empty p tags on block theme.
1348 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() ) {
1349 if ( $has_filter = has_filter( 'the_content', 'wpautop' ) ) {
1350 $uwp_set_wpautop = $has_filter;
1351
1352 remove_filter( 'the_content', 'wpautop' );
1353 }
1354 }
1355
1356 return $content;
1357 }
1358 }