Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: User Online Icon


r-a-y
Keymaster

@r-a-y

Okay, here’s my crack at finding out if a displayed user ID is online:

function is_displayed_user_online() {
global $bp;

$user = new BP_Core_User();
$fetchOnlineUsers = array_values($user->get_online_users());

// grab online user IDs
$onlineIDs = $fetchOnlineUsers[0];

// loop through each online user ID; if online user ID matches displayed user ID, then displayed user is online, hence return true
foreach($onlineIDs as $online) {
if($bp->displayed_user->id == $online->user_id) {
return true;
}
}
}

//let's test out the function
//put this in a profile template
if(is_displayed_user_online())
echo 'user is online';
else
echo 'user is offline';

Skip to toolbar