- Hi guys, - I’m trying to create code to allow my website users to be excluded from the sitewide activity stream, per user id. - They simply request to admin to be excluded and I add their user id to the $exclude array and that’s it. A bit crude, but simple and it works. - But there is an issue with one type of activity, the one which shows in the activity stream as “UserA and UserB are now friends x-time ago” - My code correctly excludes this activity if the initiator of the friendship request is in my array. - But I require this activity to be excluded also if the “accepter” is in the array. - So if the initiator OR the accepter is in the array then the activity should be hidden (sitewide). - Could you assist please? - My code is below. - ` 
 function do_not_display_sitewide( $activity_object ) {- // array of user IDs 
 $exclude = array( 1, 2, 3 );- if( in_array( $activity_object->user_id, $exclude ) ) 
 $activity_object->hide_sitewide = true;- } 
 add_action(‘bp_activity_before_save’, ‘do_not_display_sitewide’, 1, 1 );- So something is missing from my code. 
- Sorry, it pasted messy and won’t let me edit. - Here it is again. - function do_not_display_sitewide( $activity_object ) { // array of user IDs $exclude = array( 1, 2, 3 ); if( in_array( $activity_object->user_id, $exclude ) ) $activity_object->hide_sitewide = true; } add_action('bp_activity_before_save', 'do_not_display_sitewide', 1, 1 );
- Update: I looked in the database and it seems like the “secondary_item_id” was also being used to hold info for the type “friendship_created”, so both userIDs can be checked, both initiator and accepter. - I updated my code, it works. - It’s probably poor code, I am not a coder! - Could you please check it’s safe. - Thankyou. - function do_not_display_sitewide( $activity_object ) { // array of user IDs $exclude = array( 1, 2, 3 ); if( in_array( $activity_object->user_id, $exclude ) ) return $activity_object->hide_sitewide = true; if( in_array( $activity_object->secondary_item_id, $exclude ) && $activity_object->type === 'friendship_created') return $activity_object->hide_sitewide = true; } add_action('bp_activity_before_save', 'do_not_display_sitewide', 1, 1 );-  This reply was modified 10 months, 1 week ago by Michael. 
 
-  This reply was modified 10 months, 1 week ago by 
- Hi Michael, 
 Thank you for your post.- Your approach in https://buddydev.com/support/forums/topic/exclude-from-sitewude-activity-stream-per-user-id/#post-54246 is correct one. - There is a problem with your second approach in https://buddydev.com/support/forums/topic/exclude-from-sitewude-activity-stream-per-user-id/#post-54349 - 1. The first approach always hides activity (marks as private) irrespective of what activity type it is. 
 2.- secondary_item_idcould be a lot of things depending on context. It could be a user id or another object id and I will advise checking against it unless you check the $activity->type to ensure secondary_item_id will be user id.- Regards 
 Brajesh
The topic ‘ [Resolved] Exclude from sitewude activity stream per user id’ is closed to new replies.