[[+has_access:is=`1`:then=`
Show the premium content.
`:else=`
Sorry, you need to purchase this content first. Here's a form, etc.
`]]
This question has been answered by patrickappelman. See the first response.
// Set Properties
$current_resource_id = $modx->resource->get('id'); // Gets the current Resource ID
$target_resource_id = $modx->getOption('id', $scriptProperties, $current_resource_id); // If specified, overrides the current Resource ID
$target_resource = $modx->getObject('modResource',$target_resource_id); // Gets the Resource object of the targeted Resource ID
$resourceGroups = array();
$hasAccess = true;
foreach($target_resource->getGroupsList() as $resourceGroupsList){
if(is_array($resourceGroupsList)) {
foreach ($resourceGroupsList as $resourceGroup) {
$resourceGroupArray = $resourceGroup->toArray();
if(is_array($resourceGroup->toArray())) {
if ($resourceGroup->get('access')=='1') {
foreach ($resourceGroup->toArray() as $key => $value) {
if ($key == 'name') {
$resourceGroups[] = $value;
}
}
}
}
}
}
}
if (!empty($resourceGroups)) {
$user = $modx->getUser();
$hasAccess = $user->isMember($resourceGroups);
}
return $hasAccess;[[!get_user_access]]
[[!get_user_access? &id=`24`]]