Show some text only to users who don't have a particular role

Over the past few weeks I've been working away on the Nevada Boys' State website. It is a pretty cool site if I do say so myself. The delegates log in and complete things like the pre-program survey and submit legislation. Of course it is a Drupal site. Using Taxonomy Access Control pages are created for parents, staff or delegates. However parents and staff can look at the delegate pages. This is fine but there is some customization done on the page that shows the current user's email and reports that it's the "Delegate's email account".

It is a simple problem to solve and a quick trip to the Drupal site gave me the pieces to put together the following code that shows a note for anyone who logs in and views a Delegate page but doesn't have the role of Delegate. (Delegate has been changed in this code to MyRole).

<?php
global $user;
$approved_roles = array('MyRole');

if (
is_array($user->roles)) {
  if (
count(array_intersect($user->roles, $approved_roles)) > 0) {
         print
'';
  } else {
        print
'&lt;strong>You are viewing a page that is intended for MyRole but you are not logged in as a MyRole. You can view this page but please make sure a MyRole accesses this page to complete their tasks from their own account.&lt;/strong>';
}}
?>

No votes yet

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail|datadescriptor]. Example: [amazon 1590597559 thumbnail] or [amazon 1590597559 author]. Details are on the Amazon module handbook page.
  • Twitter-style @usersnames are linked to their Twitter account pages.
  • Twitter-style #hashtags are linked to search.twitter.com.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul><p> <img> <table> <tr> <td><strong><em><sup><div><fn><h1><h2><h3><h4><blockquote><img style="">
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.
  • You may insert videos with [video:URL]
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically. (Better URL filter.)
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options