3

Here is what I'm doing:

wp_logout();
var_dump(is_user_logged_in());

var_dump returns:

bool(true)

Why is wp_logout() not logging me out?

5

wp_logout() calls clear_auth_cookie(), which expires all authorization cookies set. It doesn't change the value of the global $current_user variable. So technically you're still logged in for the duration of the script.

If you're using wp_logout in your own code, its probably best to exit or wp_redirect immediately afterwards.

You can call wp_set_current_user(0) after wp_logout() to manually log the user out instantly, if you need to continue executing PHP but don't want the user to be logged in

  • None of this seems to work. After wp_logout() I have tried unset($current_user) and wp_redirect(get_bloginfo("url")); – Jarred Mar 26 '11 at 19:38
  • 2
    You can call wp_set_current_user(0); after wp_logout() to manually log the user out instantly, if you need to continue executing PHP but don't want the user to be logged in... – goldenapples Mar 27 '11 at 16:27
  • Couldn't get wp_redirect() to work so instead I'm using: wp_logout(); auth_redirect(); which worked perfectly for me – Daithí Jul 30 '12 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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