Created
September 26, 2017 17:20
-
-
Save stillatmylinux/973b08e28b06e2cbf01a66a64b51f190 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function frontend_login_script( $user, $user_id ) { | |
if( $user ) { | |
$login_message = apply_filters( 'appp_login_success', sprintf( __('Welcome back %s!', 'apppresser'), $user->display_name), $user->ID ); | |
$username = $user->user_login; | |
$avatar_url = get_avatar_url( $user->ID ); | |
$login_redirect = appp_get_login_redirect(); | |
?> | |
<script type="text/javascript"> | |
var login_data = { | |
message: '<?php echo $login_message; ?>', // welcome message | |
username: '<?php echo $username; ?>', // name used in greeting | |
avatar: '<?php echo $avatar_url; ?>', // URL to the avatar | |
login_redirect: '<?php echo $login_redirect; ?>' // optional login redirect | |
} | |
window.apppresser.sendLoginMsg( true, login_data ); | |
</script><?php | |
} | |
} | |
function appp_get_login_redirect() { | |
if( has_filter( 'appp_login_redirect' ) ) { | |
$redirect_to = apply_filters( 'appp_login_redirect', '' ); | |
$post_id = url_to_postid( $redirect_to ); | |
$redirect = array( | |
'url' => $redirect_to, | |
'title' => ($post_id) ? get_the_title( $post_id ) : '', | |
); | |
} else { | |
$redirect = ''; | |
} | |
return $redirect; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where does this code go?