Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

login_redirect not working correctly

$
0
0

Replies: 0

On a restricted page, I just added this script:

<?php
	if (!is_user_logged_in()) {
       		auth_redirect();
		exit;
    }
?>

1) When I go to the above page and it redirects to /wp-login.php

Then in the login_redirect filter/hook, it knows that no one has logged in, no user ID. (This is correct)

2) I enter correct user and pass, then click login.

HOWEVER, in the login_redirect filter/hook,
It thinks that no one has logged in, no user ID ????

(This is incorrect, as the user just logged in)

3) IF I refresh/reload the wp-login.php page…

Only then does login_redirect KNOW the user ID and the user is logged in,
All good.

———
SO WHY doesn’t login_redirect know the user the right after logging in?


add_filter( 'login_redirect', ‘THE_login_redirect', 10, 3 );
function THE_login_redirect( $redirect_to, $request, $user ) {

    $loggedin = is_user_logged_in();

    debug_to_console("in THE_login_redirect and are you logged in:".$loggedin);
    debug_to_console("redirect_to =".$redirect_to);
    debug_to_console("request =".$request);
    if ($loggedin) {
        debug_to_console("user id =".$user->ID);
    }

    
    debug_to_console("last LINE");
}

Viewing all articles
Browse latest Browse all 59525

Trending Articles