M
M
Minusator2018-02-21 15:56:41
WordPress
Minusator, 2018-02-21 15:56:41

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 ) ) );   
}

Conclusion
<?php
global $post;
if( is_user_online( $post->post_author ) ) : ?>
    <p>User is online</p>
<?php else : ?>
    <p>User is offline</p>
<?php endif; ?>

The site displays User is offline. At the entrance does not change to Online. What am I doing wrong? Tell.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question