You can also use hook_user_view($account, $view_mode, $langcode) function to handle the permission. At first you need to copy the original function as below in the template.php
function hook_user_view($account, $view_mode, $langcode) {
if (user_access('create blog content', $account)) {
$account->content['summary']['blog'] = array(
'#type' => 'user_profile_item',
'#title' => t('Blog'),
'#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => format_username($account)))))),
'#attributes' => array('class' => array('blog')),
);
}
}
Then check the current user role and the role of the user that is being visited. current user role is get by this:
global $user;
$role = $user->role;
the role of the profile is saved in the $account
variable. Check to see what exactly its syntax is using devel
module (I forgot the code syntax), If it was not there, you can get the owner of the profile id
, use user_load(id)
function to load the user then get its role.
After getting the roles, you should perform the condition at the first line of the hook function.