how to identify when a user is viewing their profile? I'm relatively new to Drupal and have created a module that among other things uses hook_menu() to add a link to a user navigation "my gallery" this all works well except this link appears when a user views another user's profile. So what i want to do is add some code to tell Drupal not to display this link when a user is not on their own profile.

I'm guessing I need to change the access callback from user_access to a custom callback that carries out this check. Any help would be greatly appreicated.

My code so far is the following one.

global $user;
// get name of current user
$currentUser = $user-&gt;uid;
// get profile url
$profileUrl = arg(1);
// compare usernames to determine whether the user is on their own profile.
if ($currentUser == $profileUrl) {
  // user is on their profile, display link
  $profileUrl = "i'm home";
}
else {
  $profileUrl = "away";
}

$items['user/%user/gallery'] = array(
  'title'            =&gt; $profileUrl,
  'page callback'    =&gt; 'drupal_goto',
  'page arguments'   =&gt; array('gallery'),
  'access callback'  =&gt; 'user_access',
  'access arguments' =&gt; array('access content'),
  'type'             =&gt; MENU_LOCAL_TASK,
);   

return $items;


The problem is it seems to get fixated, so if I start on the admin profile it correctly displays "I am home"; however, if I view another profile this doesn't change as it should. How can I fix this?
You can try 'title callback' attribute of hook_menu function.

$items['user/%user/gallery'] = array(
  'title callback' =&gt; 'get_title',
  'title arguments' =&gt; array(1),
  'page callback' =&gt; 'drupal_goto',
  'page arguments' =&gt; array('gallery'),
  'access callback' =&gt; 'user_access',
  'access arguments' =&gt; array('access content'),
  'type' =&gt; MENU_LOCAL_TASK,
);    


And now you can call the function

function get_title($user_id) {
  global $user;
  $currentUser = $user-&gt;uid;
  //get profile url for that you can use $user_id as user id
  $profileUrl = arg(1);
  // compare usernames to determine whether the user is on their own profile.
  if($currentUser == $profileUrl) {
    //user is on their profile, display link
    $profileUrl = "i'm home";
  }
  else {
    $profileUrl = "away";
  }
  return $profileURL;
}