BuddyDev

Search

Hide role type in directory of multiblog enabled multisite

  • Participant
    Level: Enlightened
    Posts: 24
    xmginc on #10649

    Hello,

    Your code to hide role types works perfectly for a single BuddyPress install (https://buddydev.com/buddypress/hiding-users-on-buddypress-based-site/)

    However, on a multiblog enabled multisite, if the member is not included in both the parent and child site with the specific role type, it does not filter and hide that user from the member loop.

    Is there a way to call the role type from a specific child or parent site so that when this is called, it knows to filter it out? Hope this makes sense!

    Example:

    Parent site has a list of users and “John” is an admin.

    When viewing parentsite.com/members, John is not shown.

    On the child site, “John” is not an admin or a user at all.

    When viewing parentsite.com/childsite/members, John appears *unless* you also include John as an admin of the child site.

    Is there any way to choose the role of a specific multisite install or all to filter them when displaying the member directory?

    Here is what I am using based on your code below.

    Thank you in advance

    add_filter( ‘bp_after_has_members_parse_args’, ‘buddydev_exclude_users_by_role’ );

    function buddydev_exclude_users_by_role( $args ) {
    //do not exclude in admin
    if( is_admin() && ! defined( ‘DOING_AJAX’ ) ) {
    return $args;
    }

    $excluded = isset( $args[‘exclude’] )? $args[‘exclude’] : array();

    if( !is_array( $excluded ) ) {
    $excluded = explode(‘,’, $excluded );
    }

    //$role = ‘administrator’;//change to the role to be excluded
    $user_ids = get_users( array( ‘role__in’ => [‘administrator’ , ‘contributor’ , ‘author’, ‘editor’] ,’fields’=>’ID’) );

    $excluded = array_merge( $excluded, $user_ids );

    $args[‘exclude’] = $excluded;

    return $args;
    }

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #10769

    Hi,
    On WordPress multisite, User roles are specific to a Site.
    For example Admin of one site may not be member of another site or may be just a contributor to another site.

    The only global role at the moment is super admin.

    If you are planning to hide based on role, It will be site dependent.

    Hope that clarifies.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 24
    xmginc on #10786

    Thanks very much for your insight – I just started trying your BuddyPress Profile Visibility Manager and BuddyPress Member Types Pro – can’t believe I didn’t try these sooner!

    I’m currently trying to see what is the best combination but here is what I’m trying to do either with these plugins or continuing with the code above:

    Publicsite .com/members
    – show standard members directory + profile page
    – hide Admin, Contributors, Editors, Authors directory + profile page

    Publicsite .com/privatearea/members
    – show standard members directory + profile page
    – show Admin, Contributors, Editors, Authors directory + profile page

    So far, your Visibility Manager plugin is amazingly powerful.

    One thing I am still trying to see is if I can achieve site independent settings to show for private section but hide for public section for certain roles.

    I’m currently changing tactic based on logged in vs logged out since the public would not be logged in.

    Will post back soon if I can get all of this accomplished with your plugins.

    PS: hard to believe so many questions I see in other forums could all be solved with these plugins 😄

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #10787

    Thank you.

    I have a question before I suggest some answer. Do you have the Multi Blog mode enabled for BuddyPress?

  • Participant
    Level: Enlightened
    Posts: 24
    xmginc on #10788

    Hi Brajesh,

    Yes, multiblog is enabled and I have also sent you the WP login info via message as well.

    Thx!

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #10789

    Hi Kuni,
    Thank you. I just checked the message and site and I feel that now I can assist you better.

    Still, If I see the goal 1, goal 2 from the message, is that what you need? If yes, BuddyPress Member Types pro will be the most suitable.

    1. Create a member type “staff” and make sure that all the staff have this member type.
    In the member type settings, please check “Do Not list on directory” and the staffs will be hidden.

    All we need to do is redirect.

    I am a bit confused between the reply here and the from the message.

    if it is not too much, Can you please list exact goals here or in message(and we need to use only place to communicate to keep it less confusing).

    Thank you
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 24
    xmginc on #10790

    My apologies Brajesh – completely agree and while I’d like to share the final solution here, I’d like to communicate privately by message to be able to easily share login details etc.

    Once the final solution is sorted, I’d like to share it here for anyone else that can benefit from a similar but possibly rare situation 😄

    I will message you details shortly. Thank you!

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #10791

    Hi Kuni,
    No need to apologise.
    Also, if it helps, I can add you to our live chat channel where I can assist you quickly. I will need to send you an invite(It’s slack alternative and we have just started using it).

  • Participant
    Level: Enlightened
    Posts: 24
    xmginc on #10792

    Hi Brajesh, that would be great – I’m in thx!

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #10793

    Thank you. Please check your message.

You must be logged in to reply to this topic.

This topic is: not resolved