[wp-trac] [WordPress Trac] #28116: is_user_logged_in() does not work properly after using wp_signon()

WordPress Trac noreply at wordpress.org
Sun Dec 13 18:20:37 UTC 2015


#28116: is_user_logged_in() does not work properly after using wp_signon()
--------------------------+----------------------
 Reporter:  guusifs       |       Owner:
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Users         |     Version:  3.9
 Severity:  normal        |  Resolution:  invalid
 Keywords:                |     Focuses:
--------------------------+----------------------

Comment (by SergeyBiryukov):

 Replying to [comment:1 Denis-de-Bernardy]:
 > Seems invalid though: is_user_logged_in() returns false until the init
 hook, so if you run your code when the plugin is loaded then it will not
 work indeed.

 I don't think that was the issue here, I think the report was about
 `wp_signon()` not setting the current user.

 Replying to [comment:2 guusifs]:
 > Why is that? It took me a long time to figure out what was wrong.

 `wp_signon()` is only meant to check the credentials and set the
 authentication cookies. If you need to check `is_user_logged_in()` right
 away, `wp_set_current_user()` should be called explicitly.

 Perhaps we need better docs, but as far as I can tell, there is no bug
 here.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28116#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list