Forked from messica/my_pmpro_bp_approvals_directory_init.php
Created
May 13, 2020 11:41
-
-
Save andrewlimaza/49d15f2f90b1a331aab302996ba914bd 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