BuddyDev

Search

Change Who's Online to Friend only

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #3528

    Hi,
    Sorry to bother you again.

    By default, the BuddyPress Who’s Online Widget will show all online users. I just wonder that is there any way to change it into Friends Only? I mean Who’s Online Widget will only show their friends who are currently online.

    Thank you very much.

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #3529

    Hi Dandy,
    Please put this code in your bp-custom.php.

    
    function buddydev_show_online_friends_only( $args ) {
    	
    	if ( ! is_user_logged_in() || empty( $args['type'] ) || $args['type'] !='online' ) {
    		return $args;
    	}
    	
    	$friend_ids = friends_get_friend_user_ids( bp_loggedin_user_id() );
    	
    	if ( empty( $friend_ids ) ) {
    		$friend_ids = array( 0, 0 );//invalid
    	}
    	
    	$args['include'] = $friend_ids;
    	
    	return $args;
    }
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_show_online_friends_only' );
    

    It will list only friends and if a user has no friends, they won’t see any online user.

    Hope that helps.
    regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #3555
    This reply has been marked as private.
  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #3559

    Hi, Brajesh
    I’m sorry that I already solved the issue by myself.

    Actually, I just paste here hopefully for anyone else who need the same request.

    The error message is located at:
    /wp-content/plugins/buddypress/bp-members/classes/class-bp-core-whos-online-widget.php
    Line 95

    Thanks again and hope BuddyDev getting better and better!

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #3577

    Hi Dandy,
    Thank you for the update and kind words.
    Please do note that the above fix will be overridden in next version of BuddyPress. A better idea will be to filter the text using “gettext” filter.

    if you want me to post the code, please do let me know.

    Thank you
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #3581

    Hi, Brajesh
    Thanks for your reply.

    Yes, your solution is better than mine. So, could you post the code here, please?

    Thank you very much.

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #3586

    Hi Dandy,
    No problem.
    Please put this in your bp-custom.php

    
    
    function buddydev_change_no_online_text( $translated_text, $text, $domain ) {
    
    	if ( $text == 'There are no users currently online' ) {
    		$translated_text = 'Sorry, you don’t have any friends online';
    	}
    	return $translated_text;
    
    }
    add_filter( 'gettext', 'buddydev_change_no_online_text', 20, 3 );
    
    

    That should do it.

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #3616

    Hi, Brajesh
    Thanks for your reply.

    I tried that but it seems doesn’t work. Is it something wrong with priority issue?

    Thanks.

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #3631

    Hi Dandy,
    Most probably you changed the text in the original widget earlier. This line

    There are no users currently online
    

    should match the exact line which is there in the widgets file.

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #3650
    This reply has been marked as private.

The topic ‘Change Who's Online to Friend only’ is closed to new replies.

This topic is: not resolved