Check if user with ID or name X is online
Is there any wa开发者_开发知识库y to check if a user with a certain id or name is online in Wordpress?
I think the function you want is is_user_logged_in
. Maybe try
wp_set_current_user($id, $name = '')
To set the current user by id, and then check if they are logged in using
is_user_logged_in()
http://codex.wordpress.org/Function_Reference/wp_set_current_user
http://codex.wordpress.org/Function_Reference/is_user_logged_in
jkeesh has a good solution, but that may not offer live information. is_user_logged_in()
is a conditional statement for performing actions.
It's helpful if you want to do this for example:
When logged in, show smiley.jpg
When logged out, don't show smiley.jpg
If you are simply trying to do one of those features which forums have that show "x number of users online" and list their usernames, I don't believe this conditional statement can do that. That would either require some custom code or another plugin.
精彩评论