PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.38
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.38
1.2.73 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 All 173 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.38, at includes/class-templates.php

1,362 lines 43.8 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 d-flex 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' => '#',
553 'class' => 'btn btn-outline-primary '. 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 $redirect_to = apply_filters('uwp_login_redirect_to', $redirect_to, $args);
785
786 if ( $redirect_to ) {
787 echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>';
788 }
789
790 echo '<input type="hidden" name="uwp_login_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-login-nonce' ) ) . '" />';
791 } elseif ( $form_type == 'register' ) {
792 $redirect_to = '';
793 $form_id = ! empty( $args['id'] ) ? $args['id'] : 1;
794 if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) {
795 $redirect_to = $args['redirect_to'];
796 } else {
797 $redirect_to_value = uwp_get_register_form_by( $form_id, 'redirect_to');
798 if(!$redirect_to_value){
799 $redirect_to_value = uwp_get_option( 'register_redirect_to', - 1 );
800 }
801
802 if ( - 1 == $redirect_to_value) {
803 $referer = wp_get_referer();
804 if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
805 $redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) );
806 } else if ( isset( $referer ) && ! empty( $referer ) ) {
807 $redirect_to = $referer;
808 } else {
809 $redirect_to = home_url();
810 }
811 }
812 }
813
814 $redirect_to = apply_filters('uwp_register_redirect_to', $redirect_to, $args);
815
816 if ( $redirect_to ) {
817 echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>';
818 }
819
820 $hash = substr( hash( 'SHA256', AUTH_KEY . site_url() ), 0, 25 );
821 echo '<input type="hidden" name="uwp_register_hash" value="' . esc_html( $hash ) . '" style="display:none !important; visibility:hidden !important;" />';
822 echo '<input type="hidden" name="uwp_register_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />';
823 echo '<input type="hidden" name="uwp_register_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-register-nonce' ) ) . '" />';
824 echo '<input type="hidden" name="uwp_register_form_id" value="' . absint($form_id) . '">';
825 } elseif ( $form_type == 'change' ) {
826 echo '<input type="hidden" name="uwp_change_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-change-nonce' ) ) . '" />';
827 } elseif ( $form_type == 'forgot' ) {
828 echo '<input type="hidden" name="uwp_forgot_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-forgot-nonce' ) ) . '" />';
829 } elseif ( $form_type == 'reset' ) {
830 if ( isset( $_GET['key'] ) && isset( $_GET['login'] ) ) {
831 echo '<input type="hidden" name="uwp_reset_username" value="' . esc_attr( $_GET['login'] ) . '" />';
832 echo '<input type="hidden" name="uwp_reset_key" value="' . esc_attr( $_GET['key'] ) . '" />';
833 }
834 echo '<input type="hidden" name="uwp_reset_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />';
835 echo '<input type="hidden" name="uwp_reset_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-reset-nonce' ) ) . '" />';
836 }
837 }
838
839 /**
840 * Modifies the author page content with UsersWP profile content.
841 *
842 * @param string $content Original page content.
843 *
844 * @return string Modified page content.
845 * @since 1.0.0
846 * @package userswp
847 */
848 public function author_page_content( $content ) {
849 if ( is_author() && 1 != uwp_get_option( 'uwp_disable_author_link' ) && apply_filters( 'uwp_use_author_page_content', true ) ) {
850 return do_shortcode( '[uwp_profile]' );
851 } else {
852 return $content;
853 }
854
855 }
856
857 /**
858 * Modifies the menu item visibility based on UsersWP page type.
859 *
860 * @param object $menu_item Menu item info.
861 *
862 * @return object Modified menu item.
863 * @since 1.0.0
864 * @package userswp
865 */
866 public function setup_nav_menu_item( $menu_item ) {
867
868 if ( is_admin() ) {
869 return $menu_item;
870 }
871
872 // Prevent a notice error when using the customizer
873 $menu_classes = $menu_item->classes;
874
875 if ( is_array( $menu_classes ) ) {
876 $menu_classes = implode( ' ', $menu_item->classes );
877 $str = 'users-wp-menu ';
878 if ( strpos( $menu_classes, 'users-wp-menu ' ) !== false ) {
879 $menu_classes = str_replace( $str, '', $menu_classes );
880 }
881
882 $menu_classes = explode( " ", $menu_classes );
883 }
884
885 $register_slug = uwp_get_page_slug( 'register_page' );
886 $login_slug = uwp_get_page_slug( 'login_page' );
887 $change_slug = uwp_get_page_slug( 'change_page' );
888 $account_slug = uwp_get_page_slug( 'account_page' );
889 $profile_slug = uwp_get_page_slug( 'profile_page' );
890 $forgot_slug = uwp_get_page_slug( 'forgot_page' );
891 $logout_slug = "logout";
892
893 $register_class = "users-wp-{$register_slug}-nav";
894 $login_class = "users-wp-{$login_slug}-nav";
895 $change_class = "users-wp-{$change_slug}-nav";
896 $account_class = "users-wp-{$account_slug}-nav";
897 $profile_class = "users-wp-{$profile_slug}-nav";
898 $forgot_class = "users-wp-{$forgot_slug}-nav";
899 $logout_class = "users-wp-{$logout_slug}-nav";
900
901 if ( ! empty( $menu_classes ) ) {
902 foreach ( $menu_classes as $menu_class ) {
903 switch ( $menu_class ) {
904 case $register_class:
905 if ( is_user_logged_in() ) {
906 $menu_item->_invalid = true;
907 } else {
908 $menu_item->url = uwp_get_page_id( 'register_page', true );
909 }
910 break;
911 case $login_class:
912 if ( is_user_logged_in() ) {
913 $menu_item->_invalid = true;
914 } else {
915 $menu_item->url = uwp_get_page_id( 'login_page', true );
916 }
917 break;
918 case $account_class:
919 if ( ! is_user_logged_in() ) {
920 $menu_item->_invalid = true;
921 } else {
922 $menu_item->url = uwp_get_page_id( 'account_page', true );
923 }
924 break;
925 case $profile_class:
926 if ( ! is_user_logged_in() ) {
927 $menu_item->_invalid = true;
928 } else {
929 $menu_item->url = uwp_get_page_id( 'profile_page', true );
930 }
931 break;
932 case $change_class:
933 if ( ! is_user_logged_in() ) {
934 $menu_item->_invalid = true;
935 } else {
936 $menu_item->url = uwp_get_page_id( 'change_page', true );
937 }
938 break;
939 case $forgot_class:
940 if ( is_user_logged_in() ) {
941 $menu_item->_invalid = true;
942 } else {
943 $menu_item->url = uwp_get_page_id( 'forgot_page', true );
944 }
945 break;
946 case $logout_class:
947 if ( ! is_user_logged_in() ) {
948 $menu_item->_invalid = true;
949 } else {
950 $menu_item->url = $this->uwp_logout_url();
951 }
952 break;
953 }
954 }
955 }
956
957 $menu_item = apply_filters( 'uwp_setup_nav_menu_item', $menu_item, $menu_classes );
958
959 return $menu_item;
960
961 }
962
963 /**
964 * Returns the logout url by adding redirect page link.
965 *
966 * @param null $custom_redirect Redirect page link.
967 *
968 * @return string Logout url.
969 * @since 1.0.0
970 * @package userswp
971 */
972 public function uwp_logout_url( $custom_redirect = null ) {
973
974 $redirect = null;
975
976 $user = get_userdata(get_current_user_id());
977 if($user && isset($user->roles[0])){
978 $user_role = $user->roles[0];
979 $redirect_page_id = uwp_get_option( 'logout_redirect_to_'.$user_role );
980 }
981
982 if ( ! empty( $custom_redirect ) ) {
983 $redirect = esc_url( $custom_redirect );
984 } else if ( isset($redirect_page_id) && !empty($redirect_page_id) ) {
985 if ( uwp_is_wpml() ) {
986 $wpml_page_id = uwp_wpml_object_id( $redirect_page_id, 'page', true, ICL_LANGUAGE_CODE );
987 if ( ! empty( $wpml_page_id ) ) {
988 $redirect_page_id = $wpml_page_id;
989 }
990 }
991 $redirect = get_permalink( $redirect_page_id );
992 }
993
994 return wp_logout_url( apply_filters( 'uwp_logout_url', $redirect, $custom_redirect ) );
995
996 }
997
998 /**
999 * Adds the UsersWP body class to body tag.
1000 *
1001 * @param array $classes Existing class array.
1002 *
1003 * @return array Modified class array.
1004 * @since 1.0.0
1005 * @package userswp
1006 */
1007 public function add_body_class( $classes ) {
1008
1009 if ( is_uwp_page() ) {
1010 $classes[] = 'uwp_page';
1011
1012 if ( is_uwp_page( 'register_page' ) ) {
1013 $classes[] = 'uwp_register_page';
1014 } elseif ( is_uwp_page( 'login_page' ) ) {
1015 $classes[] = 'uwp_login_page';
1016 } elseif ( is_uwp_page( 'forgot_page' ) ) {
1017 $classes[] = 'uwp_forgot_page';
1018 } elseif ( is_uwp_page( 'change_page' ) ) {
1019 $classes[] = 'uwp_change_page';
1020 } elseif ( is_uwp_page( 'reset_page' ) ) {
1021 $classes[] = 'uwp_reset_page';
1022 } elseif ( is_uwp_page( 'account_page' ) ) {
1023 $classes[] = 'uwp_account_page';
1024 } elseif ( is_uwp_page( 'profile_page' ) ) {
1025 $classes[] = 'uwp_profile_page';
1026 } elseif ( is_uwp_page( 'users_page' ) ) {
1027 $classes[] = 'uwp_users_page';
1028 }
1029 }
1030
1031 return $classes;
1032 }
1033
1034 /**
1035 *
1036 * Returns content for author box
1037 *
1038 * @param $content
1039 *
1040 * @return string
1041 */
1042 public function author_box_page_content( $content ) {
1043
1044 global $post;
1045
1046 if ( is_single() ) {
1047
1048 $author_box_enable_disable = uwp_get_option( 'author_box_enable_disable', 1 );
1049
1050 if ( 1 == $author_box_enable_disable ) {
1051
1052 $author_box_display_post_types = uwp_get_option( 'author_box_display_post_types' );
1053
1054 if ( ! empty( $post->post_type ) && in_array( $post->post_type, (array) $author_box_display_post_types ) ) {
1055
1056 $author_box_display_content = uwp_get_option( 'author_box_display_content' );
1057
1058 if ( ! empty( $author_box_display_content ) && 'above_content' === $author_box_display_content ) {
1059 $content = do_shortcode( '[uwp_author_box]' ) . $content;
1060 } else {
1061 $content = $content . do_shortcode( '[uwp_author_box]' );
1062 }
1063
1064 // run block content if its available
1065 if ( function_exists( 'do_blocks' ) ) {
1066 $content = do_blocks( $content );
1067 }
1068 }
1069
1070 }
1071
1072 }
1073
1074 return $content;
1075 }
1076
1077 /**
1078 * Adds form html for privacy fields in account page.
1079 *
1080 * @param string $type Form type.
1081 *
1082 * @return void
1083 * @since 1.0.0
1084 * @package userswp
1085 *
1086 */
1087 public function privacy_edit_form_display( $type ) {
1088 if ( $type == 'privacy' ) {
1089 $make_profile_private = uwp_can_make_profile_private();
1090 echo '<div class="uwp-account-form">';
1091 $extra_where = "AND is_public='2'";
1092 $fields = get_account_form_fields( $extra_where );
1093 $fields = apply_filters( 'uwp_account_privacy_fields', $fields );
1094 $user_id = get_current_user_id();
1095 $form_id = uwp_get_register_form_id( $user_id );
1096 $design_style = uwp_get_option( "design_style", "bootstrap" );
1097 $bs_form_group = $design_style ? "form-group mb-3 row" : "";
1098 $bs_form_control = $design_style ? "form-control" : "";
1099 $bs_btn_class = $design_style ? "btn btn-primary btn-block text-uppercase" : "";
1100 ?>
1101 <div class="uwp-profile-extra">
1102 <div class="uwp-profile-extra-div form-table">
1103 <form class="uwp-account-form uwp_form" method="post">
1104 <?php if ( $fields ) { ?>
1105 <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1106 <div class="uwp-profile-extra-key col" style="font-weight: bold;">
1107 <?php esc_attr_e( "Field", "userswp" ) ?>
1108 </div>
1109 <div class="uwp-profile-extra-value col" style="font-weight: bold;">
1110 <?php esc_attr_e( "Is Public?", "userswp" ) ?>
1111 </div>
1112 </div>
1113 <?php foreach ( $fields as $field ) { ?>
1114 <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1115 <div class="uwp-profile-extra-key col"><?php echo esc_attr( $field->site_title ); ?>
1116 <span class="uwp-profile-extra-sep">:</span></div>
1117 <div class="uwp-profile-extra-value col">
1118 <?php
1119 $field_name = $field->htmlvar_name . '_privacy';
1120 $value = uwp_get_usermeta( $user_id, $field_name, false );
1121 if ( $value === false ) {
1122 $value = 'yes';
1123 }
1124 ?>
1125 <select name="<?php echo esc_attr( $field_name ); ?>"
1126 class="uwp_privacy_field aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
1127 style="margin: 0;">
1128 <option value="no" <?php selected( $value, "no" ); ?>><?php esc_attr_e( "No", "userswp" ) ?></option>
1129 <option value="yes" <?php selected( $value, "yes" ); ?>><?php esc_attr_e( "Yes", "userswp" ) ?></option>
1130 </select>
1131 </div>
1132 </div>
1133 <?php }
1134 }
1135
1136 global $wpdb;
1137 $tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs';
1138 $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) ) );
1139
1140 if ( $tabs ) { ?>
1141 <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1142 <div class="uwp-profile-extra-key col" style="font-weight: bold;">
1143 <?php esc_attr_e( "Tab Name", "userswp" ) ?>
1144 </div>
1145 <div class="uwp-profile-extra-value col" style="font-weight: bold;">
1146 <?php esc_attr_e( "Privacy", "userswp" ) ?>
1147 </div>
1148 </div>
1149 <?php }
1150
1151 foreach ( $tabs as $tab ) { ?>
1152 <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1153 <div class="uwp-profile-extra-key col"><?php esc_attr_e( $tab->tab_name, 'userswp' ); ?>
1154 <span class="uwp-profile-extra-sep">:</span></div>
1155 <div class="uwp-profile-extra-value col">
1156 <?php
1157 $field_name = $tab->tab_key . '_tab_privacy';
1158 $value = uwp_get_usermeta( $user_id, $field_name, '' );
1159
1160 $privacy_options = array(
1161 0 => __( "Anyone", "userswp" ),
1162 1 => __( "Logged in", "userswp" ),
1163 2 => __( "Author only", "userswp" ),
1164 );
1165
1166 // Admin default
1167 $admin_privacy = isset( $tab->tab_privacy ) ? absint( $tab->tab_privacy ) : 0;
1168 $privacy_options = apply_filters( 'uwp_tab_privacy_options', $privacy_options, $tab );
1169
1170 if ( empty( $value ) ) {
1171 $value = $admin_privacy;
1172 }
1173 ?>
1174 <select name="<?php echo esc_attr( $field_name ); ?>"
1175 class="uwp_tab_privacy_field aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
1176 style="margin: 0;">
1177 <?php
1178 foreach ( $privacy_options as $key => $val ) {
1179
1180 $default = '';
1181 if ( $admin_privacy == $key ) {
1182 $default = __( ' (Default)', 'userswp' );
1183 }
1184 echo '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key, false ) . '>' . esc_attr( $val . $default ) . '</option>';
1185 }
1186 ?>
1187 </select>
1188 </div>
1189 </div>
1190 <?php }
1191
1192 $value = get_user_meta( $user_id, 'uwp_hide_from_listing', true ); ?>
1193 <div class="uwp-profile-extra-wrap">
1194 <div id="uwp_hide_from_listing" class="uwp_hide_from_listing">
1195 <input name="uwp_hide_from_listing" class="" <?php checked( $value, "1", true ); ?>
1196 type="checkbox"
1197 value="1"><?php esc_attr_e( 'Hide profile from the users listing page.', 'userswp' ); ?>
1198 </div>
1199 </div>
1200 <?php
1201 do_action( 'uwp_after_privacy_form_fields', $fields );
1202 if ( $make_profile_private ) {
1203 $field_name = 'uwp_make_profile_private';
1204 $value = get_user_meta( $user_id, $field_name, true );
1205 if ( $value === false ) {
1206 $value = '0';
1207 }
1208 ?>
1209 <div id="uwp_make_profile_private" class=" uwp_make_profile_private_row">
1210 <input type="hidden" name="uwp_make_profile_private" value="0">
1211 <input name="uwp_make_profile_private" class="" <?php checked( $value, "1", true ); ?>
1212 type="checkbox" value="1">
1213 <?php esc_attr_e( 'Make the whole profile private', 'userswp' ); ?>
1214 </div>
1215 <?php
1216 }
1217 ?>
1218 <input type="hidden" name="uwp_privacy_nonce"
1219 value="<?php echo esc_attr( wp_create_nonce( 'uwp-privacy-nonce' ) ); ?>"/>
1220 <input name="uwp_privacy_submit" class="<?php echo esc_attr( $bs_btn_class ); ?>"
1221 value="<?php esc_attr_e( 'Submit', 'userswp' ); ?>" type="submit">
1222 </form>
1223 </div>
1224 </div>
1225 <?php
1226 echo '</div>';
1227 }
1228 }
1229
1230 /**
1231 * Redirects the user to login page when email not confirmed.
1232 *
1233 * @param string $username Username.
1234 * @param object $user User object.
1235 *
1236 * @return void
1237 * @package userswp
1238 *
1239 * @since 1.0.0
1240 */
1241 public function unconfirmed_login_redirect( $username, $user ) {
1242 if ( ! is_wp_error( $user ) ) {
1243 $mod_value = get_user_meta( $user->ID, 'uwp_mod', true );
1244 if ( $mod_value == 'email_unconfirmed' ) {
1245 if ( ! in_array( 'administrator', $user->roles ) ) {
1246 $login_page = uwp_get_page_id( 'login_page', false );
1247 if ( $login_page ) {
1248 $redirect_to = add_query_arg( array(
1249 'uwp_err' => 'act_pending',
1250 'user_id' => $user->ID
1251 ), get_permalink( $login_page ) );
1252 wp_destroy_current_session();
1253 wp_clear_auth_cookie();
1254 if ( wp_doing_ajax() ) {
1255 global $userswp;
1256 $message = $userswp->notices->form_notice_by_key( 'act_pending', false, $user->ID );
1257 wp_send_json_error( $message );
1258 } else {
1259 wp_redirect( $redirect_to );
1260 }
1261 exit();
1262 }
1263 }
1264 }
1265 }
1266 }
1267
1268 /**
1269 * Oxygen override theme template.
1270 *
1271 * @since 1.2.2.15
1272 *
1273 * @param string $located Located template.
1274 * @param string $template_name Template name.
1275 * @param array $located Template args.
1276 * @param string $template_path Template path.
1277 * @param string $default_path Template default path.
1278 * @return string Located template.
1279 */
1280 public function oxygen_override_template( $located, $template_name, $args, $template_path, $default_path ) {
1281 if ( $_located = $this->oxygen_locate_template( $template_name ) ) {
1282 $located = $_located;
1283 }
1284
1285 return $located;
1286 }
1287
1288 /**
1289 * Oxygen locate theme template.
1290 *
1291 * @since 1.2.2.15
1292 *
1293 * @param string $template The template.
1294 * @return string The theme template.
1295 */
1296 public function oxygen_locate_template( $template ) {
1297 $located = '';
1298
1299 if ( ! $template ) {
1300 return $located;
1301 }
1302
1303 $has_filter = has_filter( 'template', 'ct_oxygen_template_name' );
1304
1305 // Remove template filter
1306 if ( $has_filter ) {
1307 remove_filter( 'template', 'ct_oxygen_template_name' );
1308 }
1309
1310 $_located = $this->get_theme_template_path() . '/' . $template;
1311
1312 if ( file_exists( $_located ) ) {
1313 $located = $_located;
1314 }
1315
1316 // Add template filter
1317 if ( $has_filter ) {
1318 add_filter( 'template', 'ct_oxygen_template_name' );
1319 }
1320
1321 return $located;
1322 }
1323
1324 /**
1325 * Get the UsersWP templates theme path.
1326 *
1327 * @since 1.2.2.15
1328 *
1329 * @return string Template path.
1330 */
1331 public static function get_theme_template_path() {
1332 $template = get_template();
1333 $theme_root = get_theme_root( $template );
1334
1335 $theme_template_path = $theme_root . '/' . $template . '/' . untrailingslashit( uwp_get_theme_template_dir_name() );
1336
1337 return $theme_template_path;
1338 }
1339
1340 /**
1341 * Check & unset the_content hook.
1342 *
1343 * @since 1.2.13
1344 *
1345 * @param string $content The content.
1346 * @return string The post content.
1347 */
1348 public function set_the_content_hook( $content ) {
1349 global $wp_query, $post, $uwp_set_wpautop;
1350
1351 // Prevent empty p tags on block theme.
1352 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() ) {
1353 if ( $has_filter = has_filter( 'the_content', 'wpautop' ) ) {
1354 $uwp_set_wpautop = $has_filter;
1355
1356 remove_filter( 'the_content', 'wpautop' );
1357 }
1358 }
1359
1360 return $content;
1361 }
1362 }