Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hide deactivated users from members loop


  • cityfox
    Participant

    @cityfox

    Hi,

    how can I hide deactivated users from the members loop?

    I work on an Intranet site based on WordPress for my company. I use BuddyPress and the plugin Active Directory Integration for displaying our staff. If a staff member leaves the company he/she will be automatically deactivated in WordPress. That means that the checkbox “User deactivated” is checked in the user’s profile in the back end. But these users are still displayed in the members loop. How can I exclude users from the loop based on whether they are deactivated?

    I already read this thread:
    https://buddypress.org/support/topic/hide-members-from-members-directory/

    But this code doesn’t work (added directly after bp_the_member() in members-loop.php):

    <?php while ( bp_members() ) : bp_the_member(); ?>

    <?php

    $user = new WP_User( bp_get_member_user_id() );
    if ( ($user->roles[0] == 'blocked') ) continue;
    ?>

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

  • cityfox
    Participant

    @cityfox

    After more research and trying I found a solution that works for my case. Maybe it helps other people, too.

    I added the following code in the members-loop.php directly after bp_the_member():

    $user_id = bp_get_member_user_id();
    if (get_user_meta($user_id,'adi_user_disabled', true)) continue;

    Henry Wright
    Moderator

    @henrywright

    @cityfox the only problem with that approach is it doesn’t consider pagination.


    cityfox
    Participant

    @cityfox

    I don’t understand exactly what you mean. For me pagination works well.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide deactivated users from members loop’ is closed to new replies.
Skip to toolbar