Description
This collection of snippets allows site administrators to show or hide specific profile fields, depending on user permissions or on user roles.
Usage
- For use in a user profile page override
- Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the snippet into the user_profile.tpl.php file
- Tested and works with Drupal 4.5 and 4.6
- Change the div class name or the link text to suit.
Show content based on user permissions
User permissions are specified on the ADMINISTER --> ACCESS CONTROL page.
<?php if (user_access('administer users')): ?>
<div class="fields">CONTENT FOR ADMIN ONLY GOES HERE</div>
<?php endif; ?>
Show content based on user role.
In this example snippet, the content will only be displayed to users with the super admin
role type. Change the role type, DIV etc. to change the output.
<?php if (in_array('super admin',$GLOBALS['user']->roles)): ?>
<div class="fields">Super Administraator</div>
<?php endif; ?>
Show "Read User's Blog" on profile if user has permission to add blog entries.