Skip to:
Content
Pages
Categories
Search
Top
Bottom

Don't show certain member roles in Member widget


  • Joost23
    Participant

    @joost23

    How we can don’t show certain member roles in the Member widget from BuddyPress? We use the following code for the member overview page, that’s working, but not for the widget.

    
    `/*-----------------------------------------------------------------------------------*/
    /*	Buddypres don't show roles 
    /*-----------------------------------------------------------------------------------*/
    
    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','employer' ); // 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;
    }
    '
  • The topic ‘Don't show certain member roles in Member widget’ is closed to new replies.
Skip to toolbar