WordPress alert when you are on the staging site.

Recently I accidentally overwrote my Production site when I thought I was on the staging site so after a bit of googling I came up with this solution. If you are on WordPress you can just paste this at the end of your functions.php for your theme. This could also probably be turned into a very simple plugin.

// Alert on Staging Site
// http://stackoverflow.com/questions/6522023/php-if-domain
$host = $_SERVER['HTTP_HOST'];
if ($host != 'XXXXXXXXXX.com') {
function staging_admin_error_notice()
{
$class = "error";
$message = "You are on the staging site.";
echo"<div class=\"$class\"> <h1>$message</h1></div>";
}
add_action('admin_notices', 'staging_admin_error_notice');
}