I would like to require that users be logged in to access a particular MENU_CALLBACK.

The following works, but only for the admin account. Regular users are still denied access:

'access arguments' => array('user_is_logged_in')

There must be an access argument that just checks for authenticated users?

  • If there is no way to do this, I will be creating my own permission using hook_permission() and assigning authenticated users that permission. – jdu Nov 22 '12 at 20:53

access arguments is for the arguments that will be passed to the callback function...you need to use access callback instead:

'access callback' => 'user_is_logged_in'

Since user_is_logged_in() doesn't take any arguments, you can safely remove access arguments for your menu item.

Your current code works for the admin account only because the default access callback is user_access(), which bypasses the access check for user 1.

  • 2
    The opposite then is 'access callback' => 'user_is_anonymous'. – leymannx Feb 16 '16 at 16:25
  • 1
    For Drupal 8 under "requirements" in your YAML file, add this: _role: 'authenticated' – coderama Aug 21 '17 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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