最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

is_logged_in not working after login

matteradmin51PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far