WCF: Check User Group Membership

Warning: This page is a part of an archive now and will be removed in the future.

From time to time users ask how to check for users, who have specific user group memberships. Thus there are several possibilities – based on the area where to check – I want to declare it in this article.

At first you need the ID of the user group whose membership should be checked. You can find it directly in the ACP under Users -> User Groups -> List User Groups. In the first row, beside the icons, you can see a number, which represents the ID of the particular user group. This ID will be used for the check inside the code.


Template
In templates the query is the following:
{if GROUP_ID|in_array:$__wcf->user->getGroupIDs()}Content{/if}
Just replace the GROUP_ID with the real ID of the user group you want to check. If the user is in this user group the character string Content is displayed.

PHP
In PHP the query is similar:
if (in_array(GROUP_ID, WCF::getUser()->getGroupIDs())) { … }
Again just replace the GROUP_ID with the ID of your desired user group.
About the Author
Ich bin Webentwickler in Stuttgart und administriere Server seit vielen Jahren. In diesem Blog erstelle ich hauptsächlich Tutorials für andere Webentwickler, Webdesigner und Serveradministratoren.
-------------------------------------------------------------------------------------------------------------------------------------
I’m a web developer in Stuttgart, Germany, and server administrator since many years. This blog mainly contains a tutorial set for other web developer, web designer and server administrators.

353 times read

Comments 0

There are not any items at the moment.

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.