Skip to content

Instantly share code, notes, and snippets.

@vapvarun
Created October 30, 2025 07:37
Show Gist options
  • Select an option

  • Save vapvarun/052c3a11f56f936aede898abc342a98f to your computer and use it in GitHub Desktop.

Select an option

Save vapvarun/052c3a11f56f936aede898abc342a98f to your computer and use it in GitHub Desktop.
BuddyBoss Active/Inactive Members Filter - Complete implementation with dropdown filters and optional visual badges for Members Directory

BuddyBoss Active/Inactive Members Filter

Complete implementation for adding Active/Inactive member filters to BuddyBoss Members Directory.

Features

  1. Dropdown Filter - Adds "Active Members" and "Inactive Members" options to the members directory filter dropdown
  2. Smart Filtering - Filters members based on whether they have activity in the bp_activity table
  3. Visual Badges (Optional) - Displays Active/Inactive status badges on member cards

Installation

Option 1: Dropdown Filter Only (Minimal)

Add the code from functions.php (lines 11-70 only) to your child theme's functions.php file.

Option 2: Complete Implementation (Filter + Visual Badges)

  1. Add all code from functions.php to your child theme's functions.php
  2. Copy members-loop.php to wp-content/themes/buddyboss-theme-child/buddypress/members/members-loop.php
    • OR add the badge code snippet from members-loop-badge-code.php to your existing template

How It Works

Active Members: Users who have at least one entry in the bp_activity table (posts, comments, updates, etc.)

Inactive Members: Users who have NO entries in the bp_activity table

Files

  • functions.php - Filter logic and CSS styles (add to child theme)
  • members-loop-badge-code.php - Template snippet for displaying badges (optional)
  • members-loop.php - Complete template file (reference only)

Usage

  1. Navigate to Members Directory on your BuddyBoss site
  2. Look for the filter dropdown (usually says "Newest Members", "Active Members", etc.)
  3. Select "Active Members" or "Inactive Members" to filter the list
<?php
/**
* BuddyBoss - Active/Inactive Members Filter
* Complete implementation with dropdown filters and optional visual badges
*
* Features:
* 1. Adds "Active Members" and "Inactive Members" to members directory dropdown filter
* 2. Filters members based on activity in bp_activity table
* 3. (Optional) Displays visual status badges on member cards
*/
// ============================================================================
// PART 1: DROPDOWN FILTER (Required)
// ============================================================================
/**
* Custom: Add "Active Members" and "Inactive Members" to member directory filter dropdown
*/
add_filter( 'bp_nouveau_get_members_filters', 'buddyboss_child_add_activity_filter_options', 10, 2 );
function buddyboss_child_add_activity_filter_options( $filters, $context ) {
// Only add to main members directory, not group members
if ( 'group' !== $context ) {
// Add our custom filter options to the existing dropdown
$filters['active_members'] = __( 'Active Members', 'buddyboss' );
$filters['inactive_members'] = __( 'Inactive Members', 'buddyboss' );
}
return $filters;
}
/**
* Custom: Filter members based on activity status when selected
*/
add_filter( 'bp_after_has_members_parse_args', 'buddyboss_child_filter_members_by_activity' );
function buddyboss_child_filter_members_by_activity( $args ) {
// Only apply on members directory
if ( ! bp_is_members_directory() ) {
return $args;
}
// Check if one of our custom filter types is selected
if ( ! isset( $args['type'] ) || ! in_array( $args['type'], array( 'active_members', 'inactive_members' ) ) ) {
return $args;
}
global $wpdb;
// Get user IDs based on activity status
if ( $args['type'] === 'active_members' ) {
// Get users who have activity in bp_activity table
$user_ids = $wpdb->get_col( "SELECT DISTINCT user_id FROM {$wpdb->prefix}bp_activity WHERE user_id > 0" );
} else {
// Get users who have NO activity in bp_activity table
$all_user_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->users}" );
$active_user_ids = $wpdb->get_col( "SELECT DISTINCT user_id FROM {$wpdb->prefix}bp_activity WHERE user_id > 0" );
$user_ids = array_diff( $all_user_ids, $active_user_ids );
}
// Apply the filter
if ( ! empty( $user_ids ) ) {
$args['include'] = $user_ids;
} else {
// No users match the criteria, return empty result
$args['include'] = array( 0 );
}
return $args;
}
// ============================================================================
// PART 2: VISUAL STATUS BADGES (Optional)
// ============================================================================
/**
* Custom: Add CSS for Active/Inactive member status badges
*/
add_action( 'wp_head', 'buddyboss_child_member_activity_status_styles' );
function buddyboss_child_member_activity_status_styles() {
if ( bp_is_members_directory() ) {
?>
<style>
.member-activity-status {
display: inline-block;
padding: 2px 8px;
border-radius: 3px;
font-size: 0.85em;
font-weight: 600;
}
.member-status-active {
background-color: #28a745;
color: #fff;
}
.member-status-inactive {
background-color: #6c757d;
color: #fff;
}
</style>
<?php
}
}
<?php
/**
* Code snippet to add to members-loop.php template
* Location: wp-content/themes/buddyboss-theme-child/buddypress/members/members-loop.php
*
* Add this code after the member name and profile type display (around line 168)
* This displays the Active/Inactive status badge on each member card
*/
// Custom: Check if user has activity (Active/Inactive status)
global $wpdb;
$has_activity = $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(*) FROM {$wpdb->prefix}bp_activity WHERE user_id = %d",
$bp_get_member_user_id
) );
$activity_status = $has_activity > 0 ? 'Active' : 'Inactive';
$activity_status_class = $has_activity > 0 ? 'member-status-active' : 'member-status-inactive';
// Always show the meta line if we have any content to display
$show_meta_line = ( $enabled_last_active && $member_last_activity ) ||
( $enabled_joined_date && $member_joined_date ) ||
true; // Always show at least the status badge
if ( $show_meta_line ) :
echo '<p class="item-meta last-activity">';
$has_content = false;
// Show joined date if enabled and available
if ( $enabled_joined_date && $member_joined_date ) {
echo wp_kses_post( $member_joined_date );
$has_content = true;
}
// Show last activity if enabled and available
if ( $enabled_last_active && $member_last_activity ) {
if ( $has_content ) {
echo '<span class="separator">&bull;</span>';
}
echo wp_kses_post( $member_last_activity );
$has_content = true;
}
// Always add Active/Inactive label
if ( $has_content ) {
echo '<span class="separator">&bull;</span>';
}
echo '<span class="member-activity-status ' . esc_attr( $activity_status_class ) . '">' . esc_html( $activity_status ) . '</span>';
echo '</p>';
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment