Skip to:
Content
Pages
Categories
Search
Top
Bottom

Exclude Site Role From Member Directory


  • GyziieDK
    Participant

    @dreampixel

    Hello guys! 🙂

    I’m looking to exclude a specific user role/site role from being shown within the member directory. I’ve found some snippets online, but most are super outdated and dosen’t really provide a useful solution.

    Anyone who might be able to help with this? 🙂

Viewing 1 replies (of 1 total)

  • GyziieDK
    Participant

    @dreampixel

    Figured it out (I’m stupid lol).

    I can confirm that the snippet from Brajesh Singh still works. Just make sure to place it into your bp-custom.php (/wp-content/plugins/bp-custom.php). Turns out my role wasn’t called “Basic” (as shown/named within the backend). Since I use Paid Membership Pro it used pmpro_role_1 set by PMP.

    Remember to change the role within the code down below to the one you want to exclude. 🙂

    Credit: https://buddydev.com/hiding-users-on-buddypress-based-site/

    /**
     * Exclude Users from BuddyPress Members List by WordPress role.
     *
     * @param array $args args.
     *
     * @return array
     */
    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' => $role, 'fields' => 'ID' ) );
    
    	$excluded = array_merge( $excluded, $user_ids );
    
    	$args['exclude'] = $excluded;
    
    	return $args;
    }
    
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' );
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar