Answer the question
In order to leave comments, you need to log in
How to display user's online status in wordpress?
Good day.
The task is to display the online status (Online and Offline) of the user's avatar.
Added themes to Functions.php
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 ) ) );
}
<?php
global $post;
if( is_user_online( $post->post_author ) ) : ?>
<p>User is online</p>
<?php else : ?>
<p>User is offline</p>
<?php endif; ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question