Skip to:
Content
Pages
Categories
Search
Top
Bottom

displayed user is logged in

  • Avatar of Intervik
    Intervik
    Participant

    @intervik

    Hi, searched for weeks for this, now start posting here… Propably simple solution.
    I need a true/ false statement if a user_id (not me) IS logged in. In worst case, IS online (active less than those % MINUTES)
    like bp_is_logged_in(id) or a default wp call or something.

    / thankful any directions here

Viewing 7 replies - 1 through 7 (of 7 total)
  • Avatar of Intervik
    Intervik
    Participant

    @intervik

    Note. type=online will not work when other types needed, and multiple loops avoiding c we have 18 000 members…

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    is_user_logged_in()

    Avatar of Intervik
    Intervik
    Participant

    @intervik

    Thanks, but it seems to apply me as logged in, not the profile im visit. “I need a true/ false statement if a user_id (not me)”

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    EDIT:

    `
    function bp_is_displayed_user_online(){
    $member_id = bp_displayed_user_id();
    if (bp_has_members(‘user_id=0&type=online’)) :
    while (bp_members()) : bp_the_member();
    if($member_id == bp_get_member_user_id()) return true;
    endwhile;
    endif;
    }

    function bp_is_online(){
    if ( bp_is_displayed_user_online() )
    echo ‘online!’;

    }
    add_action(‘bp_before_member_header_meta’, ‘bp_is_online’);
    `

    Avatar of nitestop
    nitestop
    Participant

    @nitestop

    isnt there a plugin for this already on here

    Avatar of Intervik
    Intervik
    Participant

    @intervik

    Thanks. As my note above, We have 18 000 members, and loop them for a simpe boolean seems heavy (if id == 17999…). Isnt there a smart php session solution, if the core doesnt provide a ONLINE ARRAY ?

    Avatar of chroniko
    chroniko
    Participant

    @chroniko

    better solution to check online users:

    `
    function bp_is_user_online($member_id=0){
    if(!$member_id)
    $member_id = bp_displayed_user_id();
    $now = time();
    $last_activity = bp_get_user_meta($member_id, ‘last_activity’, true);
    $last_activity = strtotime($last_activity);
    if( ($last_activity + 300) >= $now )
    return true;
    }
    `
    300 (in seconds) is default buddypress interval to check online users.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.