Skip to:
Content
Pages
Categories
Search
Top
Bottom

Exclude ‘subscriber’ members from listings


  • bojates
    Participant

    @bojates

    I am running a subscription site. When membership expires, the member is demoted to a ‘subscriber’ role. They should then be excluded from listings and searches. I had this working ok before the new BuddyPress but it seems a bit trickier with Nouveau. I have the following code so far in bp-custom.php.

    
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' );
    add_filter( 'bp_members_suggestions_query_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 );
        }
     
        $user_ids = get_users( array( 'role__in' => ['subscriber'], 'fields' => 'ID' ) );
        $excluded = array_merge( $excluded, $user_ids );
     
        $args['exclude'] = $excluded;
     
        return $args;
    }
    

    The first filter seems to fix the regular member listing.
    The second filter fixes the autocomplete when trying to find a user for messages.

    Do you know how I can filter the list for inviting members to groups? I’m using Nouveau and it seems to be ignoring these filters at that point.

    Thanks.

  • You must be logged in to reply to this topic.
Skip to toolbar