How can you access a user's permissions within php as you can can there user id and name via $user->uid and $user->name respecitvely? I want to be able to check their permissions to hide certain fields.

Comments

anner’s picture

If you are basing your permission of the role(s) of the user, which is the default method, it would be $user->roles ..as in:

if (is_array($user->roles) && in_array('SuperAdmin', $user->roles)) {
do something;
} else { don't }
wpd’s picture

This way requires custom code, but uses the drupal access system.

1. Define a new permission. http://api.drupal.org/api/4.6/group/node_access
2. Assign a role under admin>access control
3. In your display code use user_access
http://api.drupal.org/api/4.6/function/user_access

<?php 
  if(user_access('secret stuff')){
    print $secret_stuff;
  }
?>

White Paper Designs