Adding a Friends Online widget to your BuddyPress community
The goal of this trick is to display the friends of a displayed user once in his member area. Just like on BuddyPress.org or wpmu.org. I only added an ajax call to display those who are online.. I haven’t checked wpmu.org’s plugin, but this widget mimics the functionality on buddypress.org, and it does not displays the friends of the logged in user but the friends of the user currently being viewed.
Step 1: Edit Sidebar.php
Add the template sidebar.php to your Child Theme and open it. just before calling the dynamic sidebar (around line 68) add this code :
Step 2: Edit Functions.php
In the functions.php file of the Child theme add the following functions :
function imath_bp_display_friends(){ global $bp; $user_id = $bp->displayed_user->id; $user_all_friends_url = $bp->displayed_user->domain . BP_FRIENDS_SLUG; ?> No friends online!'; else echo 'displayed_user->id; if(isset($_POST['offoronline'])) $type = $_POST['offoronline']; else $type = 'offline'; if($type=='offline') $args = 'user_id='.$user_id.'&per_page=10&max=10&populate_extras=0'; else $args = 'user_id='.$user_id.'&type=online&per_page=10&max=10&populate_extras=0'; if ( bp_has_members( $args ) ){ ?>No friends!
'; } die(); } function imath_bp_display_friends_js(){ if ( bp_is_member() ){ ?>Voilà! Sorry for my english
Hey, cool!
I created a widget for BP 1.1 that did absolutely the same but in a different way (at that time there were not so many handy bp_ functions).
hi Slava UA,
thks 4 your comment.
How to add a “Follow this member!” button on the activity stream, like in this site ?
note: I didn’t get an appropriate place to request for this , so posted here, kindly forgive any mistake …
you should directly ask @bowe
Merci imath
de rien
just 4 info, thanks to the wpmu.org suggestion, it’s now a plugin called BP Show Friends
Great! Well done
Hey, I can’t get this to work, and the plugin does not do what you say this tutorial does, it shows all your friends, I only want to show the ones online but there are no widgets for that and this did not work, is there a specific place I put the code in the functions.php file?
Hi Lewis,
I advise you to use the widget BP Show Friends. Once installed, go to WordPress backend, then drag and drop the widget in your sidebar.
Once on your member’s page (siteurl/members/yourname) it will show your friends. Under the title of the widget, there are 2 links calling ajax functions, the second link will display the friends that are online or a message ‘No friends online’..
So the plugin actually do what this tutorial does !!
Cool plugin, Imath. Thank you for taking the time to develop this.
One question. If I wanted to change the title of the widget to say “current members” friends, where “current member” is the name of the users who’s page you are on, how would I do that? I see the h3 title, but I am not sure how to echo the members name.
Thanks very much
Hi!
Very interesting name by the forum bp-tricks.com
It is the truth.