Last active
January 25, 2020 11:16
-
-
Save KaineLabs/2ed72f02953fd2371f5b5ad396b0c353 to your computer and use it in GitHub Desktop.
Filter Members Directory By User Role.
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 | |
/** | |
* Filter Members Directory By User Role. | |
*/ | |
function yzc_filter_members_directory_by_role( $args ) { | |
// do not exclude in admin. | |
if ( ! bp_is_members_directory() ) { | |
return $args; | |
} | |
$included = isset( $args['include'] ) ? $args['include'] : array(); | |
if ( ! is_array( $included ) ) { | |
$included = explode( ',', $included ); | |
} | |
$user_ids = get_users( array( 'role' => 'administrator', 'fields' => 'ID' ) ); | |
$included = array_merge( $included, $user_ids ); | |
$args['include'] = $included; | |
return $args; | |
} | |
add_filter( 'bp_after_has_members_parse_args', 'yzc_filter_members_directory_by_role' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment