Skip to:
Content
Pages
Categories
Search
Top
Bottom

Exclude only admins from members list.

  • @mickfrench

    Participant

    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 6 replies - 1 through 6 (of 6 total)
  • @anonymized-18187419

    Inactive

    This should explain how …

    Hiding Users on BuddyPress based site

    @mickfrench

    Participant

    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 ?

    @anonymized-18187419

    Inactive

    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

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

    @webarctech

    Participant

    I’m bumping this as I’ve had this code working for the past few years. After I updated the server from 7.3 to 8.0 the exclusion stopped working. Any reason why that may be?

    @emaralive

    Moderator

    @webarctech Can’t say for sure as to your issue, but I had to replace all the single quotes after copying and pasting the code that is above your post. After that, it worked for PHP 7.4, 8.0, 8.1 & 8.2; it may be that PHP 7.3 allowed (which I don’t have) something that 8.0 doesn’t. If you haven’t already, you should check your error log, it may provide some insight as to what the issue might be.

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