| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
/* |
| 5 |
* Function that returns a front-end logout message from the wppb-logout shortcode |
| 6 |
* |
| 7 |
* @param $atts The shortcode attributes |
| 8 |
*/ |
| 9 |
function wppb_front_end_logout( $atts ) { |
| 10 |
|
| 11 |
if( !is_user_logged_in() ) |
| 12 |
return; |
| 13 |
|
| 14 |
$current_user = get_userdata( get_current_user_id() ); |
| 15 |
|
| 16 |
$wppb_generalSettings = get_option( 'wppb_general_settings' ); |
| 17 |
|
| 18 |
if( !empty( $wppb_generalSettings['loginWith'] ) && $wppb_generalSettings['loginWith'] == 'email' ) { |
| 19 |
$display_username_email = $current_user->user_email; |
| 20 |
} |
| 21 |
else { |
| 22 |
$display_username_email = $current_user->user_login; |
| 23 |
} |
| 24 |
|
| 25 |
$atts = shortcode_atts( array( |
| 26 |
'text' => sprintf(__('You are currently logged in as %s. ', 'profile-builder'), $display_username_email), |
| 27 |
'redirect' => '', |
| 28 |
'redirect_url' => wppb_curpageurl(), |
| 29 |
'redirect_priority' => 'normal', |
| 30 |
'link_text' => __('Log out »', 'profile-builder'), |
| 31 |
'url_only' => '', |
| 32 |
), $atts, 'wppb-logout' ); |
| 33 |
|
| 34 |
if( ! empty( $atts['redirect'] ) ) { |
| 35 |
$atts['redirect_url'] = $atts['redirect']; |
| 36 |
} |
| 37 |
|
| 38 |
// CHECK FOR REDIRECT |
| 39 |
$redirect_url = wppb_get_redirect_url( $atts['redirect_priority'], 'after_logout', esc_url_raw( $atts['redirect_url'] ), $current_user ); |
| 40 |
$redirect_url = apply_filters( 'wppb_after_logout_redirect_url', $redirect_url ); |
| 41 |
|
| 42 |
if( isset( $atts['url_only'] ) && $atts['url_only'] == 'yes' ) |
| 43 |
return wp_logout_url( $redirect_url ); |
| 44 |
|
| 45 |
$logout_link = '<a href="' . esc_url( wp_logout_url( $redirect_url ) ) . '" class="wppb-logout-url" title="' . esc_attr__( 'Log out of this account', 'profile-builder' ) . '">' . esc_html( $atts['link_text'] ) . '</a>'; |
| 46 |
|
| 47 |
$meta_tags = apply_filters( 'wppb_front_end_logout_meta_tags', array( '{{meta_user_name}}', '{{meta_first_name}}', '{{meta_last_name}}', '{{meta_display_name}}' ) ); |
| 48 |
$meta_tags_values = apply_filters( 'wppb_front_end_logout_meta_tags_values', array( $current_user->user_login, $current_user->first_name, $current_user->last_name, $current_user->display_name ) ); |
| 49 |
|
| 50 |
$text = apply_filters( 'wppb_front_end_logout_text', str_replace( $meta_tags, $meta_tags_values, $atts['text'] ), $current_user ); |
| 51 |
|
| 52 |
return apply_filters( 'wppb_logout_message', '<p class="wppb-front-end-logout"><span>' . esc_html( $text ) . '</span>' . $logout_link . '</p>' ); |
| 53 |
} |