Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display green border around avatar when user is online

  • @kakilo

    Participant

    Hi guys,

    I was lookin for a green border on member’s search page that is shown when the user is online. If the user is offline, instead, show a red one.

    Could anybody please help me with this? I was trying to use this code:

    <div id="online">
    <?php
    global $bp;
    function check_is_user_online($user_id){
    if ( bp_has_members( 'type=online&include='.$user_id) ) return true;
    else return false;
    }
    $this_id = bp_displayed_user_id();
    $is_online = check_is_user_online($this_id);
    if ($is_online) echo "<img src='http://www.yourweb.com/wp-content/themes/yourtheme/_inc/images/online.png' />";
    
    else{ echo "<img src='http://www.yourweb.com/wp-content/themes/yourtheme/_inc/images/offline.png' />";}

    But seems I can’t get it to work or it doesn’t works at all.

    Thanks in advance,
    Very appreciate.

    Henry.

Viewing 11 replies - 1 through 11 (of 11 total)
  • @modemlooper

    Moderator

    @macpresss

    Participant

    Nope I’ve been searching for this also – none of the code snippets online work. There are 3 different code snippets and none are working at the moment for some reason.

    It would be cool if we just had a simple user check within the members loop.

    Example:
    Check if user_is_online() return a Boolean? or –> Echo “something” if user is not online Echo “nothing or something else”;

    I would like to add a simple word like online or offline to a HTML class and target it by CSS while making a small ‘breathing’ animation of the gender symbol to show if a user is online or not.
    user_online

    @henrywright-1

    Member

    @macpresss I wouldn’t use that code from web developers wall in the members loop as it will add a database query for each member. It is more intended for use on the profile page. For the members loop, there are better ways to do it performance wise.

    @naijaping

    Participant

    @kakilo, I posted 3 different version of that code in the forum and it is still working. It is for member-header and not members-loop but there is nothing stopping you from making it work with
    members-loop just pay attention to the code.

    I still have that coding working in my member .

    Naijaping

    @shanebp

    Moderator

    To show in the members loop, create a template override in your theme for members-loop.php

    At the top of your override, paste this:

    $current_time = current_time( 'mysql', 1 );
    
    function online_check( $current_time ) { 
      global $members_template;
    	
      if ( isset( $members_template->member->last_activity ) ) {
    
        $diff =  strtotime( $current_time ) - strtotime( $members_template->member->last_activity ); 
    
        if ( $diff < 300 ) // 5 minutes  =  5 * 60
    	echo " online";
        else
    	echo " offline ";
    			
        }
    }

    Call it wherever you like in the members loop like so:
    online_check( $current_time );

    @kakilo

    Participant

    Man, this worked like a charm!

    Thank you so much :}

    @kakilo

    Participant

    I’m also using Prince Abiola script to show if the user is on/off on the members header. Everything is working great now!

    Thank you guys!
    Henry.

    @macpresss

    Participant

    @shanebp

    Thanks that works beautiful just like I wanted.

    ? Just one question, why does it only work if you place the huge function code snippet in the loop template ( at the top ) but when you paste it inside your functions.php it doesn’t work.

    @shanebp

    Moderator

    @macpresss

    You should be able to put the function in functions.php

    But you still need to put this
    $current_time = current_time( 'mysql', 1 );
    at the top of the template and _not in functions.php

    @macpresss

    Participant

    Thank you so much!

    This looks very good and like real clean code. 🙂

    @macpresss

    Participant

    buddypress user online check

    It’s still work in progress and needs a lot of tuning to be not annoying for users but you get the picture.
    It’s something different then a Green or Red bullet that say’s online.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Display green border around avatar when user is online’ is closed to new replies.
Skip to toolbar