Hi there!
I want to show error messages only to users that are admins.
I know that I can do something like <?php if($is_admin):?> <?php print $messages;?> <?php endif; ?> .
But that way I would avoid all kind of messages to be shown to normal users, and I want only to hide error messages.

Could it work with something like: if($is_admin && $type = 'error'): ... ?
Thanks in advance for your help!!
Rosamunda

Comments

zbricoleur’s picture

...but you can (and should, on a production site) change the settings at admin/settings/error-reporting to write errors to the log only (not to the screen).

Rosamunda’s picture

Hi! Thanks for your anwser. I know but I like as admin to see the arreros in the screen too, but I don´t want my users to see them... :)
That´s why I thougth that I could do a little trick in the TPL.

zbricoleur’s picture

function phptemplate_status_messages($display = NULL) {
  $output = '';
  global $user;
  if ($user->roles) {
    $roles = implode("','", array_keys($user->roles));
    $is_admin = db_result(db_query("SELECT COUNT(rid) FROM {permission} WHERE rid IN ('$roles') AND perm LIKE '%access administration pages%'"));
  }
  foreach (drupal_get_messages($display) as $type => $messages) {
    if (($type == 'error' && $is_admin > 0) || $type != 'error') {
      $output .= "<div class=\"messages $type\">\n";
      if (count($messages) > 1) {
        $output .= " <ul>\n";
        foreach ($messages as $message) {
          $output .= '  <li>'. $message ."</li>\n";
        }
        $output .= " </ul>\n";
      }
      else {
        $output .= $messages[0];
      }
      $output .= "</div>\n";
    }
  }
  return $output;
}
Rosamunda’s picture

I see, not inside the TPL...
THANKS! BIG THANKS!!
Rosamunda

cj-a-min’s picture

Thanks

ErikU’s picture

This code works great but if you don't want to edit your template.php file, you can always just wrap the print $message code in a php if statement.

<?php if ($tabs): ?>
  <?php print $messages ?>
  <div class="tabs">
    <?php print render($tabs); ?>
  </div>
<?php endif; ?>

This will make sure that only people that have the permission to edit the page will be able to see the messages.