1

This question is specific to Drupal 7, and I'm pretty sure that I already know the answer to this, namely that I won't be able to do what I want, but I thought I'd pose it to you Drupal experts.

Is it possible to extend Drupal's user_access() function to provide a more complex logic for permissions? I know it is possible to create an access callback function that provides more complex logic, but I want it so that every function that calls the user_access() function will implement this new logic for determining permissions.

So, how do you extend Drupal's user_access() function to run your own functions too to check access?

0

Looking at the code there's simply no way to do this without directly hacking the user_access() function.

There are no hooks invoked and the logic is completely self-contained, aside from one call user_role_permissions(). That function just runs a database query though so there's no scope to intercept the process there.

Obviously you could write your own access function and call it from your own code, but there are 152 calls to user_access() in core files (and countless others in contributed modules) which won't be able to take advantage of it unfortunately.

1
  • That was the conclusion I had come too as well. Unfortunate. Thank you for your expertise and confirmation.
    – James
    Jul 26 '12 at 14:33
0

Despite its very generic name, user_access() is actually a simple function to determine whether the user has a given privilege. And by privilege, the documentation actually means has a role whose has been granted a single permission.

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.