You can use Disable Messages or look how they do it. Among other features you'll get a permission to specifically hide all messages of a given type from any role.
Gives a site owner options to disable specific messages shown to end
users. The core drupal message system as offered by drupal_set_message
is an excellent way for modules to send out messages to the end users.
However not all drupal site owners are keen to show all the messages
sent out by drupal core and all modules to their users. This module
gives site administrators a reasonably powerful way to filter out
messages shown to the end users.
Features
- Filter out messages that match a full text string exactly.
- Filter out messages that match a regular expression.
- Permissions to specifically hide all messages of a given type from any role.
- Disable all filtering for specific users.
- Disable all filtering for specific paths.
- Apply filtering only for specific paths.
- Debug system to get messages in the HTML without showing it to the end users.
Apart from that I found this little gem:
function MYMODULE_preprocess_status_messages(&$variables) {
// The exact message you want to filter.
$message = 'Further instructions have been sent to your e-mail address.';
if (isset($_SESSION['messages'])) {
foreach ($_SESSION['messages'] as $type => $messages) {
// Limit it to a certain type if you want to.
if ($type == 'status') {
$pos = array_search($message, $messages);
if ($pos !== FALSE) {
unset($_SESSION['messages'][$type][$pos]);
}
}
}
}
}
Source: https://api.drupal.org/comment/51793#comment-51793
Here's another alternative to filter all messages of a certain type.
/**
* Implements hook_page_build().
*/
function MYMODULE_page_build(&$page) {
$hide_types = ['status', 'error', 'warning'];
if (isset($_SESSION['messages'])) {
foreach ($_SESSION['messages'] as $type => $messages) {
if (in_array($type, $hide_types)) {
unset($_SESSION['messages'][$type]);
}
}
}
}
You could also easily get the $account = global $user
and check its roles to tighten this request if you need.
Last but not least – not recommended - you can remove or if-wrap the <?php print $messages; ?>
variable in your theme's page.tpl.php
. But editing templates for this kind of logic should be considered bad practice.