Notification
Notification copied to clipboard
Email templates
It would be nice to have some simple email template support, to include some reusable blocks of css and html to make messages consistent across multiple notification definitions.
Possibly useful for others, or as a basis for how/where to insert custom css into the message:
/**
* Notification: add css to html head on outgoing messages.
*/
add_filter( 'notification/carrier/email/message', function( $message, $carrier, $trigger ) {
// read .css file or whatever
$css = "body { background-color: red; }";
$html_mime = true;
if ( function_exists( 'notification_get_setting' ) ) {
$html_mime = notification_get_setting( 'notifications/email/type' ) === 'html';
}
$html_mime = apply_filters( 'notification/carrier/email/use_html_mime', $html_mime, $carrier, $trigger );
if ( ! $html_mime ) {
return $message;
}
if ( stripos( $message, '<html>' ) !== false ) {
if ( stripos( $message, '</head>' ) !== false ) {
$message = preg_replace( "{</head>}i", "<style>{$css}</style></head>", $message, 1 );
} // else malformed html ?
} else {
$message = <<<HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style> {$css} </style>
</head>
<body>
{$message}
</body>
</html>
HTML;
}
return $message;
}, 10, 3);
The email templates is a high demand extension we plan to release: https://bracketspace.com/downloads/notification-email-templates/