Skip to content

Instantly share code, notes, and snippets.

@jamiehs
Created July 7, 2015 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiehs/02816a2c31a6430ab9c3 to your computer and use it in GitHub Desktop.
Save jamiehs/02816a2c31a6430ab9c3 to your computer and use it in GitHub Desktop.
Snippet to add a smarter option to Mandrill for WordPress.
<?php
/**
* Add paragraph breaks to plain text notifications sent by Mandrill
*
* Mandrill's default option for handling this is a bit too
* agressive. This method checks the type of email, and attempts
* to detect whether or not it is HTML or not.
*
* @param array $message
* @return array Modified $message
*/
function wpmandrill_auto_add_breaks($message) {
$html = $message['html'];
$is_comment_notification = ( $message['tags']['automatic'][0] == 'wp_wp_notify_moderator' );
$is_password_reset = ( $message['tags']['automatic'][0] == 'wp_retrieve_password' );
$no_html_found = ( $html == strip_tags($html) );
// Add line breaks and links to messages that don't appear to be HTML
if ( $no_html_found || $is_comment_notification || $is_password_reset ) {
$html = wpautop($html);
$message['html'] = make_clickable($html);
}
return $message;
}
add_filter('mandrill_payload', 'wpmandrill_auto_add_breaks');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment