Skip to:
Content
Pages
Categories
Search
Top
Bottom

Excluding a role from appearing in the directory, activity feed, etc

  • @echoleaf

    Participant

    I have a role called ‘testing’ which is just used for testing purposes. I would like to exclude members with that role from the directory and also prevent all content created by ‘testing’ members from appearing in activity feeds, post archives, etc.

    I check out this 5yo topic and tried replacing this in the member-loop.php:

    <?php while ( bp_members() ) : bp_the_member(); ?>

    with this

    <?php while ( bp_members() ) : bp_the_member();
    $user = new WP_User( bp_get_member_user_id() );
    if ( $user->roles[0] != ‘subscriber’ ) :
    ?>

    That didn’t work. This didn’t work either:

    <?php while ( bp_members() ) : bp_the_member(); ?>
    
    		<?php
           $wp_user = new WP_User( bp_get_member_user_id() );
          if( $wp_user->roles[0] != 'testing' ): ?>

    I’m at a loss as these are the options I found Googling. What is the correct method?

Viewing 21 replies - 1 through 21 (of 21 total)
  • @shanebp

    Moderator

    Don’t check each member in the while loop – very inefficient and things like pagination will be buggy. Just get the members you want.
    Try something like this:

    $test_role_array = get_users( array( 'fields' => 'ID', 'role' => 'testing' ) );
    $test_role_csv = implode(",", $test_role_array).
    $exclude_testing = 'exclude=' . $test_role_csv;
    
    if ( bp_has_members( $exclude_testing ) )  // etc

    @echoleaf

    Participant

    Thanks – where would that go?

    @shanebp

    Moderator

    Same file you used for your code.

    You can also use bp_parse_args. It’s probably more appropriate given that you want to affect various templates.

    @echoleaf

    Participant

    Sorry, that’s beyond me. Adding the code you suggested also broke the /members page just like my other attempts

    @shanebp

    Moderator

    Use pastebin or gist to share your code attempt.

    @echoleaf

    Participant

    @shanebp

    Moderator

    @echoleaf

    Participant

    Bummer – that did not change anything, though the page is no longer broken. Members with the ‘testing’ role still appear :/

    @echoleaf

    Participant

    Anything else I can do make this happen?

    @shanebp

    Moderator

    change this:
    <?php if ( bp_has_members( bp_ajax_querystring( 'members' ) . $exclude_members ) ) : ?>

    to this:
    <?php if ( bp_has_members( bp_ajax_querystring( 'members' ) . $exclude_testing ) ) : ?>

    @echoleaf

    Participant

    Still nothing. I changed the role in
    $test_role_array = get_users( array( 'fields' => 'ID', 'role' => 'testing' ) );

    To ‘Administrator’ and that didn’t do anything either. You can see at http://roofcoachpro.staging.wpengine.com/members/ that ‘Free Member’ and ‘Just Testing’ appear; both of those have the testing role.

    Do you have an example of this working somewhere?

    @neev07

    Participant

    Where is option to create new topic?…. sorry for asking this question here. BUT PLEASE HELP

    @echoleaf

    Participant

    Still nothing. I changed the role in
    $test_role_array = get_users( array( 'fields' => 'ID', 'role' => 'testing' ) );

    To ‘Administrator’ and that didn’t do anything either. You can see at http://roofcoachpro.staging.wpengine.com/members/ that ‘Free Member’ and ‘Just Testing’ appear; both of those have the testing role.

    Do you have an example of this working somewhere?

    @davidryal

    Participant

    I’m trying to solve this as well. I’d hoped for a simple custom fix, but it looks like this might be able to accomplish something similar?

    http://buddydev.com/buddypress/buddypress-user-searching-by-user-roles/ – note the customization section?

    @davidryal

    Participant

    update: I was able to exclude basic roles using the discussion in the end of this thread https://buddypress.org/support/topic/alphabetically-displaying-only-buddypress-users-in-multisite/

    ..but can’t get it working reliably with my membership plugin’s roles (PMPro), and it doesn’t update member counts, so I’m going to try the buddydev plugin method.

    @davidryal

    Participant

    update2: found shane’s answer here:
    http://wordpress.stackexchange.com/questions/196929/how-to-get-member-list-based-on-role-by-using-buddypress

    …and got it to work to only show a single role, which covers about half the users I want to show. I don’t really understand array syntax, but am now neck-deep in the new “role__in” thing in 4.4

    …and finally got it to work, after finding https://gist.github.com/sbrajesh/2142009 (the most recent comment is key, bringing in “role__in”

    @ariktwena

    Participant

    Hi

    Did you find a way to exclude specific user-roles from the activity feeds? I’m having the same issue? :/
    Link to my question

    Thanks

    @steverusso66

    Participant

    I need to exclude Author role from my BP members loop. The authors will all go into a different Directory system with different profile template and no BP functionality, just wordpress blogging capabilities.

    Does anyone have some code I can pop into the functions.php of my child theme?

    thanks!

    @johnjamesjacoby

    Keymaster

    Hey @steverusso66! I noticed you hit an error when you posted your reply; sorry about that.

    Everything should be all fixed up now.

    @steverusso66

    Participant

    that was my fault, I’d forgotten to check “notify me when…” and I did while the form was sending… 🙂

    @steverusso66

    Participant

    I’m testing Ultimate Members running simultaneously with Buddypress. My ‘Author’ roles will have searchable profiles in UM and NOT in BP, and vice versa: All roles EXCEPT ‘Author’ will have access to BP functions, Authors will not have a profile in BP, and ONLY Authors will be able to create a profile in UM.

    Can anyone help me separate these two worlds of users?

    thanks

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