Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Hide Admin(s) from Bp Widget

  • @livingflame

    Participant

    Please, Help!

    I need a Php code (functions.php) for Hide Admin(s) from BuddyPress Widget (Newest, Active, Popular… or whatever).

    Im using this ===> But, I need for Bp W.

    // Deny access to admins profile. User is redirected to the homepage
    
    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 );
    
     
    
     
    
    // 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  ) {
    
     
    
    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 );
    
     
    
     
    
    // Remove admin from the member directory
    
    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’);
Viewing 2 replies - 1 through 2 (of 2 total)
  • @livingflame

    Participant

    @livingflame

    Participant

    I found the solution:

    // Exclude Admins from Directories and BP Widgets 
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users' );
     
    function buddydev_exclude_users( $args ) {
        //do not exclude in admin
        if( is_admin() && ! defined( 'DOING_AJAX' ) ) {
            return $args;
        }
        
        $excluded = isset( $args['exclude'] )? $args['exclude'] : array();
     
        if( !is_array( $excluded ) ) {
            $excluded = explode(',', $excluded );
        }
        
        $user_ids = array( 1, ); // enter user ids here
        
        
        $excluded = array_merge( $excluded, $user_ids );
        
        $args['exclude'] = $excluded;
        
        return $args;
    }
    
    // Deny access to admins profile. User is redirected to the homepage
    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 );
    
    // 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  ) {			
    			
    			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 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Hide Admin(s) from Bp Widget’ is closed to new replies.
Skip to toolbar