Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hide member from public based on x-profile setting


  • xmginc
    Participant

    @xmginc

    Hey guys,

    Wondering if there is a way to hide specific members based on a extended profile setting.

    While I see options for hiding based on WordPress user role (i.e. Admin, Author, etc.) or based on WordPress user’s ID #, I’m hoping we can do this via an option available to admins to change whether a member is visible in the directory.

    Also, we found that the options to hide users appear to work on the parent Buddypress but those settings don’t affect the child site in a multiblog/multisite setting.

    Any suggestions is greatly appreciated thanks!

Viewing 1 replies (of 1 total)

  • xmginc
    Participant

    @xmginc

    Update: we have found that with a multisite with multiblog enabled to share the member list from the parent across all the child sites, code to filter out roles such as “administrator” only work if that user is also added to the child site.

    Example:

    Does not work in this scenario:

    – parent site setup with user “johnadmin” with admin role is hidden on parent site directory
    – child site without this user created does not hide him from the site directory

    Works in this scenario:

    – parent site setup with user “johnadmin” with admin role is hidden on parent site directory
    – child site ALSO setup with user “johnadmin” with admin role is hidden on child site directory

    For anyone wondering, the code that is partially working for us is below found at buddydev.com. This code has been added to the functions.php in the child site so that we can control what the child site loop shows individually. (example: parent shows everyone, child 1 shows only subscribers, child 2 only shows x, child 3 only shows y, etc.)

    Would super appreciate any suggestions thx!

    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;
    }
    
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar