Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to remove admin from members list


  • Pamela
    Participant

    @infoknutsford-softwarecouk

    How do I remove admin which is the site administrator from http://ibsregister.com/members/ please

    I tried

    
    function custom_bp_core_get_users($users, $params) {
    
    		$users_ids_to_hide = array(1);
    
    		if (isset($users['users'])) {
    			foreach($users['users'] as $user_idx => $user) {
    				if (in_array($user->ID, $users_ids_to_hide) !== false) {
    					unset($users['users'][$user_idx]);
    				}
    			}
    			$users['users'] = array_values($users['users']);
    			$users['total'] = count($users['users']);
    		}
    
    		return $users;
    	}
    	add_filter( 'bp_core_get_users', 'custom_bp_core_get_users', 10, 2 );
    

    But I only end up with 19 instead of 40 members.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

  • shanebp
    Moderator

    @shanebp

    Assuming the user_id for the admin is 1, try this:

    function infok_exclude_users($qs=false,$object=false){
        //list of users to exclude
         $excluded_users = '1'; //comma separated ids of users whom you want to exclude
       
        if($object!='members')//hide for members only
            return $qs;
        
        $args=wp_parse_args($qs);
        
        //check if we are searching for friends list etc?, do not exclude in this case
        if(!empty($args['user_id']))
            return $qs;
        
        if(!empty($args['exclude']))
            $args['exclude']=$args['exclude'].','.$excluded_users;
        else 
            $args['exclude']=$excluded_users;
          
        $qs=build_query($args);
         
       return $qs;   
    }
    add_action('bp_ajax_querystring','infok_exclude_users',20,2);

    Pamela
    Participant

    @infoknutsford-softwarecouk

    I already have this bit of code

    
    add_action('bp_ajax_querystring','bpdev_exclude_users', 20, 2 );
    
    function bpdev_exclude_users($qs=false,$object=false){
    	global $count_of_excluded_members;
    	global $count_of_included_members;
    	$count_of_excluded_members = 0;
    	
     	if ($object != 'members') {		
     		return $qs;
    	}
    	
    	$subscribers = get_users('role=subscriber');
    		
    	$exclude = "";
    	foreach ($subscribers as $subscriber) {		
    		if (trim($exclude) != "") {
    			$exclude = $exclude . ",";			
    		}		
    		$exclude = $exclude . $subscriber -> ID;
    		$count_of_excluded_members++;
    				
    	}
    	$administrators = get_users('role=administrator');
    	foreach ($administrators as $administrator) {		
    		if (trim($exclude) != "") {
    			$exclude = $exclude . ",";			
    		}		
    		$exclude = $exclude . $administrator -> ID;		
    		$count_of_excluded_members++;				
    	}
    	$count_of_included_members = 0;
    	$editors = get_users('role=editor');
    	foreach ($editors as $editor) {
    		$count_of_included_members++;				
    	}
    	$contributors = get_users('role=contributor');
    	foreach ($contributors as $contributor) {
    		$count_of_included_members++;				
    	}	
    	$args = wp_parse_args($qs);
    	$args['exclude'] = $exclude; 
    		
     	$qs = build_query($args);		
     return $qs;
     
    }
    

    Which puts 1 in the exclude list and it goes through there so it doesn’t make sense to me


    shanebp
    Moderator

    @shanebp

    The function I provided works.
    It removes a member with ID = 1 from the members loop.
    If you want to use some other function or use 2 or more functions that hook to bp_ajax_querystring, then I can’t help you.


    Pamela
    Participant

    @infoknutsford-softwarecouk

    I agree it should do but as you see it doesn’t unless something else later on is amending the exclude

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to remove admin from members list’ is closed to new replies.
Skip to toolbar