Skip to:
Content
Pages
Categories
Search
Top
Bottom

Exclude only admins from members list.


  • MickFrench
    Participant

    @mickfrench

    Hello !
    Is there a way to exclude admins from the front users list? And also from the item list tabs?
    I’m building a little dating website for seniors and administrators are not supposed to be into the dating.
    Thanks for listening !

Viewing 4 replies - 1 through 4 (of 4 total)

  • michaelabf
    Participant

    @michaelabf

    This should explain how …

    Hiding Users on BuddyPress based site


    MickFrench
    Participant

    @mickfrench

    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 ?


    michaelabf
    Participant

    @michaelabf

    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.


    MickFrench
    Participant

    @mickfrench

    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’ );

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar