Skip to content

Instantly share code, notes, and snippets.

@stillatmylinux
Created September 26, 2017 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stillatmylinux/973b08e28b06e2cbf01a66a64b51f190 to your computer and use it in GitHub Desktop.
Save stillatmylinux/973b08e28b06e2cbf01a66a64b51f190 to your computer and use it in GitHub Desktop.
<?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;
}
@myrafletcher
Copy link

where does this code go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment