Check if the user is online from code

Developer Knowledge Level

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_id is 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.

Rate this article
0
0
2398

You are not allowed to rate this post.

Leave a Comment

0
0
0
0
0
0
0
0
0