Last active
October 30, 2025 07:31
-
-
Save vapvarun/314fd76a900492b0c5fa49bb30d88353 to your computer and use it in GitHub Desktop.
BuddyBoss Members Directory Filter - Add Active/Inactive Members dropdown options to filter members
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * BuddyBoss - Active/Inactive Members Filter for Members Directory | |
| * Add "Active Members" and "Inactive Members" dropdown filter options | |
| */ | |
| /** | |
| * 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment