The patch provided above works but is not quite optimal. The problem is that set_content_type() calls add_action(). If you are sending 100 emails in a loop, you do not want to call add_action 100 times (even though WP will simply replace the existing hook)
Below is my patch. How come this plugin has not been fixed yet? maximinime reported this 2 months ago and I emailed the author 1 month ago with the below patch.
diff -Naur wp-better-emails/wpbe.php wp-better-emails-krb/wpbe.php
--- wp-better-emails/wpbe.php 2013-03-18 10:33:38.944313476 -0400
+++ wp-better-emails-krb/wpbe.php 2013-03-18 10:35:22.584185730 -0400
@@ -1,6 +1,6 @@
<?php
/*
- Plugin Name: WP Better Emails
+ Plugin Name: WP Better Emails (FIXED)
Plugin URI: https://www.ads-software.com/extend/plugins/wp-better-emails/
Description: Beautify the default text/plain WP mails into fully customizable HTML emails.
Version: 0.2.4.1
@@ -38,6 +38,7 @@
var $options = array();
var $page = '';
+ var $send_as_html; //KRB
/**
* Construct function (old way)
@@ -63,6 +64,8 @@
add_filter('wp_mail_from', array($this, 'set_from_email'));
add_filter('wp_mail_content_type', array(&$this, 'set_content_type'), 100);
+ add_action('phpmailer_init', array(&$this, 'send_html')); //KRB
+
if (!is_admin())
return;
@@ -77,7 +80,7 @@
add_action('admin_head', array(&$this, 'load_wp_tiny_mce'));
if( version_compare($wp_version, '3.2', '<') && version_compare($wp_version, '3.0.6', '>') )
add_action( 'admin_print_footer_scripts', 'wp_tiny_mce_preload_dialogs');
-
+
// Filters
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'settings_link'));
add_filter('contextual_help', array(&$this, 'contextual_help'), 10, 3);
@@ -363,8 +366,10 @@
function set_content_type($content_type) {
// Only convert if the message is text/plain and the template is ok
if ($content_type == 'text/plain' && $this->check_template() === true) {
- add_action('phpmailer_init', array(&$this, 'send_html'));
+ $this->send_as_html = true; //KRB
return $content_type = 'text/html';
+ } else {
+ $this->send_as_html = false; //KRB
}
return $content_type;
}
@@ -376,16 +381,18 @@
* @param object $phpmailer
*/
function send_html($phpmailer) {
- // Set the original plain text message
- $phpmailer->AltBody = wp_specialchars_decode($phpmailer->Body, ENT_QUOTES);
- // Clean < and > around text links in WP 3.1
- $phpmailer->Body = $this->esc_textlinks($phpmailer->Body);
- // Convert line breaks & make links clickable
- $phpmailer->Body = nl2br(make_clickable($phpmailer->Body));
- // Add template to message
- $phpmailer->Body = $this->set_email_template($phpmailer->Body);
- // Replace variables in email
- $phpmailer->Body = $this->template_vars_replacement($phpmailer->Body);
+ if ( $this->send_as_html ) {
+ // Set the original plain text message
+ $phpmailer->AltBody = wp_specialchars_decode( $phpmailer->Body, ENT_QUOTES );
+ // Clean < and > around text links in WP 3.1
+ $phpmailer->Body = $this->esc_textlinks( $phpmailer->Body );
+ // Convert line breaks & make links clickable
+ $phpmailer->Body = nl2br( make_clickable( $phpmailer->Body ) );
+ // Add template to message
+ $phpmailer->Body = $this->set_email_template( $phpmailer->Body );
+ // Replace variables in email
+ $phpmailer->Body = $this->template_vars_replacement( $phpmailer->Body );
+ }
}
/**