0

Is there any reason why wp_get_current_user() doesn't return the logged in user's info array when used within functions.php file in a child theme, nor does the is_user_logged_in() return the correct state for a logged in user? They both return 0 regardless if the user is logged in or not.

I am embedding the wordpress libraries into a 3rd party script and everything, literally everything else works outside of wordpress on a separate PHP page but this.

3
  • What's your WP version?
    – mukto90
    May 7, 2018 at 7:26
  • Latest one available.
    – Crazy Serb
    May 7, 2018 at 8:05
  • From which action/filter are you calling them?
    – kero
    May 7, 2018 at 9:09

1 Answer 1

1

It could be due to a hook firing sequence issue. When are you hooking your function?

The safest way to detect your current user is to fire on wp_login action. Someone reported the need to call it late.

The codex recommends to use wp_get_current_user() functon on or after the init hook.

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.