0

From time to time (and anytime after I run "drush cc all") my custom module with an access callback returns an 'access denied' error for Admins when they attempt to edit a user. I can solve this issue by disabling and re-enabling (any) module -- not just the one with the access callback code. If I remove this code, an admins ability to edit a user is fully and permanently restored. Here is the code in my custom module:

function cs_menu_alter(&$items) {
    $items['user/%/edit']['access callback'] = 'cs_user_edit_access';
}
function cs_user_edit_access() {
    global $user;
    if (!user_has_role(3, $user) || !user_has_role(4, $user)) {
        return FALSE;
    }
    else {
        return TRUE;
    }
}

I don't know why this code would suddenly stop working, but I don't really want to lose the functionality that this custom code supplies (most of the time).

2
  • Is this in a module file or a .inc file? Also the argument should be %user which should be able to be passed to the function without doing global user.
    – Kevin
    Commented Dec 3, 2018 at 12:49
  • Nevermind, I see that you are checking the current users role. Is there a reason why you are not using permissions?
    – Kevin
    Commented Dec 3, 2018 at 14:44

1 Answer 1

0

I was able to solve for my use case by dropping the secondary function, and just using the following code:

function cs_menu_alter(&$items) {
  $items['user/%user/edit']['access arguments'] = array('administer users');
  $items['user/%user/edit']['access callback'] = 'user_access';
}

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.