Navigation visible only to Admin

Permalink 1 user found helpful
Hello. I'm not very familiar with PHP and wish to limit the visibility of the nav to Admin only. I read some and tried this, but don't know if it works or how to see or set the permissions.

<?php
$a = new Area('Header Nav');
$p = new Permissions($a);
$p->display($c);
?>

Advice is welcomed.

View Replies:
boomgraphics replied on at Permalink Reply
boomgraphics
Hello, I think this is what you are looking for. It looks for instances where the dashboard edit bar is visible, and then does something. In this case, i've set it to display the area only if you are logged in and "can admin page" or "can write" or "can add subcontent" or "can approve collection".

<?php
$cp = new Permissions($c);
$headerBar = is_object($cp) && ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage() || $cp->canApproveCollection());
if ($headerBar){
        $a = new Area('Header Nav');
        $a->display($c);
}
?>


Hope it helps! :-)
beebs93 replied on at Permalink Reply
beebs93
You can also try:
$u = new User();
if($u->isSuperUser()){
  $area = new Area('Header Nav');
  $area->display($c);
}


Note: This would only allow the main admin (not anyone in the 'Administrators' default group) to see this. If you wanted to allow both the super user AND anyone in said group:

$u = new User();
if($u->isSuperUser() || $u->inGroup(Group::getByName('Administrators'))){
  $area = new Area('Header Nav');
  $area->display($c);
}


If you already are using the advanced permissions model you can control who can see/edit the area as well. I wouldn't turn on advanced permissions if you are only going to use it on this one area. Doing it programatically with either examples shown here would be the best bet.
boomgraphics replied on at Permalink Reply
boomgraphics
Beebs93, thanks for that last one. I didn't know you could check for a group. This opens some interesting possibilities. :-)