16

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?

1
  • 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
    Commented Nov 22, 2012 at 20:53

1 Answer 1

33

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
  • 2
    The opposite then is 'access callback' => 'user_is_anonymous'.
    – leymannx
    Commented Feb 16, 2016 at 16:25
  • 1
    For Drupal 8 under "requirements" in your YAML file, add this: _role: 'authenticated' Commented Aug 21, 2017 at 11:26

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.