Avoid access to profiles (user/%user/view) I want to avoid access to user/%user/view, so only admins can see profiles. At first I tried with changing the permission user_view_access without any luck.

I tried to use the hook hook_menu_alter:

53 function mymenu_menu_alter(&amp;$items) {
54   $items['user'] = array(
55     'access callback' =&gt; 'user_access',                                                                                                                                                                                                  
56     'access arguments' =&gt; array('access administration pages'),                                                                                                                                                                         
57     'type' =&gt; MENU_NORMAL_ITEM,
58   );
59   $items['user/%user_uid_optional'] = array(
60     'access callback' =&gt; 'user_access',
61     'access arguments' =&gt; array('access administration pages'),
62      'type' =&gt; MENU_NORMAL_ITEM,
63   );
64   $items['user/%user/view'] = array(
65     'access callback' =&gt; 'user_edit_access',
66     'access arguments' =&gt; array('access administration pages'),
67     'type' =&gt; MENU_NORMAL_ITEM,
68   );


It doesn't work neither. Do you have any hint?
There are four problems with the code you reported:


The code is changing the menu type, when it should not do so.
The code is changing values that it should not touch, if the purpose is to only change who can access the user profiles.
user_edit_access() and user_access() expect the argument they receive to be a user object, not a string. It is wrong to set "access arguments" to array('access administration pages'), as you are doing.
Even if you would set "access arguments" to array(1), user_edit_access() allows the users to see their own user profile; if you want to avoid to show to the users their own user profile, then that function is not the function I would use as access callback.
As said by jhedstrom, it is not necessary to use code in this case, when it is enough to don't give the permission to access user profiles to those roles you don't want to be able to see any user profile. The answer I am going to give takes the assumption you don't want the users to see any user profile, including their own; in this case, removing the permission to access user profiles doesn't help, as Drupal still allows the users to see their own user profile.




function mymenu_menu_alter(&amp;$items) {
  $items['user/%user/view']['access callback'] = FALSE;
}

function mymenu_user_view_access($account) {
  return $account &amp;&amp; $account-&gt;uid &amp;&amp; user_access('administer users');
}