BuddyDev

Search

[Resolved] Green dot to the corner of a users avatar if they are currently online

Tagged: 

  • Participant
    Level: Initiated
    Posts: 13
    Hans Simtanda Caspersen on #45964

    I was thinking it would be quite cool to add a little green dot to the corner of a users avatar if they are currently online, would that be possible?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2986
    Ravi on #45975

    Hello Hans,

    Thank you for posting. Please try the following code:

    
    add_filter( 'bp_core_avatar_class', function ( $class, $item_id, $object ) {
    
    	if ( 'user' != $object ) {
    		return $class;
    	}
    
    	$last_activity_time = bp_get_user_last_activity( $item_id );
    
    	// Maybe add 'is-online' class.
    	if ( ! empty( $last_activity_time ) ) {
    
    		// Calculate some times.
    		$current_time  = bp_core_current_time( true, 'timestamp' );
    		$last_activity = strtotime( $last_activity_time );
    		$still_online  = strtotime( '+5 minutes', $last_activity );
    
    		// Has the user been active recently?
    		if ( $current_time <= $still_online ) {
    			$class .= ' is-online';
    		}
    	}
    
    	return $class;
    }, 10, 3 );
    
    

    It will add a class to the avatar ‘is-online’ with this class you can apply the CSS rule for online users.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 13
    Hans Simtanda Caspersen on #46008

    Thanks again for top notch support

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2986
    Ravi on #46010

    I am glad to help you.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #46018

    Hello Ravi the css class was added everywhere except for avatars in post comments

  • Keymaster
    (BuddyDev Team)
    Posts: 24262
    Brajesh Singh on #46022

    Hi Tosin,
    Are you referring to blog post comments?

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #46033

    Yes blog post comments

  • Keymaster
    (BuddyDev Team)
    Posts: 24262
    Brajesh Singh on #46046

    The comments are part of WordPress not BuddyPress and have a very different markup than that of BuddyPress. That’s why it is not available there.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #46052

    Ohh ok thanks Brajesh

The topic ‘ [Resolved] Green dot to the corner of a users avatar if they are currently online’ is closed to new replies.

This topic is: resolved