Will a plugin able to know is_user_logged_in?

I am currently building a plugin and it doesn't know when a user is logged in. global $current_user;echo $current_

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 badges
Add a comment  | 

2 Answers 2

Reset to default 1

The $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.

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

相关推荐

  • Will a plugin able to know is_user_logged_in?

    I am currently building a plugin and it doesn't know when a user is logged in. global $current_user;echo $current_

    11小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信