Is there a way to display a list of currently logged in users?
Ideally it would just show their name and gravatar.
Is there a way to display a list of currently logged in users?
Ideally it would just show their name and gravatar.
You must be logged in to post a comment.
Personaly I would use the session_tokens meta key to determine if a user is online (or has a running session) or not.
You’ll get a list of Users with running sessions. Then you can use that for your output.
You could even display the session ip addresses if you modify the last bit of code.
WordPress does not have a built in function for this, but you can easily add one yourself. For example, you can use the wp_login hook to store each users last login time. Then you can list the users that logged in within the last 30 minutes or so as online.
Then, you can echo out the users that logged in within the last twenty minutes ( or whatever timeframe you choose) with something like:
If you don’t want to use a plugin, this can be done easily :
1/ Add this to your functions.php file to add or remove a usermeta when the user connects or disconnects :
2/ In your templates (you could also make a function in functions.php), to show all users that are loggedin, just use the built in wordpress get_users() with some meta query params :
1)Create on extra field named as ‘status’ with enum(‘1′,’0’) in wp_users table
2)after in functions.php put following code
now to list the currently login user you can use
You can get current logged in user in following way
id this $current_user variable you can find all the user details in array and object you can take from this variable