How to hide Admin activities in BuddyPress

Hello,
I have BuddyPress running in my WP Network. The current problem is how to hide all the admin/selected users' activity in Activity in BuddyPress? I don't want public see my admin accounts' activities.

  • Nastia

    Hello Yudong

    I trust you are doing well today!

    The code below should hide the admin's activity with user ID=6

    // hide admin's activities from all activity feeds
    function bpfr_hide_admin_activity( $a, $activities ) {	
    
    	// ... but allow admin to see his activities!
    	if ( is_site_admin() )
    		return $activities;	
    
    	foreach ( $activities->activities as $key => $activity ) {
    		// ID's to exclude, separated by commas. ID 1 is always the superadmin
    		if ( $activity->user_id == 6  ) {			
    
    			unset( $activities->activities[$key] );			
    
    			$activities->activity_count = $activities->activity_count-1;
    			$activities->total_activity_count = $activities->total_activity_count-1;
    					$activities->pag_num = $activities->pag_num -1;
    		}
    	}
    	// Renumber the array keys to account for missing items
    	$activities_new = array_values( $activities->activities );
    	$activities->activities = $activities_new;	
    
    	return $activities;
    
    }
    add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 );

    I hope this helps!

    Cheers,
    Nastia

  • Nastia

    Hello Yudong

    I hope everything is well!

    Please use the following code. Thanks to Panos he has modified it to your needs and added 2 user ID inside: 1 and 2.

    // hide admin's activities from all activity feeds
    function bpfr_hide_admin_activity( $a, $activities ) {	
    
    	// ... but allow admin to see his activities!
    	if ( is_site_admin() )
    		return $activities;	
    
    	foreach ( $activities->activities as $key => $activity ) {
    		// ID's to exclude, separated by commas. ID 1 is always the superadmin
    		if( $activity->user_id == 1 || $activity->user_id == 6){			
    
    			unset( $activities->activities[$key] );			
    
    			$activities->activity_count = $activities->activity_count-1;
    			$activities->total_activity_count = $activities->total_activity_count-1;
    					$activities->pag_num = $activities->pag_num -1;
    		}
    	}
    	// Renumber the array keys to account for missing items
    	$activities_new = array_values( $activities->activities );
    	$activities->activities = $activities_new;	
    
    	return $activities;
    
    }
    add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 );

    I hope this helps!

    Cheers,
    Nastia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.