is_logged_in not working after login

admin2025-06-07  50

I am using is_user_logged_in() after a user has logged in to woocommerce (the page is a replacement for the user's woocommerce dash). This returns false, though if I reload the page it returns true.

I am using is_user_logged_in() after a user has logged in to woocommerce (the page is a replacement for the user's woocommerce dash). This returns false, though if I reload the page it returns true.

Share Improve this question asked Sep 1, 2018 at 10:03 frank astinfrank astin 1331 silver badge12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I faced a similiar problem that user seemed to be logged out after getting redirected after login. After refreshing the page or navigating to another page user would be logged in.

A comment I saw here, Logging in redirects to correct page but shows logged out content until forced refresh, helped me to solve the problem.

I used add_query_arg to add a dummy parameter to bust browser cache, which I think was the root problem. I placed the following code inside my redirection function's conditions check,

$redirect = add_query_arg( 'redirect', time(), home_url() );
wp_redirect( $redirect );
exit();

Of course the key and the value can be anything.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749256232a317659.html

最新回复(0)