Skip to:
Content
Pages
Categories
Search
Top
Bottom

function total_friend_online_count()

  • @ryuns

    Participant

    Not a plug-in or widget yet, but thought I might get some feedback, I couldn’t find any other core function, maybe I’m just crazy or blind, anyhow I threw this together so fit my needs, thought maybe someone else might benefit from also…

    function total_friend_online_count( $user_id = false ) {
    global $wpdb, $bp;
    if ( !$user_id )
    $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;

    $sql = “SELECT DISTINCT COUNT(u.ID) FROM ” . CUSTOM_USER_TABLE . ” u LEFT JOIN ” . CUSTOM_USER_META_TABLE . ” um ON um.user_id = u.ID WHERE ” . bp_core_get_status_sql( ‘u.’ ).” AND um.meta_key = ‘last_activity’ AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()”;
    $friend_ids = friends_get_friend_user_ids( $user_id );
    $friend_ids = $wpdb->escape( implode( ‘,’, (array )$friend_ids ) );
    if ( !empty( $friend_ids ) )
    $sql .= ” AND u.ID IN ({$friend_ids})”;
    $sql .= “ORDER BY um.meta_value DESC”;
    $total_users = $wpdb->get_var( $sql );
    return $total_users;
    }

  • The topic ‘function total_friend_online_count()’ is closed to new replies.
Skip to toolbar