• I need to display the online status (online/offline) for each author page (custom author.php page template).

    is_user_logged_in() only applies to the current user and I can’t find a relevant approach targeting the current author e.g. is_author_logged_in().

    It’ possible?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Dion

    (@diondesigns)

    User online status in WordPress is not possible unless you find something that adds true session support. Also keep in mind that true session support requires dynamic pages, which means it is not compatible with cache plugins/applications.

    (What WordPress 4.0+ calls “sessions” are called autologin keys by most everyone else. They have very different purposes.)

    Moderator bcworkz

    (@bcworkz)

    One could track when authors who are logged in make server requests and if the request is within the last x few minutes, assume they are still “online”. Not a true online status, but a reasonable approximation perhaps.

    Thread Starter calle81

    (@calle81)

    @bcworkz do you have any code to advise me? Thanks.

    Moderator bcworkz

    (@bcworkz)

    Sorry, no. I think I would create a custom table with all author user IDs, in which a timestamp of every author access is logged. This scheme will not scale well, like if you had hundreds of authors. Hook the “init” action to check if the current user is an author and if so log the time.

    Where you wish to show if an author is online, get their latest timestamp and if it’s not too long ago, assume they are still online. Be aware that logging access times and indicating one’s status to others could have privacy implications if not handled properly.

    There will also need to be supporting code for various user management actions like adding users or changing roles to keep the custom table synchronized with current user states.

    Thread Starter calle81

    (@calle81)

    Thanks @bcworkz. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to check if a user (not current user) is online or offline?’ is closed to new replies.