Hide members from Members Directory
-
Hi All,
I was wondering if there was a way to hide/filter out inactive members from the member’s directory in buddypress.
At the moment as long as the person has logged in at least once it shows them in the list; but I would like the members directory to not show them if they haven’t logged in for over 60 days. Is this possible?
Thanks for any help provided.
Robert.
-
or even if there is just a plugin that lets me hide people from the members directory manually on an account by account basis?
The general idea would be to add something like this directly after
bp_the_member()
in members-loop.php$days_since_last_login; if ( $days_since_last_login > 60 ) continue;
You just need to find out how to get the number of days since last login.
That approach is okay, but it’s post query.
Starting in 1.7 there are some pre_query hooks. And I think more in 1.8.
Those hooks are very handy, especially on big sites where performance is an issue.In this context, you would:
Gather all the ids in the stated range
And exclude them from the member query – take a look at the bp_pre_user_query_construct hook.OK, I think I might have cracked it for you. Just tested and this works for me. Add this directly after
bp_the_member()
in members-loop.php<?php $memberid = bp_get_member_user_id(); $now = time(); $last_active = bp_get_user_meta ( $memberid, 'last_activity', true ); $last_active = strtotime( $last_active ); $seconds_since_last_active = $now - $last_active; $minutes_since_last_active = $seconds_since_last_active / 60; $hours_since_last_active = $minutes_since_last_active / 60; $days_since_last_active = $hours_since_last_active / 24; if ( $days_since_last_active > 60 ) continue; ?>
Basically, for each member, this will get the number of days since last active and if that number is greater than 60 then it will skip them (not display that member on the page).
@shanebp thanks – i’ll take a look at pre_query hooks in 1.8 – just about to download the beta and have a play around.
Nice! I’ll give that a shot tonight and let you know how to goes 🙂 really appreciate the help!.
Is there also a way to get it to skip displaying an account that is “locked out”? There is one other situation I need to handle where they might have logged in within the last 60 days but have left the community due to either misconduct or by choice; in that situation we need to remove them from the member’s directory immediately; but at the same time we won’t be deleting their account; just locking it.
Sorry if I’m asking too much here; but thanks again for all the great help! 🙂
forgot to add @henrywright-1 to my post 😉
What do you mean by locking an account? i’m not sure i’ve ever come across that before. Is it standard functionality to WordPress/ BuddyPress or does the functionality come as a plugin?
@henrywright-1 apologies it comes with a plug-in so I’m guessing we won’t know what meta data to query for filtering a person out. How about if I set them to “Blocked” under the forum role; would this be something we could filter against for the member’s directory?
Thanks!.
@henrywright-1 making a bit of a mess of these replies; I should have actually mentioned its bbpress for the forums 🙂
Humm, never used the ‘blocked’ role in bbPress. You could try changing the line:
if ( $days_since_last_active > 60 ) continue;
to
$user = new WP_User( bp_get_member_user_id() ); if ( ($user->roles[0] == 'blocked') || ($days_since_last_active > 60 ) ) continue;
I am not exactly sure if there is a role called “blocked” in bbPress. Perhaps someone else familiar with bbPress can chip in here to confirm?
My approach was taken from this thread:
https://buddypress.org/support/topic/excluding-roles-from-the-member-loop/Hi, Thanks for that.. I’ve just tested the code. It certainly removes members who haven’t logged in for 60 days; however it doesn’t reduce the “member count” on the page; so you end up with empty pages where it says its showing members 80-88 but no-one is listed.
Is there anyway to get the member count to reduce so I don’t have empty pages with invisible members? 🙂
also the role exclusion doesn’t appear to work; I’ve tried replacing it with ‘subscriber’ to see if it was because “blocked” wasn’t the right role phrase; however subscribers were still displayed; so I assume its a code error?
So 2 issues remain.
1. Pagination count
2. Filter by roleWith reference to the first issue, you’d need to rewrite function
bp_members_pagination_count()
which is found in bp-members-template.php. Your new function would go into your theme’s functions.php and would have to account for the recently inactive and blocked users.With reference to the second issue, I think the logic you have is OK – just not sure about the role “blocked” – still hoping for a bbPress expert to advise…
I’m happy to forget filtering members by last activity date.
So to simplify it; can someone can tell me how to filter members from the member’s directory if their WordPress role is set to “no role on this site” (or the blocked role from bbpress). Also when hiding such members the pagination count in the members directory would also need to be correct; as the previous ideas remove the member but not the count; thus you get empty pages saying “showing members X – X” but nothing there.
I’m a totally inept when it comes to coding in PHP so any help really is appreciated.
@rigormortis_uk, did you figure it out? I have the same question, multisite install, on some sites users have no roles, I would like to hide them
- The topic ‘Hide members from Members Directory’ is closed to new replies.