logout - wp_logout Not Logging Me Out

Here is what I'm doing:wp_logout();var_dump(is_user_logged_in());var_dump returns: bool(true)Why is wp_logout() no

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?

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?

Share Improve this question edited Dec 18, 2012 at 14:37 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Mar 25, 2011 at 21:01 JarredJarred 4983 gold badges7 silver badges13 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 6

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

I had same problem with my code. I was trying to logout by using wp_logout() but It wasn't working perfectly as per my need because of some code changes so I used wp_destroy_current_session(); and then wp_redirect(); and exit();

    wp_destroy_current_session();
    wp_logout();
    wp_redirect(site_url()); 
    exit();

And it woked for me. you can also use auth_redirect(); instead of wp_redirect(site_url()); and also in my case wp_set_current_user(0); was also not working if used before redirect as it was setting user 0 active

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745346030a4623547.html

相关推荐

  • logout - wp_logout Not Logging Me Out

    Here is what I'm doing:wp_logout();var_dump(is_user_logged_in());var_dump returns: bool(true)Why is wp_logout() no

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信