• Resolved Carsten Lund

    (@carsten-lund)


    Hi there, when I block a user, my own profile and administrator profile are listed in the members directory.

    I am using this code to exclude logged and admin users from BuddyPress users list which is not working with the plugin activated:

    function 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' );

    How do solve this issue?

    Best
    Carsten

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Ben Roberts

    (@bouncingsprout)

    Hi @carsten-lund,

    I haven’t seen that code before. I will run some tests as soon as I can.

    Regards,

    Ben

    Thread Starter Carsten Lund

    (@carsten-lund)

    Thanks for your prompt reply and for looking into this!

    Regards
    Carsten

    Plugin Author Ben Roberts

    (@bouncingsprout)

    Hey @carsten-lund,

    I’ve just tested this. With the custom code disabled, my members directory correctly shows me (admin) – https://prnt.sc/opgb9c.

    As soon as I enable the code you supplied, I disappear from the member directory, and the user count is updated accordingly – https://prnt.sc/opgcg8.

    It certainly looks like your code works well with the plugin.

    Are you getting different behavior?

    Regards,

    Ben

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hi Ben, thanks for testing this out. That’s strange, I’m experiencing the opposite behavior, the plugin is disabling the code I supplied to you.

    Best
    Carsten

    Plugin Author Ben Roberts

    (@bouncingsprout)

    No problem at all. That certainly is strange. I will mark as resolved, as at the moment I can’t replicate the behavior you describe, but I will continue to explore why it may be happening.

    Best,

    Ben

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hi again, did you try and block a member? this only happens after blocking a member

    Plugin Author Ben Roberts

    (@bouncingsprout)

    Aghhh, sorry @carsten-lund I missed that bit!

    Okay, I see what you mean, very strange – I will start debugging that immediately.

    Plugin Author Ben Roberts

    (@bouncingsprout)

    Hey @carsten-lund,

    I have updated the plugin. Could you let me know whether this fixes your issue?

    Regards,

    Ben

    Thread Starter Carsten Lund

    (@carsten-lund)

    Yes, the issue is fixed with the update, thanks for bringing up a solution so fast!

    Regards
    Carsten

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Own profile and administrator profile are listed in the members directory’ is closed to new replies.