Web design, programming, graphics, and pretty much anything else I care about.

Restricting access to user profile

Here is a helpful little snippet to prevent a user from accessing their own profile page, or changing their password. This is useful for cases where people are using some kind of guest account, or shared account.

<?php
//implementation of hook_menu alter to change permissions to prevent users from viewing their own profile. unless they have the 'access user profiles' permission.
function ias_profilerestrict_menu_alter(&$items) {
 
$items['user/%user_uid_optional']['access callback'] = 'user_access';  
 
$items['user/%user_uid_optional']['access arguments'] = array('access user profiles');

//If you also want to deny users the ability to edit their own password and email address at /user/%uid/edit then include these lines too
 
$items['user/%user_category/edit']['access callback'] = 'user_access';
 
$items['user/%user_category/edit']['access arguments'] = array('administer users');
  }
?>