Tagged: code, friends, online users, tutorial
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.
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
BrajeshHi, 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 95Thanks again and hope BuddyDev getting better and better!
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
BrajeshHi, Brajesh
Thanks for your reply.Yes, your solution is better than mine. So, could you post the code here, please?
Thank you very much.
Hi Dandy,
No problem.
Please put this in your bp-custom.phpfunction 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.
Hi, Brajesh
Thanks for your reply.I tried that but it seems doesn’t work. Is it something wrong with priority issue?
Thanks.
Hi Dandy,
Most probably you changed the text in the original widget earlier. This lineThere are no users currently online
should match the exact line which is there in the widgets file.
The topic ‘Change Who's Online to Friend only’ is closed to new replies.