hide admin and student role from BP members directory

Home Forums Legacy Support Support queries Other issues hide admin and student role from BP members directory

Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #205999
    David
    Spectator
    Hello everyone, I hope you're doing well. I am trying to hide admin and student roles from the Buddypress members directory. I have tried many codes but they didn't work. Am I missing something on this code because it seems to work for many people. Are the admin role called 'administrator' and the student role 'student' ? Here is the snippet code if it can help : function get_user_ids_by_role($role){ $users=array(); $founded_users = get_users( array( 'role' => $role ) ); if(!empty($founded_users)){ foreach((array)$founded_users as $user) $users[]=$user->ID; }   return $users; }   function exclude_by_role( $exclude_roles, $implode = true ) { $memberArray = array(); foreach ( $exclude_roles as $exclude_role ) { $memberArray = array_merge($memberArray, get_user_ids_by_role($exclude_role) ); }   if( !$implode ) return $memberArray;   $theExcludeString = implode( ",", $memberArray ); return $theExcludeString; }     add_action('bp_ajax_querystring','bp_exclude_byroles',20, 2); function bp_exclude_byroles($qs=false,$object=false){   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;   $excluded_roles = array( 'administrator', 'student' ); // you can add roles here $exclude = exclude_by_role( $excluded_roles );   if(!empty($args['exclude'])) $args['exclude']=$args['exclude'].','.$exclude; else $args['exclude'] = $exclude;   $qs = build_query($args); return $qs; } Thank you!! David
    #206005
    David
    Spectator
    This reply has been marked as private.
    #206279
    David
    Spectator
    Hello, Is there any answer ? Thanks.
    #206419
    Mk
    Moderator
    This reply has been marked as private.
    #206420
    Mk
    Moderator
    For me this code is working fine :   function get_user_ids_by_role($role){ $users=array(); $founded_users = get_users( array( 'role' => $role ) ); if(!empty($founded_users)){ foreach((array)$founded_users as $user) $users[]=$user->ID; } return $users; } function exclude_by_role( $exclude_roles, $implode = true ) { $memberArray = array(); foreach ( $exclude_roles as $exclude_role ) { $memberArray = array_merge($memberArray, get_user_ids_by_role($exclude_role) ); } if( !$implode ) return $memberArray; $theExcludeString = implode( ",", $memberArray ); return $theExcludeString;   } add_action('bp_ajax_querystring','bp_exclude_byroles',20, 2); function bp_exclude_byroles($qs=false,$object=false){ 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; $excluded_roles = array( 'administrator', 'student' ); // you can add role's slug here $exclude = exclude_by_role( $excluded_roles ); if(!empty($args['exclude'])) $args['exclude']=$args['exclude'].','.$exclude; else $args['exclude'] = $exclude; $qs = build_query($args); return $qs; }
    #206421
    Mk
    Moderator
    One more thing , while using above code please confirm your role's slugs. You can check slugs here : http://prntscr.com/nh7cr5  
    #206469
    David
    Spectator
    Thank you so much! The issue is resolved thanks to your clear explanation. Greetings :)
Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘hide admin and student role from BP members directory’ is closed to new replies.