Search code examples
drupalhttp-redirectdrupal-6adminuser-roles

drupal 6: redirect admin url for custom user role


I need to redirect a url for a user role.

URL From: http://www.example.com/admin

URL TO: http://www.example.com/admin/content/filter

User Role: example-admin

So, when a user (example-admin role) login to admin panel with the url example.com/admin , he will not see Access Denied page, but redirected to content/filter as default login url.

Appreciate helps! Thanks a lot!


Solution

  • If you want to do it from code in a custom module, you could implement hook_menu_alter() and adjust the access callback function to use a custom override:

    function yourModule_menu_alter(&$items) {
      // Override the access callback for the 'admin' page
      $items['admin']['access callback'] = 'yourModule_admin_access_override';
    }
    

    In that override, you perform the standard access check and return the result, but add the check for the specific role and redirect instead, if needed:

    function yourModule_admin_access_override() {
      global $user;
      // Does the user have access anyway?
      $has_access = user_access('access administration pages');
      // Special case: If the user has no access, but is member of a specific role,
      // redirect him instead of denying access:
      if (!$has_access && in_array('example-admin', $user->roles)) {
        drupal_goto('admin/content/filter');  // NOTE: Implicit exit() here.
      }
      return $has_access;
    }
    

    (NOTE: Untested code, beware of typos)

    You will have to trigger a rebuild of the menu registry for the menu alteration to be picked up.