Pierre today needed a Drupal hack to limit the set of roles, members of which would be displayed on a Drupal users listing page. This is the listing that comes up when you access a URI like: http://example.com/profile. Of course, it took us less than 5 minutes to figure-out how to do it, since Drupal is so awesome. When we were done, we thought about it (yes, it was quicker to do than analyze) and it's a pretty useful hack. I mean, it should be a quite common need to only display, say, bloggers in the user listing but not expose admin user and other technical members.

I am too lazy to make a module of the hack, but here are simple steps of how to do the same on your Drupal install:

  1. Open modules/profile/profile.module file for editing
  2. Find function definition for theme_profile_listing(\$account, \$fields = array())
  3. In the beginning of the function insert something like:\

     //--- HACKED. 
      if ( !in_array("blogger", $account->roles ) ) return "";
      //--- End HACK

    where "blogger" is the role members of which you want to be displayed in the listing. If you have several such groups, you can do something like:

     //--- HACKED. 
      if ( !in_array("blogger", $account->roles )  
        && !in_array("editor", $account->roles )  ) return "";
      //--- End HACK

where you will now be displaying members of "blogger" and "editor" groups. You can keep adding groups like that until the code gets too ugly at which point you can ask yourself - why in the world do you need so many groups? or write a different code.

Have fun