Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewlimaza/49d15f2f90b1a331aab302996ba914bd to your computer and use it in GitHub Desktop.
Save andrewlimaza/49d15f2f90b1a331aab302996ba914bd to your computer and use it in GitHub Desktop.
Hide pending/denied members from BuddyPress member directory.
<?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