Last active
March 1, 2024 09:25
-
-
Save davidpede/1f3c2f76967e655668b28b035dd9c4af to your computer and use it in GitHub Desktop.
Usergroup membership check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Checks current users group membership | |
* | |
* @var modX $modx | |
* @var array $scriptProperties | |
*/ | |
/* set default properties */ | |
$usergroup = $modx->getOption('usergroup',$scriptProperties); | |
$sendError = $modx->getOption('sendError',$scriptProperties) == 1 || null; | |
$group = array(); | |
$member = ($modx->user->isMember($usergroup)) ? 1 : 0; | |
$group[$usergroup] = $member; | |
$modx->setPlaceholders($group, 'ugroup.'); | |
if ($sendError && $member === 0 ) { $modx->sendErrorPage(); } | |
return ''; | |
//usage in modx template or chunk | |
//snippet call sets the placeholder | |
[[!ugroupCheck? &usergroup=`myGroup`]] //snippet call | |
//conditional output | |
//https://docs.modx.com/current/en/building-sites/tag-syntax/output-filters | |
[[!+ugroup.myGroup:eq=`1`:then=` | |
<button id="create_srv_btn" class="btn btn-success">Add New Survey</button> | |
`]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment