|
<?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 |
|
} |
|
} |