There are two paths a user could be visiting their own page: "user" and "user/UID" where their UID matches.
There is a global variable $user that stores the currently logged in user.
So in the variable preprocessor for the template you can determine whether or not a user is on their own user page and save it to a variable that you can reference in the template file, like below.
Note the use of $variables['logged_in']
, which is an available variable as listed in the page.tpl.php documentation.
/**
* Override or insert variables into the page templates.
*
* @param $variables
* An array of variables to pass to the theme template.
*/
function THEME_NAME_preprocess_page(&$variables) {
// If we are on the 'user' page or a sub-page of it.
if (arg(0) == 'user') {
$variables['own_account'] = FALSE;
// If we are on 'user' and are logged in then we are on our own user page.
if (!arg(1) && $variables['logged_in']) {
$variables['own_account'] = TRUE;
}
// If we are on 'user/UID' then check against the current user.
else if (is_numeric(arg(1)) && !arg(2)) {
global $user;
if ($user->uid == arg(1)) {
$variables['own_account'] = TRUE;
}
}
}
}
Then you can use the variable $own_profile
in your page-user.tpl.php
template, which in this case might look something like this:
<?php if ($own_account): ?>
<div class="own-account-msg">
Here is some markup for the message a user sees when they are on their own account page.
</div>
<?php endif; ?>