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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745594804a4635045.html
评论列表(0条)