The “Like this, a complete snippet for functions.php :” has a more complete version, and now works with categories or taxonomies.
I also made a cache function so that a already known information loaded on that template page, doesnt have to query the stuff again.
The plugin WILL slow down your site and grow negative, but this is common with many protectet systems. I try to keep this like s2member “quality”:
function uamIsAccess($show_groups = 0){
global $oUserAccessManager;
if(!isset($oUserAccessManager)) return '';
if($show_groups === true) $show_groups = 1;
if($show_groups === false) $show_groups = 0;
if($show_groups == 0 || $show_groups == 1) {
global $post;
$sLink = '';
if (is_category()) {
$iPostId = get_query_var('cat');
$iPostType = 'category';
} else {
$iPostId = $post->ID;
$iPostType = get_post_type($iPostId);
}
//echo $iPostId;
if(isset($GLOBALS['UAM-CACHE'][$iPostId][$show_groups])) {
return $GLOBALS['UAM-CACHE'][$iPostId][$show_groups];
} else {
if (isset($oUserAccessManager)) {
//echo $iPostId. ' ' .$iPostType;
$oUamAccessHandler = $oUserAccessManager->getAccessHandler();
$aGroups = $oUamAccessHandler->getUserGroupsForObject($iPostType, $iPostId);
if (count($aGroups) > 0) {
if(!$show_groups) {
$sLink = __('This area is protected. Only users with the same capabilities can view this content', 'UA Network');
} else {
$sLink = TXT_UAM_ASSIGNED_GROUPS.' : ';
foreach ($aGroups as $oGroup) {
$sLink .= $oGroup->getGroupName().', ';
}
$sLink = rtrim($sLink, ', ');
}
}
}
$GLOBALS['UAM-CACHE'][$iPostId][$show_groups] = $sLink;
return $sLink;
}
} else return 'ERR: Invalid uamIsAccess() call. Arguments must be (bool) true or false';
}
This return 2 states, one the name of the assigned groups, like the after edit links for admins. And The false version, just telling the user that this is safe and protected.
The latter, is to make the users feel good when commenting on protected stuff, or interacting whatever. My clients are happy anyway…
echo uamIsAccess()
echo uamIsAccess(true)
if(uamIsAccess()) { this stuff is protected in any way ... } else { This has no restrictions ... }
I think it works to just paste in ya functions.php
file