Thank you Michael,
It doesn’t work. I have tried the second code for admnins and also the first code by excluding users by ID (numbers of the admins I want to hide).
Tried at the root of folder Plugins and BuddyPress, also into the code directly in functions.php of my theme Sydney… nothing works.
Hoping you or someone have another idea ?
Think it needs to go in bp-custom.php
Failing that, try using the Code Snippets plugin to add it. Usually works.
Failing that, reach out to Brajesh at BuddyDev, he will assist.
Thank you Michael, it works using Code Snippets with this code:
/**
* Exclude Users from BuddyPress Members List by WordPress role.
*
* @param array $args args.
*
* @return array
*/
function buddydev_exclude_users_by_role( $args ) {
// do not exclude in admin.
if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) {
return $args;
}
$excluded = isset( $args[‘exclude’] ) ? $args[‘exclude’] : array();
if ( ! is_array( $excluded ) ) {
$excluded = explode( ‘,’, $excluded );
}
$role = ‘administrator’;// change to the role to be excluded.
$user_ids = get_users( array( ‘role’ => $role, ‘fields’ => ‘ID’ ) );
$excluded = array_merge( $excluded, $user_ids );
$args[‘exclude’] = $excluded;
return $args;
}
add_filter( ‘bp_after_has_members_parse_args’, ‘buddydev_exclude_users_by_role’ );
I’m bumping this as I’ve had this code working for the past few years. After I updated the server from 7.3 to 8.0 the exclusion stopped working. Any reason why that may be?
@webarctech Can’t say for sure as to your issue, but I had to replace all the single quotes after copying and pasting the code that is above your post. After that, it worked for PHP 7.4, 8.0, 8.1 & 8.2; it may be that PHP 7.3 allowed (which I don’t have) something that 8.0 doesn’t. If you haven’t already, you should check your error log, it may provide some insight as to what the issue might be.