Created
March 31, 2022 03:43
-
-
Save KaineLabs/8e76c9a2bb646f27a046c88f287fa205 to your computer and use it in GitHub Desktop.
Youzify - BuddyPress Exclude Users from Members Directory by Meta Value
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 | |
/** | |
* Youzify - BuddyPress Exclude Users from Members Directory by Meta Value | |
* Ps: Adminstartor can see everyone one. | |
*/ | |
function yzc_exclude_users_by_meta_value( $args ) { | |
// do not exclude in admin. | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { | |
return $args; | |
} | |
$args = array( | |
'fields' => 'ID', | |
'meta_query' => array( | |
'relation' => 'AND', | |
array( | |
'key' => '_gamipress_trees_points', | |
'value' => 10, | |
'compare' => '<' | |
) | |
) | |
); | |
$user_ids = get_users( $args ); | |
if ( ! empty( $user_ids ) ) { | |
$excluded = isset( $args['exclude'] ) ? $args['exclude'] : array(); | |
if ( ! is_array( $excluded ) ) { | |
$excluded = explode( ',', $excluded ); | |
} | |
$excluded = array_merge( $excluded, $user_ids ); | |
$args['exclude'] = $excluded; | |
} | |
return $args; | |
} | |
add_filter( 'bp_after_has_members_parse_args', 'yzc_exclude_users_by_meta_value' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment