Skip to content

Instantly share code, notes, and snippets.

@nickcernis
Last active January 24, 2016 21:23
Show Gist options
  • Save nickcernis/8b87ac0a875e417b304b to your computer and use it in GitHub Desktop.
Save nickcernis/8b87ac0a875e417b304b to your computer and use it in GitHub Desktop.
Fix for the wpMandrill WordPress plugin for blogs that send both plain text and HTML email
<?php
// Add to functions.php and leave the “Content” box unticked in Settings > Mandrill
// Be sure to omit the opening <?php tag when copying this code
// Add paragraph breaks to plain text notifications sent by Mandrill
add_filter('mandrill_payload', 'wpmandrill_auto_add_breaks');
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment