How to show an urgent message in the WordPress admin area

How to show an urgent message in the WordPress admin area

When writing custom WordPress theme or plugins, you might want to inform users that something important needs doing, perhaps due to an upgrade. e.g. You need the user to update a setting, or check that their settings have been transposed correctly. Here is a ready to use hook to display a custom message to admins.

function showMessage($message, $errormsg = false){

if ($errormsg) {

echo ‘

‘; } else { echo ‘

‘; } 


  echo “



  $message

  
  
  
“; }
  
  
  
function showAdminMessages() { showMessage(“You need to upgrade your database as soon as possible…”, true);
  
  
  
if (user_can(‘manage_options’) { showMessage(“Hello admins!”); } }
  
  
  
add_action(‘admin_notices’, ‘showAdminMessages’);
  
  
  
→