1

When I visit www.example.com/user, there is a page that shows the login/password and as well as a "Request New Password" tab.

How do I remove this "Request New Password" tab from the user page?

  • What are you trying to achieve? Just hide that tab or disable the functionality it provides? – Clive Dec 28 '16 at 15:09
  • Disable and hide both ways would be appreciated. I'll make the choice. Thanks! – user3236765 Dec 28 '16 at 15:10
1

The No Request New Password module is probably the easiest way to go, though you'll need to dig for the 6.x releases. This disables any request to user/password, so this path with neither be accessible directly nor display in menus/tabs/links.

Alternatively, you can put its main function into your own custom module:

 /**
  * Implementation of hook_menu_alter().
  */

 function MYMODULE_menu_alter(&$callback) {  
     $callback['user/password'] = array('access arguments' => array(FALSE));
 }
  • Hi Thanks, the code you gave above, where exactly in template.php should I place the code? Thanks again! – user3236765 Dec 28 '16 at 15:23
  • 1
    Support for alter hooks in template.php was added in Drupal 7, for Drupal 6 you'll need to put this in a custom module @user3236765 – Clive Dec 28 '16 at 15:53
  • Thanks Clive, can the module referred to above work with drupal 6? – user3236765 Dec 28 '16 at 15:55
  • @Clive Thanks, it's been a while since I dealt with D6. – choster Dec 28 '16 at 15:56
  • Me too, I had to check ;) @user3236765 yes that module should work out of the box. Nitpicking - the code in Jaypan's answer is a slightly better solution than what that module does, it will potentially save database access and some cpu cycles, plus it's conceptually the "better" way to solve the problem. It's technically possible for the implementation of user_access to change and that method to stop working, or at least start throwing warnings, but it's very unlikely given D6 isn't being actively developed – Clive Dec 28 '16 at 16:01
1

You can change the permission so the page is not accessible:

function hook_menu_alter(&$menu)
{
  $menu['user/password']['access callback'] = FALSE;
}

This code will disable the page altogether, so it's not available to anyone.

0

If you are already using a custom module (called, for example, custom_module) you can hide the user/password tab using the following code.

function custom_module_menu_alter(&$items) {
  $items['user/password']['type'] = MENU_CALLBACK;
}

This doesn't show the tab, but the path is still accessible to the users who know Drupal has that path.

To hide it and disable it, use the following code.

function custom_module_menu_alter(&$items) {
  $items['user/password']['access callback'] = FALSE;
}

Setting the access callback to FALSE, the tab will not be accessible nor visible to any user, including the user #1.

In the last hook implementation that I shown, using $items['user/password'] = array('access arguments' => array(FALSE)); is wrong since:

  • Setting the access arguments to an array containing the FALSE value is not the correct way to avoid Drupal checks the user has the permission to see the route/menu.
  • Using that code, I am literally setting the route definition to an array containing just 'access arguments' => array(FALSE) with all the consequences that could happen if there is another module that re-enables the user/password tab for the currently logged-in user, and that module has hooks invoked after the hooks of your module. (With the example code I shown, this simply happens when the other module is called destiny_change_user_password_tab.)

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.