2010-08-07, 04:11 AM
HOW TO: Filter Certain Members from Memberlist by User or Group ID
I recently found the need to filter banned members from the memberlist. I did not want regular members seeing any banned users accounts. I searched the MyBB community forums for awhile. I found many people asking how to hide admins from the memberlist, which is similar to what I wanted to do, but could not find any obvious way of doing it. So I decided to solve my problem, the manual way. To my surprise, it worked! So I decided to create this tutorial and share my solution.
I am going to show you how to filter out members from the member list by both user ID or group ID or both. This is a relatively simple tutorial that requires some basic PHP knowledge.
[IMPORTANT NOTE!]
This requires the modification of core MyBB files.
Before we begin, you should backup "[ROOT]/memberlist.php", where "[ROOT]" is the location you installed MyBB.
Step 1: Add the code
The first step is to locate and open your "memberlist.php" file which we backed up earlier.
Find this line:
while($user = $db->fetch_array($query))
{
Just below that add:
//FILTER
if($user['usergroup'] != "7")
{
//FILTER
It should now look something like this:
while($user = $db->fetch_array($query))
{
//FILTER
if($user['usergroup'] != "7")
{
//FILTER
Then directly below this line:
eval("\$users .= \"".$templates->get("memberlist_user")."\";");
Add this:
//ENDFILTER
}
//ENDFILTER
The comments are just in case you ever decide to remove the filter, you can easily find them again by searching for "filter".
Step 2: Modify the code
This last step is to modify the code to filter what you want.
The first part of the code you added is a PHP "if" statement that only displays the user if they are NOT in the group you specified.
Here are some other common filters you may want to try.
This filters all Banned users from the memberlist. (This is the one we used above)
if($user['usergroup'] != "7")
This filters all Administrators from the memberlist.
if($user['usergroup'] != "4")
This filters all Unactivated users from the memberlist. (Any users that are in the "Awaiting Activation" group)
if($user['usergroup'] != "5")
This filters all Moderators from the memberlist.
if($user['usergroup'] != "3")
You can filter any usergroup you want by replacing the GIDHERE with your own GID (Group ID)
if($user['usergroup'] != "GIDHERE")
Alternately you can filter by display group
if($user['displaygroup'] != "DisplayGroupID")
You can also filter a specific member by UID (User ID)
if($user['uid'] != "UIDHERE")
To get the user id of any member, just visit their profile. In the URL you will see the user id
/member.php?action=profile&uid=1234
If you want to filter simply by username, you can use the following. However remember that if you or the member changes their username, the filter will no longer work.
if($user['username'] != "UserNameHere")"UserNameHere"
This can all be very useful in hiding members or groups of members from your memberlist.
I have only tested this using MyBB 1.4.11. If this works on MyBB 1.6, post below and I will make a note of it here.
If you need help figuring out how to do this tutorial, use this thread for help.
[NOTE: When Updating]
When updating MyBB you will need to re-add any filters you previously added. This is because MyBB will overwrite any modifications to the memberlist.php file. Make sure make a copy of the code before you update. Then you can easily re-add it later.
Also, this is my first tutorial. Any feedback would be great