<div id="new-users">
<?php
$list     = bp_get_friend_ids( $bp->loggedin_user->id );
$newUsers = "select * from wp_users where user_status = 0 and ID not in ({$list}) order by user_registered DESC limit 4";
$users    = $wpdb->get_results($wpdb->prepare($newUsers));

date_default_timezone_set('Europe/Madrid');

foreach ($users as $item) {
    
    echo '<div class="user-' . $item->ID . '">';
    echo '<a href="'. bp_core_get_user_domain( $item->ID ) .'" title="'. bp_core_get_user_displayname( $item->ID ) .'" class="avatar">' . get_avatar( $item->ID, '40' ) . '</span></a>';
    
    $online_time = get_user_meta($item->ID, 'last_activity');
    $online_time2 = strtotime($online_time[0]) + 300;
    
    if (time() <= $online_time2)
        echo '<img class="check-online" src="'. get_stylesheet_directory_uri() . '/_inc/images/user_online.png" />';
    
    echo '</div>';
    
}
?>
</div>