Template variable for checking group membership

A perfect place for code snippets to small to be a MOD or a library.
Or for examples on how to use our libraries.
Post Reply
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6243
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Template variable for checking group membership

Post by RMcGirr83 »

This post was originally posted by Kenny at 6 String MODs, I have made some minor adjustments and we in the team will try to fix any bugs in the included codes.

I keep loosing this snippet and quite often I notice people asking for it, so I decided to post it here.

#
#-----[ OPEN ]------------------------------------------
#
includes/functions.php
#
#-----[ FIND ]------------------------------------------
#

Code: Select all

        // application/xhtml+xml not used because of IE
        
header('Content-type: text/html; charset=UTF-8'); 

#
#-----[ BEFORE, ADD ]------------------------------------------
#

Code: Select all

if (!function_exists('group_memberships'))
{
    include(
$phpbb_root_path 'includes/functions_user.'.$phpEx);
}
$groups group_memberships(false,$user->data['user_id']);
if (
sizeof($groups))
{
    foreach (
$groups as $grouprec)
    {
        
$template->assign_vars(array(
            
'S_GROUP_' $grouprec['group_id'] => true)
        );
    }


Now on any page, you should be able to use this switch

Code: Select all

<!-- IF S_GROUP_X -->

Just replace X with ID of the group. You can also expand on that and add multiple groups and/or any other template function that is built into phpBB

Code: Select all

<!-- IF (S_GROUP_1 or S_GROUP_2) --> // if user is in either of the groups

Code: Select all

<!-- IF (S_GROUP_1 and S_GROUP_2) --> // User has to be in both groups to return true

Code: Select all

<!-- IF not S_GROUP_X --> // Show for all except that group
wads2424
New member
New member
Posts: 1
Joined: 13 Mar 2021, 04:06

Re: Template variable for checking group membership

Post by wads2424 »

Has anyone made an extension for this modification? So, I don't have to modify core files after each upgrade.
User avatar
bonelifer
Administrator
Administrator
Posts: 477
Joined: 24 Jun 2006, 17:48
Real name: William
Location: htpc.MythBuntu

Re: Template variable for checking group membership

Post by bonelifer »

wads2424 wrote:Has anyone made an extension for this modification? So, I don't have to modify core files after each upgrade.
https://www.phpbb.com/customise/db/exte ... _variables
Post Reply