admin管理员组文章数量:1433896
I am currently building a plugin and it doesn't know when a user is logged in.
global $current_user;
echo $current_user->ID;
It works when embedded on a template but not on a plugin? I have a custom database that depends on user_id, whenever I insert a record, user_id field always has a zero value while others have the correct one.
I am currently building a plugin and it doesn't know when a user is logged in.
global $current_user;
echo $current_user->ID;
It works when embedded on a template but not on a plugin? I have a custom database that depends on user_id, whenever I insert a record, user_id field always has a zero value while others have the correct one.
Share Improve this question asked Nov 29, 2010 at 15:14 JoannJoann 1,4853 gold badges18 silver badges22 bronze badges2 Answers
Reset to default 1The $current_user
global isn't setup until right before the 'init'
action is called. So any code using it shouldn't be fired until that action or later.
I would also suggest using the get_current_user_id()
method instead of getting the global directly.
Try using is_user_logged_in() to check whether the user is logged in. It will return true or false depending on whether the user is logged in.
本文标签: Will a plugin able to know isuserloggedin
版权声明:本文标题:Will a plugin able to know is_user_logged_in? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745594804a2665411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论