I have a site with two different type of users: clients and anonymous users.

I'm currently building custom modules to handle a "client administration" section of the site, where clients are able to change their profiles, modify custom settings, etc. There is a section of the site "client" users are able to access, but regular users are not.

How can I restrict access to that section to only a particular class of user?

2 Answers 2


If you implement hook_permission in your custom module, you can control the access of your client administration section.

  1. Set up roles. You've done this already with the client role.
  2. Implement hook_permission():

    function MODULE_permission()
        return array(
            'access client administration' => array(
                'title'       => t('Access Client Administration'),
                'description' => t('Allow users to access client administration'),
  3. When you define hook_menu(), make sure you set the permissions accordingly:

    function MODULE_menu()
        $items['client_administration'] = array(
            'title' => 'Client Administration Page',
            'access arguments' => array('access client administration'),
        return $items;
  4. Go to admin/people/permissions and set the permissions for 'Access Client Administration' to your client role.


Use hook_permission() in your custom module to define a new permission (e.g. "use module foo") and then assign that permission to the appropriate roles. Then check permissions with user_access() wherever necessary in your module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.