MyBB Community Forums

Full Version: Filter certain members from memberlist by user or group id
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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 Smile



Nice !
You could do this easier with other methods and there is even a hook if you want this as a pure plugin.

hook: "memberlist_user"

(2010-08-07, 07:14 AM)ghazal Wrote: [ -> ]Nice !

Thanks Smile

(2010-08-07, 07:32 AM)labrocca Wrote: [ -> ]You could do this easier with other methods and there is even a hook if you want this as a pure plugin.

hook: "memberlist_user"

Yeah, I am sure there are probably simpler ways. I've never made a plugin though so I would need to figure out how to go about doing that first haha. If someone does puts this into a plugin I would definitely use it!


Two years later is there any less complicated method available?
I had a method using core edits - it is complicated(ish) but you can use it with the patches plugin.

http://www.leefish.nl/mybb/showthread.php?tid=1174
yup, i just use a core edit to remove super admins. can be done with a single edit line added if you just want a usergroup to be excluded.

http://www.communityplugins.com/forum/sh...hp?tid=118
Yea, I also removed some groups from the members list as well, and the stats. Those spammers get everywhere.....
I just wanted to say that I found this in a search and this is actually REALLY easy to do. It looks hard because of the way the OP wrote so many optional steps but in reality you're just pasting the first code he tells you to paste and then closing with a " } " later on in the file. It just looks long because of each option he shows you separately, but you don't actually do all those things; you just choose which one you want to do or leave it as the original in step 1 was written, which blocks group 7.

This is an old post... The only difference now, is that his second part in Step 1 (for me) had to be changed. This was the line to search for in the second part of step 1 on my files...

eval("\$users .= \"".$templates->get("memberlist_user")."\";");
Which basically the only difference is the spacing/tabbing in front which threw off my search when I tried to find the original. Technically all the coding itself in the line is still the same...

Anyway once you've done that, and then follow the step he gives for pasting right under that line... you're done. Just put in the group number of the group you DO NOT want showing unless you want it to stay "7" like it is in the first part of step 1.

If, however, you only want one group TO show...(meaning, you block all groups except the one you enter)... you can put in the number of the only group you want to display and then make this change to the code:

Right before the number of the group you will see
!=
and you just need to change it to
==
and now you're set to ONLY display the group number that you put there.

Pretty cool! Literally only takes a moment to make this edit. Smile
Be careful with multipage.
Pages: 1 2