I'm customizing user profile page in my Drupal 7 site. I decided to remove menu tabs on the page by modifing template.php file with following code function my_theme_preprocess_page(&$variables){ unset($variables['tabs']); }
Insted of tabs I created block in user-profile.tpl.php and moved links from tabs there `

        <?php print l(t('Edit profile'), "user/{$GLOBALS['user']->uid}/edit"); ?>
    <div class="user-profile-subscriptions">
        <?php print l(t('Subscriptions'), "user/{$GLOBALS['user']->uid}/subscriptions");?>

How can I configure permissions to display this block only whe user is viewing own profile and hide whe viewing profile of other user?

UPD: I assume this may be possible through comparing current user name user->name and user name from URL but I do not know how to extract user name from URL.

  • 1
    Get the user id using arg(1) (for any path in the form user/%). – Ben May 21 '15 at 14:16

You can use

user_access('administer users')

It returns TRUE if user have permission to edit profiles and FALSE otherwise.

| improve this answer | |
  • In my case only administrator has Administer users permission. So it does not work for users with different roles – burzakovskiy May 21 '15 at 8:52
  • Then you can define your own permission and alter the menu callback – Eugene May 21 '15 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.