Show blocks only on user's own profile page

On profile pages, if the user is viewing his/her own page they see their Private message block, group block, etc. (basically all of their personal blocks), but if they are viewing a DIFFERENT user profile, I do not want them to see those details (as I don't want to see a list of my messages/groups/etc. on someone else's page).

<?php
global $user;
if (
arg(0) == 'user' && $user->uid == arg(1)){
  return
TRUE;
}
else {
  return
FALSE;
}
?>

http://www.example.com/user/uid
http://www.example.com/arg(0)/arg(1)

So basically the block is visible if the viewer's uid is the same as arg(1) meaning the viewer is viewing his/her own profile.

snippet for use in theme_user_profile

firebus - May 2, 2007 - 21:28

you can do the same thing in the profile page theme. however in theme_user_profile, $user refers to the page being viewed, not the user who is viewing.

however, you can grab the viewing user from the global scope:

if ($user->uid != $GLOBALS[user]->uid) {
  print 'show something fascinating';
}

 
 

Drupal is a registered trademark of Dries Buytaert.