将以下代码放在 (子) 主题的 functions.php 文件里即可。
/**
* Exclude Users from BuddyPress Members List by WordPress role.
* 从 BuddyPress 成员列表中排除特定 WordPress 角色的成员。
*
* @param array $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' );
via