Skip to:
Content
Pages
Categories
Search
Top
Bottom

Excluding some WP basic roles from BP member loop


  • steverusso66
    Participant

    @steverusso66

    Hi, I’m trying to keep one or more WP basic roles, specifically editor and author.. out of my Buddypress community but still allow them to use other WP functionality like publishing posts, etc.

    In this case scenario, I’m using BP for the main population of users, and Ultimate Member for another category of users who are insulated from the BP community but have a profile that can be viewed by all. UM profiles are celebrities who are present in the site with a profile created through the UM registration system and mainly write blog posts. BP profiles are people who interact with each other and use mainly the BP functionality, no blogging.

    Its all working so far but I just haven’t figured out how to get the UM “celebrity” members out of the BP directories, including the alphabetical directory. When the UM member registers, there’s also a BP profile created for him. These should not be available to BP users, only the UM one so I need a way to filter them out completely.

    Another big question I have is how to restrict Buddypress pages, directories, groups etc. I’m using Groups by Itthinx for most of my membership functionality.

    Thanks for any help anyone can provide.

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

  • shanebp
    Moderator

    @shanebp

    You can exclude roles from the members directory like so:

    function steve_exclude_members_loop( $retval ) {
    
        if ( bp_is_members_directory() ) {
    
    		$exclude_ids = get_users(
    			array(
    			        'fields' => 'ID',
    				'role__in' => array( 'editor', 'author' )
    			)
    		);
    
            $retval['exclude'] = $exclude_ids;
        }
     
        return $retval;
    }
    add_filter( 'bp_before_has_members_parse_args', 'steve_exclude_members_loop' );

    Your other issues involve the other plugins you’re using and are more complicated and beyond the scope of these forums.


    steverusso66
    Participant

    @steverusso66

    Thanks Shane.

    would that code go in the functions.php file under Appearance > Editor?


    shanebp
    Moderator

    @shanebp

    It could go into your theme functions.php file.


    steverusso66
    Participant

    @steverusso66

    I tried putting the code in the functions.php theme file as is, without any changes, and it corrupted the site. I had to download the file from the server and remove the code and upload it in order to access the admin again. Could you please advise me more specifically?

    I’m not a coder so your help and patience is much appreciated.

    Thanks


    shanebp
    Moderator

    @shanebp

    The code has been tested without issues on a dev site.
    Do not use the wp-admin editor for making changes, due to the reasons you’ve stated.
    ‘corrupted’ is a very general term.
    What entry did it create in your error_log?


    steverusso66
    Participant

    @steverusso66

    Ok, uploaded the file via File Manager in Cpanel. Seems to be working now, no more white page…

    thanks a bundle, you’re help has been invaluable.

    cheers

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