Check if the user is online from code
This content is intended for WordPress developers, and it may require coding knowledge of WordPress, PHP, and JavaScript. Code examples provided here may contain errors or needs some additional coding. Make sure to test the code before using it on a live website!
You can check if the user is tracked as online from anywhere in your code. This tutorial shows example PHP code that you can use in your own plugin or theme.
Here is the basic code that you can use:
<?php $online = Dev4PressPluginGDBBXBasicUser::instance( $user_id )->is_online(); ?>
This code will work even if the plugin’s Online Tracking is not active or loaded, so your code will not break if that happens.
You should know that if
$user_idis 0 (user is not logged in), the function will always return TRUE. To make sure this works correctly, you should use this code only if the $user_id is not 0.