Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By drupalDougT on
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
roles
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:
user_access
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
White Paper Designs