Make your BuddyPress Sitewide Activity Stream Friends Only
By default, the site wide activity stream on a BuddyPress site contains all the updates/activities from the whole site. If your site is aimed at being more social type, you may want to make this page list friends only activity, to provide a more personalized feeling. It was asked on our Forum by Israel, and here I am presenting the code to you all.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | function buddydev_friends_only_activity_args( $args ) { if ( ! bp_is_activity_directory() || ! is_user_logged_in() || ! empty( $args['scope'] ) ) { return $args; } $user_id = get_current_user_id(); $user_ids = friends_get_friend_user_ids( $user_id ); // include user's own too? array_push( $user_ids, $user_id ); $args['user_id'] = $user_ids; return $args; } add_filter( 'bp_after_has_activities_parse_args', 'buddydev_friends_only_activity_args' ); |
Put this code in your bp-custom.php or your theme's functions.php and the sitewide activity stream will only list activities from current user and his/her friends.
How can I make BuddyPress Sitewide Activity Stream list followers only activity. What is the code that will support the buddypress follow plugin.
Hi Tosin,
instead of friends_get_friend_ids you can use bp_get_follower_ids as shown here
https://github.com/r-a-y/buddypress-followers/blob/master/_inc/bp-follow-functions.php#L281
Hope that helps.
Amazing, worked Best in my Case.
Thanks for brilliant work
You are welcome 🙂
Does this snippet support the users I'm following as well, or how would I modify it to also show the activities of the people I'm following?
Hi Nathan,
This snippet is for friends. It can be easily modified to use with the follow plugin.
You will need to use bp_get_following_ids instead of the friends_get_friend_user_ids
ash shown here
https://github.com/r-a-y/buddypress-followers/blob/master/_inc/bp-follow-functions.php#L314
If you want me to put the complete code, please do let me know. I will post that.
Thank you
Brajesh
Hi, the above code works pretty well. But I even want to display all buddy press members activity in a page called global page. Is this possible to display only me and friends activity is one page and in other page all buddy press member activities..
Hi Brajesh, when there is only 1 friend or 1 follower connection…there is an error –
array_push() expects parameter 1 to be array. What do you suggest?
Hi NM,
I am not sure about the follower but the function "friends_get_friend_user_ids" will always return an array even when there are no friends. Please do check if something is filtering and causing any issue.