Last active
May 13, 2020 11:41
-
-
Save messica/35e08a8f8322431721d9c647864236b8 to your computer and use it in GitHub Desktop.
Hide pending/denied members from BuddyPress member directory.
This file contains 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 | |
// Exclude pending and denied members from BuddyPress directory. | |
function my_pmpro_bp_bp_pre_user_query_construct( $query_array ) { | |
// Only apply this to the directory. | |
if ( 'members' != bp_current_component() ) { | |
return; | |
} | |
// Only continue if PMPro Approvals is active. | |
if ( ! class_exists( 'PMPro_Approvals' ) ) { | |
return; | |
} | |
// Only continue if there are members to check. | |
global $pmpro_bp_members_in_directory; | |
if ( empty( $pmpro_bp_members_in_directory ) ) { | |
return; | |
} | |
// Remove users who aren't approved. | |
$exclude = array(); | |
foreach( $pmpro_bp_members_in_directory as $user_id ) { | |
if ( ! PMPro_Approvals::isApproved( $user_id ) ) { | |
$exclude[] = $user_id; | |
} | |
} | |
$query_array->query_vars['exclude'] = $exclude; | |
} | |
add_action( 'bp_pre_user_query_construct', 'my_pmpro_bp_bp_pre_user_query_construct', 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment