It looks like you’re close on this one.
Move this function:
function is_user_online( $user_id ) {
// get the online users list
$logged_in_users = get_transient( 'users_online' );
// online, if (s)he is in the list and last activity was less than 15 minutes ago
return isset( $logged_in_users[$user_id] ) && ( $logged_in_users[$user_id] > ( current_time( 'timestamp' ) - ( 15 * 60 ) ) );
}
to your functions.php file and remove it from any other files. Then in the loop, here’s the code you’ll want to use:
<?php
global $post;
if( is_user_online( $post->post_author ) ) : ?>
<p>User is online</p>
<?php else : ?>
<p>User is offline</p>
<?php endif; ?>
Related Posts:
- stop login if user_status equal zero
- hide woo commerce dashboard status and reports from woo commerce from specific users but display to other users
- If the current user is an administrator or editor
- How do I add a field on the Users profile? For example, country, age etc
- How to check if a user (not current user) is logged in?
- user_login vs. user_nicename
- WordPress usermeta scaling for thousands of users
- Groups of capabilities: users with multiple roles?
- Is there a way to merge two users?
- How to restrict access to uploaded files?
- Execute a function when admin changes the user role
- How to let user set password on registration
- How to get the Gravityform entry ID from current user’s form submission? [closed]
- Post list based on the user that is logged in
- Why does is_user_logged_in() return false after redirect from another site?
- How can I add a user through SQL?
- Copy a user from one WordPress site to another
- Count user posts by type and date
- Assigning tags to user?
- How to use tinyMCE for user “biographical info” without messing with any core file?
- Get user info outside WordPress
- How to change the order in which users are displayed in admin?
- Total number of authors with more than one post
- WordPress has a trash for users? (Wrong result for count_user, greater than expected)
- Is there a simple way to manage capabilities per user?
- Check for user meta data at Login
- Buddypress – Send New User Activation Link to Admin [closed]
- Redirect after users complete profile form
- Cannot set user passwords
- Memory usage for scalable usermeta queries
- How to get current user’s phone number
- Front End Registration Form Code – Password Field Not Saving
- How can I verify users facebook ID that he provides during signup process
- How do I customize the dashboard?
- WordPress User Meta & ChromePHP or other way to debug/view php variables
- How would I hook into `clear_auth_cookie` to return the user’s ID that’s currently being logged out?
- How to disable a specific page for a specific user
- New users not showing up in Post -> Edit
- How can i change the name order in the admin?
- Getting author page slug from get_users() or get_userdata() functions
- WP_User_Query by meta_value with Number returns nothing
- How to add user from front end
- Rewrite Rules and Login Issue
- I am getting mysql_real_escape_string() function error while adding user?
- User profile updates password even if not filled (Theme my login) in Firefox? [closed]
- Preventing auto-filling of e-mail addresses on profile.php
- users and usermeta table
- Getting the age of a users account
- Prevent subscribers to changing certain profile fields
- New user form rejected because “passwords don’t match”—but there’s only one password field
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Creating User Profiles using author.php
- “the_author_meta(‘url’)” not working inside “href”
- REST API: wp_get_current_user not working on second call
- How to let the users edit their user names?
- How do I filter users based on email address?
- What’s the correct way to add capabilites to user roles?
- Web app vs CMS backend
- User roles not displaying
- Allow admins to login as other users
- How to count total words for posts published by one author?
- Should I setup frontend-only users as CPT or use a plug-in?
- How to expire user registration?
- Delete a user from frontend
- Echo a list of all subscriber’s user IDs
- user login and its profile
- wp_delete_user – huge overhead in Buddypress?
- Get current logged-in user from external site
- Delete all users with Editor role and their content mysql
- Load Custom Field to User Profile as per User Role using Ajax
- Show posts who published after registration date
- How to hide “Change role to” dropdown on Users admin menu
- How to display a calendar with events depending on the user?
- How to show different pages for different users
- How can i display pagination in custom comment list?
- hide page menu from admin panel for specific users
- Single Sign On (SSO) between two WordPress websites
- Disabling user capability to edit_posts or delete_posts in the front-end
- Redirect /member/ to /member/user
- get user id in a plugin without a function
- $user_login is not working if author has only 1 post
- WP_User object behaving strangely when used inside Admin Panel?
- REST_query_vars for users
- How to use a transient inside WP_User_Query
- Allowing users to edit only their page and nobody else’s
- How to bulk change user role to “No role for this site”
- Add an ‘edit profile’ page with Genesis
- Exclude Current user email and send notification
- Insert query not working for non-logged in user
- Disallow user registration/checkout via Hotmail/Yahoo
- User management missing after migration to new host
- Add new user and user bio at same time
- Validate user meta and redirect
- Let admin users edit member profiles from front end
- What techniques can a user employ to achieve a password rated “strong” in the WordPress password checker
- New User Registration email
- How can I list users by date in an array in meta_value?
- Email Subscribe for Downloads in WordPress
- Cant edit profile from frontend
- Can I provide a user’s user_ID to them and can it also be searchable in a member’s directory