Removing roles from directory

This topic contains 1 reply, has 2 voices, and was last updated by  themosaurus 1 week, 6 days ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3784

    alex
    Participant
    • 187 Posts
    @abourne

    After MUCH effort finding scripts and snippets to remove admin and a particular role -I found one – but it ended up causing problems so disabled.

    Left without a solution, I found this awesome plugin.

    Please suggest it in your docs to help future Gwangi fans like me who want to exclude Admin roles and the like.

    PLUS it allows restriction of profile viewing! the only plugin I can find which does so.

    BP Custom Functionalities

    Under 10 active downloads – not sure how its not been found…

    Here’s the snip used in any case:

    /**
     * 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' );
    #3821

    themosaurus
    Keymaster
    • 1225 Posts
    @themosaurus

    Hi @abourne,

    Thank you for sharing this plugin with our community. #SharingIsCaring ❤️
    We hope that it might help others further customize their BuddyPress website.

    When useful, we won’t hesitate to share the link.

    All the best,

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Removing roles from directory’ is closed to new replies.