How do I remove the "users" search tab displayed on the search results page. I do not want people to search users.

-scott

Comments

VM’s picture

even if you remove the tab someone can point to yoursite.com/search/user

I believe you will have to create a custom search.tpl.php, information is available in the handbooks -> theme development section

Keeling’s picture

1. See this link here for how to strip unwanted tabs
2. Use Taxonomy Access to prevent users from pointing to yoursite.com/search/user

Good luck!

www.keelingdesign.com

skinnydog’s picture

thanks that worked great.

xurizaemon’s picture

Note that this tab only appears if you have "access user profiles" permission. You may only be seeing this tab because you're logged in as an administrator, or because the current role has been granted that permission.

This UI is added by user.module using hook_search()

himagarwal’s picture

<?php
function _phptemplate_variables($hook, $vars = array()) {

  if($hook == 'page') {
    yourthemename_removetab('address book', $vars);
    // add additional lines here to remove other tabs
  }

  return $vars;
}

function yourthemename_removetab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $vars['tabs'] = '';

  foreach($tabs as $tab) {
    if(strpos($tab, '>' . $label . '<') === FALSE) {
      $vars['tabs'] .= $tab . "\n";
    }
  }
}
?>

How to use it to remove the users tab from search? I tried copying and chaning the yourthemename to my theme name and replaced "address book" with "users" but it didn't worked? Did I missed something?

lurkerX’s picture

Thanks for the tip!

Cheers,

phpsharma’s picture

solved my issue.
sharma chelluri

ktleow’s picture

You can 'hide' the search users tab using only CSS.
display: none;

-----
http://kahthong.com - A blog, portfolio & personal site
My blog is proudly powered by Drupal

mortenson’s picture

Oh really? and wich class or id would you use?

WoozyDuck’s picture

Even tho you remove user tab, the actual page would be accessible by typing "search/user"
So if you really want to remove user search from your website, you need to disable the "user_search" function in your "user" module.
In order to do this, open user.module file and find function user_search($op = 'search', $keys = NULL) and either remove or disable it.
In this case, search will not find user's search hook and will not add any tab nor any search result for users.

jasom’s picture

After every update you must do it again. Better is some nice template.php solution:)

rohnjeynolds’s picture

I got results in Drupal 6 using hook_menu_alter(). This removes not only the tab but the Drupal path to user search, which is what I really needed. If this is bad, I'm sure someone will point out why, but I feel that this issue is best solved at the module/menu level rather than the theme level.

function mymodule_menu_alter(&$items) {
    unset($items['search/user/%menu_tail']);
}
nrackleff’s picture

I just built a little helper module using the following code as suggested above.

 function disable_user_search_menu_alter(&$items) {
    unset($items['search/user/%menu_tail']);
    unset($items['search/profile/%menu_tail']);
}

While it did remove the tabs from the search page, it did not remove the ability to search users or profiles. For example, I can still go to '/search/user/deanna' and return results with a list of users named 'deanna'.

Any ideas?

Thanks,
Nancy

ressa’s picture

Maybe you can use something like

  unset($items['search/user/%user/example']);

From here: http://drupal.org/node/483324


Try Drupal 8 at simplytest.me
mortenson’s picture

check Tab Tamer module

Weka’s picture

Using the example code at http://drupal.org/node/483324 I made a custom module to remove the Users tab from search pages. The tabs did disappear; however users are still able to access the search/user path and search for accounts.

Here is the code I used in the custom module. Did I miss something?

<?php
// $Id: custom_mod.module

/**
* @file
* Custom functions and overrides.
*/
/**
* Implementation of hook_menu_alter().
* Remember to clear the menu cache after adding/editing this function.
*/
function custom_mod_menu_alter(&$items) {
  // Removing certain local navigation tabs that are either undesired or need to be custom relocated.

  // Set these tabs to MENU_CALLBACK, so they still register the path, but just don't show the tab:
  $items['node/%node/track']['type'] = MENU_CALLBACK;
  $items['user/%user/track']['type'] = MENU_CALLBACK;
  $items['search/user']['type'] = MENU_CALLBACK;
 
  // Fully unset these tabs and their paths, don't want them at all. This breaks the path as well:
  unset($items['search/user']['type']);
}
geneticdrift’s picture

In hook_menu_alter override 'access callback'.

This way it is possible to both hide the user search tab and block access to search/user.

For example, to restrict access to search/user only to users with 'administer users' permission.
The user/autocomplete path is handled in the same way.

function mymodule_menu_alter(&$items) {
  if (isset($items['search/user/%menu_tail'])) {
    $menu_item =& $items['search/user/%menu_tail'];
 
    $menu_item['access callback'] = 'user_access';
    $menu_item['access arguments'] = array('administer users');
  }
 
  if (isset($items['user/autocomplete'])) {
    $menu_item =& $items['user/autocomplete'];
 
    $menu_item['access callback'] = 'user_access';
    $menu_item['access arguments'] = array('administer users');
  }
}

Tested in Drupal 6.16 with core search.
(It is also possible to add a specific permission, e.g. 'search users', and use that as the access argument).

sachbearbeiter’s picture

@geneticdrift - thanks - works excellent ...

gigi_igig’s picture

Thank you , it worked excellent also for me!

malc0mn’s picture

Nice solution, but I cleaned it up like so:

function mymodule_menu_alter(&$items) {
  // Add permission to user search.
  $check = array('search/user/%menu_tail', 'user/autocomplete');
  foreach ($check as $path) {
    if (isset($items[$path])) {
      $items[$path]['access callback'] = 'user_access';
      $items[$path]['access arguments'] = array('administer users');
    }
  }
}
vladsocaciu’s picture

In drupal 7 you can disable the user search module at admin/config/search/settings

hserus’s picture

/* Admin can give access to each role */

function mymodule_menu_alter(&$items){
if(isset($items['search/user/%menu_tail'])){
	$menu_item =&$items['search/user/%menu_tail'];
	
	$menu_item['access callback'] = 'user_access';
	$menu_item['access arguments'] = array('Search user');
	}
}

/* Implementation of hook_perm */

function mymodule_perm(){
	return array('Search user');
}