1

I know that Wordpress is stateless and doesn't use any global session variables, but when a user logs in via Wordpress, it must somehow keep track of who is logged in, right? Does Wordpress keep track of that in cookies?

I'm working on a plugin that must keep track of something similar. I can easily store some data in transients, but is there a unique identifier available that can identify a user, whether he or she is logged in to Wordpress or not? I would then use that to access the transient, for example.

1 Answer 1

4

Yes, WordPress uses cookie to keep track of who is logged in in cookies. But you don't have to rely on it. If you want to check if user is logged in, you can just use is_user_logged_in function and you can identify a user by his/her ID which you can get by calling get_current_user_id function.

2
  • Right, but this also has to work if a user is not logged in to Wordpress. Is there a unique user identifier for just visitors that I can retrieve?
    – NightHawk
    Commented Jun 1, 2012 at 14:55
  • @NightHawk Use your own cookie for it. Commented Jun 1, 2012 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.