1

Drupal 7 /user url goes to a page that has 2 tabs Login and Request new password which is what I want for all of our users except for one. How can I NOT show the Request new password tab within the /user (login) page for one particular user ($user->name)?

1
  • Do you need to hide it or just disable it for that user?
    – mpdonadio
    Mar 29, 2013 at 1:11

2 Answers 2

4

If you just wish to hide the tab, you can do that by using the Tab Tamer module. However, the user would still be able to access the form through the URL http://<yoursite>/user/password.

If you wish to disable (along with hiding) the password tab, you can implement the hook_menu_alter().

function MODULE_menu_alter(&$items) {
  //condition to check the user
  global $user;
  if($user->id == '<USER_ID_OF_THE_USER>') { //can use $user->name as well
    $items['user/password']['access callback'] = FALSE;
  }
}
0

I found this looking for solutions to the same problem. However, this code will not work because hook_menu_alter and hook_menu only run when the menu's are rebuilt. So, the if clause will only execute when the user, most likely admin, does a cache clear, not when the targeted user is using the site.

My solution:

function MODULE_menu_alter(&$items) {
  $items['user/password']['access callback'] = 'MODULE_user_access_callback';
  $items['user/%user/edit']['access callback'] = 'MODULE_user_access_callback';
}
function MODULE_user_access_callback() {
  global $user;
  // target "guest" account or "anonymous"
  if ($user->name == 'guest' || $user->uid == 0) {
    return FALSE;
  } else {
    return TRUE;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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