Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hiding admins activity and profile errors


  • slimmyweight
    Participant

    @slimmyweight

    Hi all,

    I’m new to buddypress and have no experience with php. I have how ever managed to follow instructions on previous posts on preventing users from seeing the admin profile and activity but it hasnt worked correctly and has come up with errors.

    I managed to create the bp-custom.php in the wp-content/plugins directory but the admin profile still appears and just comes up with an error message saying fatal error. It still allows the option to add as a friend aswell unless that might be to do with viewing it from an account already adding the admin account with.

    This is where I got the code Im using from:
    https://buddypress.org/support/topic/hide-admin-from-members-and-activity/

    Code in the bpcustom file

    
    <?php
    
    function bpfr_hide_admins_profile() {
    	global $bp; 
    	if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) :
    		wp_redirect( home_url() );
    	exit;
    	endif;
    }
    add_action( 'wp', 'bpfr_hide_admins_profile', 1 );
    
    function bpdev_exclude_users($qs=false,$object=false){
        
        $excluded_user='1'; // Id's to remove, separated by comma
    	
        if($object != 'members' && $object != 'friends')// hide admin to members & friends 
        return $qs;
    	
        $args=wp_parse_args($qs);
    
        if(!empty($args['user_id']))
        return $qs;	
    	
        if(!empty($args['exclude']))
    		$args['exclude'] = $args['exclude'].','.$excluded_user;
        else
    		$args['exclude'] = $excluded_user;
    	
        $qs = build_query($args);
    
        return $qs;
    	
    }
    add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);
    
    // once admin is removed, we must recount the members !
    function bpfr_hide_get_total_filter($count){
        return $count-1;
    }
    add_filter('bp_get_total_member_count','bpfr_hide_get_total_filter');
    
    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  ) {			
    			
    			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 );
    
    ?>
    
Viewing 6 replies - 1 through 6 (of 6 total)

  • Henry Wright
    Moderator

    @henrywright

    I recommend using the bp_after_has_activities_parse_args filter to modify the activity stream (remove admin items). Check out this helpful article:

    Using bp_parse_args() to filter BuddyPress template loops


    slimmyweight
    Participant

    @slimmyweight

    Hi Henry,

    Thanks for the reply,

    I’m not a programmer I have basic programming knowledge at best. I’ve tried pasting

    // Fetch only the last five entries for all activity loops
    function my_bp_activities_per_page_5( $retval ) {
        $retval['per_page'] = 5;
     
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_bp_activities_per_page_5' );
    

    at the top of my current code and it is still the same showing an fatal error message and allowing me to view the admins profile.

    Have I put the code in the wrong place, or is it even possible for me to comprehend what I need to do without knowing php?

    Thanks


    Henry Wright
    Moderator

    @henrywright

    I’ve tried pasting … at the top of my current code and it is still the same showing an fatal error message and allowing me to view the admins profile.

    You will need to have a basic understanding of the code to get this done. The code you copied and pasted just limits the activity stream to 5 entries per page. It doesn’t filter admin entries or hide the admin’s profile.


    slimmyweight
    Participant

    @slimmyweight

    Isn’t there code somewhere I can just copy and paste as I tried using parts from the above forum post:

    I copy and pasted.
    https://buddypress.org/support/topic/hide-admin-from-members-and-activity/
    If not I guess I won’t be able to fix it without knowing how to code?


    slimmyweight
    Participant

    @slimmyweight

    bump


    slimmyweight
    Participant

    @slimmyweight

    Is this ever going to be a feature added as an option for none programmers it would be much easier. Is there anything I can do without understanding the code

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar