Hi there, I’m using this function below to exclude logged and admin users from BuddyPress users list.
https://buddydev.com/support/forums/topic/hide-current-logged-in-user-and-admin/#post-14503
But admin is still displayed when using BP widgets like Who’s Online.
Can I add something to this function to exclude admin from all user lists?Regards
Carstenfunction buddydev_exclude_logged_and_admin_users( $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 ); if ( is_user_logged_in() ) { array_push( $excluded, get_current_user_id() ); } $args['exclude'] = $excluded; return $args; } add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_logged_and_admin_users' )
Hello Carsten,
Thank you for posting. Please try the following code:
/** * Exclude logged in and admin users * * @param array $args Member args. * * @return mixed */ function buddydev_exclude_logged_and_admin_users( $args ) { // Do not exclude in admin. if ( is_admin() && ! wp_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 ); if ( is_user_logged_in() ) { array_push( $excluded, get_current_user_id() ); } $args['exclude'] = $excluded; return $args; } add_filter( 'bp_after_core_get_users_parse_args', 'buddydev_exclude_logged_and_admin_users' );
Regards
RaviHi Ravi, the Dynamic Members List is part of the BP widget package.
I think I have posted this topic before, my Apologies, is it something about that these widgets have a different behavior than eg. Who’s online?
Regards
CarstenHello Carsten,
The issue was BuddyPress using the rest API calls to list dynamic member lists which is why our members were not excluded in this case. Please try the following filter with the same code
add_filter( 'bp_rest_members_get_items_query_args', 'buddydev_exclude_logged_and_admin_users' );
Please check
Regards
Ravi
The topic ‘ [Resolved] Exclude admin from all members lists?’ is closed to new replies.