If you want the login works without having to reload the page (or redirect to somewhere on the site), then you would want to immediately set both the auth and logged-in cookies, i.e. set them in the superglobal $_COOKIE
array. And you can do that via the set_auth_cookie
and set_logged_in_cookie
hooks:
add_action( 'set_auth_cookie', function ( $cookie ) {
$cookie_name = is_ssl() ? SECURE_AUTH_COOKIE : AUTH_COOKIE;
$_COOKIE[ $cookie_name ] = $cookie;
} );
add_action( 'set_logged_in_cookie', function ( $cookie ) {
$_COOKIE[ LOGGED_IN_COOKIE ] = $cookie;
} );