Select modules based on the group of the user

(15 votes, average 3.60 out of 5)

Use these recipes to make module selections based on the user group of the logged-in (or not logged-in) user. This can be particularly useful for hiding various modules for users who have already logged in.

If you simply want to hide a single module from logged-in users it's easiest to use the “Show Quick module(s) to” selection in MetaMod. But if you need more control, adapt one of the simple rules below.

Any of the following rules can be used independently of the others.
// if user is not logged in, show mod 44. If they are logged in show mod 45:
if ( MM_NOT_LOGGED_IN ) return 44; else return 45;  
// if user is not logged in, show mod 44. If they are logged in show nothing at all:
if ( MM_NOT_LOGGED_IN ) return 44; else return;
// if user IS logged in, show module 44, else show nothing at all:
if ( MM_LOGGED_IN ) return 44; else return;
// a plain registered user, no additional privileges
if ( MM_USER_REGISTERED ) return 46;
// show a notice for "Author" users
if ( MM_USER_AUTHOR ) return 47;
// show a notice for "Editor" users
if ( MM_USER_EDITOR ) return 48;
// show a notice for "Publisher" users
if ( MM_USER_PUBLISHER ) return 49;
// show a notice for "Manager" users
if ( MM_USER_MANAGER ) return 50;
// show a notice for "Administrator" users
if ( MM_USER_ADMINISTRATOR ) return 51;
// show a notice for "Super Administrator" users
if ( MM_USER_SUPER_ADMINISTRATOR ) return 52;
// show a notice to anyone logged in who is not in the "Author" group
if ( MM_LOGGED_IN && MM_NOT_USER_AUTHOR ) return 53;
// if you are using any Joomla extensions that allow you to create
// your own user groups, you need to use the following syntax:
if ( $user->usertype == "My Special Group Name" ) return 54;