Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Last active January 25, 2020 11:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/2ed72f02953fd2371f5b5ad396b0c353 to your computer and use it in GitHub Desktop.
Save KaineLabs/2ed72f02953fd2371f5b5ad396b0c353 to your computer and use it in GitHub Desktop.
Filter Members Directory By User Role.
<?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