wpMandrill - Version 1.33

Version Description

  • ADDED: Logging messages to trace bug where the stats don't get updated
  • FIXED: Order of preference for tags.
  • ADDED: Support for css inlining, recipient preservation, whether or not to have the view content link in your Mandrill dashboard, tracking, signing, and return-path domains, using subaccounts, per recipient metadata, pool of ips, email scheduling, and asynchronous sending in wpMandrill::mail().
  • REMOVED: The concept of 'verified domains' was completely removed from the plugin.
  • ADDED: Tracking options in the settings page
  • ADDED: New filter, mandrill_nl2br, that can be used to modify the value of the "Replace Line Feeds by
    " setting, for specific messages. Check the How-To to see how it works.
  • FIXED: Removing wrongly formatted attachments from the payload
Download this release

Release Info

Developer MC_Will
Plugin Icon wp plugin wpMandrill
Version 1.33
Comparing to
See all releases

Code changes from version 1.32 to 1.33

Files changed (4) hide show
  1. how-tos.php +25 -2
  2. lib/mandrill.class.php +11 -3
  3. readme.txt +23 -6
  4. wpmandrill.php +152 -115
how-tos.php CHANGED
@@ -3,7 +3,7 @@
3
  class wpMandrill_HowTos {
4
  static function show($section) {
5
  $section = strtolower($section);
6
- if ( !in_array($section, array('intro','auto','regular','filter','direct','regions') ) ) $section = 'auto';
7
 
8
  $title = '';
9
 
@@ -19,6 +19,9 @@ class wpMandrill_HowTos {
19
  case 'filter':
20
  $title = __('Mandrill: How to modify a certain email using the <em>mandrill_payload</em> WordPress filter.', 'wpmandrill');
21
  break;
 
 
 
22
  case 'direct':
23
  $title = __('Mandrill: How to send emails from within your plugins.', 'wpmandrill');
24
  break;
@@ -129,7 +132,27 @@ HTML;
129
  </span>
130
  ';
131
  }
132
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  static function showSectionDirect() {
134
  return '
135
  <span class="setting-description">
3
  class wpMandrill_HowTos {
4
  static function show($section) {
5
  $section = strtolower($section);
6
+ if ( !in_array($section, array('intro','auto','regular','filter', 'nl2br', 'direct','regions') ) ) $section = 'auto';
7
 
8
  $title = '';
9
 
19
  case 'filter':
20
  $title = __('Mandrill: How to modify a certain email using the <em>mandrill_payload</em> WordPress filter.', 'wpmandrill');
21
  break;
22
+ case 'nl2br':
23
+ $title = __('Mandrill: How to tell WordPress to change line feeds by BR tags in a certain email using the <em>mandrill_nl2br</em> WordPress filter.', 'wpmandrill');
24
+ break;
25
  case 'direct':
26
  $title = __('Mandrill: How to send emails from within your plugins.', 'wpmandrill');
27
  break;
132
  </span>
133
  ';
134
  }
135
+
136
+ static function showSectionNl2br() {
137
+ return '
138
+ <span class="setting-description">
139
+ <p>'.__('That\'s easy! Just do something like this:', 'wpmandrill').'</p>
140
+ <p>
141
+ <blockquote><pre>
142
+ &lt;?php
143
+ &nbsp;&nbsp;&nbsp;function forgotMyPasswordEmails($nl2br, $message) {
144
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( in_array( \'wp-retrieve_password\', $message[\'tags\'][\'automatic\'] ) ) {
145
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$nl2br = true;
146
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
147
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $nl2br;
148
+ &nbsp;&nbsp;&nbsp;}
149
+ &nbsp;&nbsp;&nbsp;add_filter( \'mandrill_nl2br\', \'forgotMyPasswordEmails\' );
150
+ ?&gt;
151
+ </pre></blockquote>
152
+ </p>
153
+ </span>
154
+ ';
155
+ }
156
  static function showSectionDirect() {
157
  return '
158
  <span class="setting-description">
lib/mandrill.class.php CHANGED
@@ -385,16 +385,24 @@ class Mandrill {
385
  * @return array|Mandrill_Exception
386
  */
387
  function messages_send($message) {
388
- return $this->request('messages/send', array('message' => $message) );
 
 
 
 
389
  }
390
-
391
  /**
392
  * @link https://mandrillapp.com/api/docs/messages.html#method=send-template
393
  *
394
  * @return array|Mandrill_Exception
395
  */
396
  function messages_send_template($template_name, $template_content, $message) {
397
- return $this->request('messages/send-template', compact('template_name', 'template_content','message') );
 
 
 
 
398
  }
399
 
400
  function http_request($url, $fields = array(), $method = 'POST') {
385
  * @return array|Mandrill_Exception
386
  */
387
  function messages_send($message) {
388
+ $async = $message['async'];
389
+ $ip_pool = $message['ip_pool'];
390
+ $send_at = $message['send_at'];
391
+
392
+ return $this->request('messages/send', array('message' => $message, 'async' => $async, 'ip_pool' => $ip_pool, 'send_at' => $send_at) );
393
  }
394
+
395
  /**
396
  * @link https://mandrillapp.com/api/docs/messages.html#method=send-template
397
  *
398
  * @return array|Mandrill_Exception
399
  */
400
  function messages_send_template($template_name, $template_content, $message) {
401
+ $async = $message['async'];
402
+ $ip_pool = $message['ip_pool'];
403
+ $send_at = $message['send_at'];
404
+
405
+ return $this->request('messages/send-template', compact('template_name', 'template_content','message', 'async', 'ip_pool', 'send_at') );
406
  }
407
 
408
  function http_request($url, $fields = array(), $method = 'POST') {
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: MC_Will
3
  Tags: mandrill, mailchimp, transactional email, email, email reliability, smtp, wp_mail, email templates
4
  Requires at least: 3.0
5
- Tested up to: 3.5.1
6
  Stable tag: trunk
7
  License: GPLv2
8
 
@@ -10,12 +10,10 @@ The wpMandrill plugin sends emails that are generated by WordPress through Mandr
10
 
11
  == Description ==
12
 
13
- This plugin uses [Mandrill API](http://mandrillapp.com/api/docs/) to send outgoing emails from your Wordpress installation. It replaces the wp_mail function included with WordPress.
14
 
15
  Emails are tracked and automatically tagged for statistics within the Mandrill Dashboard. You can also add general tags to every email sent, as well as particular tags based on selected emails defined by your requirements.
16
 
17
- You can send certain types of attachments (image/*, text/* and application/pdf).
18
-
19
  You can also use your own templates that have been added to your MailChimp account and shared with your Mandrill account.
20
 
21
  There are a few levels of integrations between your WordPress installation and this plugin:
@@ -23,7 +21,6 @@ There are a few levels of integrations between your WordPress installation and t
23
  1. The simplest option: Install it, configure it, and wpMandrill will start sending your emails through Mandrill.
24
  1. If you need to fine tune certain emails, you can change any email by creating a filter for the **mandrill_payload** hook.
25
  1. For further customization, we've exposed a function that allows you to send emails from within your plugins, instead of the regular wp_mail function: **wpMandrill::mail**
26
- 1. If you need Mandrill Powers, we've included a full-featured class in the file lib/mandrill.class.php, where you'll find every call that can be done through the Mandrill API.
27
 
28
  This plugin is currently released as **beta** for early adopter evaluation and finalizing of the initial feature set.
29
 
@@ -59,7 +56,18 @@ $message['force_native'] = true;
59
 
60
  = My emails are broken and show weird CSS code =
61
 
62
- In version 1.09, we added a setting that allows you to tell the plugin if you want to replace your line feeds by <br/>. Try playing with that switch. If it works for certain emails doesn't for others, then you should customize the payload sent to Mandrill using the **mandrill_payload** plugin.
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  = Is there any way to check what's going on? =
65
 
@@ -99,6 +107,15 @@ If your account has more than 20 senders registered or more than 40 tags used, t
99
  4. Dashboard widget Settings
100
 
101
  == Changelog ==
 
 
 
 
 
 
 
 
 
102
  = 1.32 =
103
  * FIXED: Reordering constructors of Mandrill class to prevent the "Redefining already defined constructor" message
104
  * UPDATE: Favoring self:: instead of wpMandrill::
2
  Contributors: MC_Will
3
  Tags: mandrill, mailchimp, transactional email, email, email reliability, smtp, wp_mail, email templates
4
  Requires at least: 3.0
5
+ Tested up to: 3.8
6
  Stable tag: trunk
7
  License: GPLv2
8
 
10
 
11
  == Description ==
12
 
13
+ This plugin uses [Mandrill API](http://mandrillapp.com/api/docs/) to send outgoing emails, with or without attachments, from your Wordpress installation. It replaces the wp_mail function included with WordPress.
14
 
15
  Emails are tracked and automatically tagged for statistics within the Mandrill Dashboard. You can also add general tags to every email sent, as well as particular tags based on selected emails defined by your requirements.
16
 
 
 
17
  You can also use your own templates that have been added to your MailChimp account and shared with your Mandrill account.
18
 
19
  There are a few levels of integrations between your WordPress installation and this plugin:
21
  1. The simplest option: Install it, configure it, and wpMandrill will start sending your emails through Mandrill.
22
  1. If you need to fine tune certain emails, you can change any email by creating a filter for the **mandrill_payload** hook.
23
  1. For further customization, we've exposed a function that allows you to send emails from within your plugins, instead of the regular wp_mail function: **wpMandrill::mail**
 
24
 
25
  This plugin is currently released as **beta** for early adopter evaluation and finalizing of the initial feature set.
26
 
56
 
57
  = My emails are broken and show weird CSS code =
58
 
59
+ In version 1.09, we added a setting that allows you to tell the plugin if you want to replace your line feeds by <br/>. Try playing with that switch.
60
+
61
+ If it works for certain emails but doesn't work for others, you might want to modify this setting using the **mandrill_nl2br** filter. For example, if you don't want to use this filter for the "forgot password" emails, add something like this to your theme's functions.php file:
62
+
63
+ function my_function($nl2br, $message) {
64
+ if ( in_array('wp_retrieve_password', $message['tags']['automatic']) ) {
65
+ $nl2br = false;
66
+ }
67
+ return $nl2br;
68
+ }
69
+ add_filter('mandrill_nl2br', 'my_function');
70
+
71
 
72
  = Is there any way to check what's going on? =
73
 
107
  4. Dashboard widget Settings
108
 
109
  == Changelog ==
110
+ = 1.33 =
111
+ * ADDED: Logging messages to trace bug where the stats don't get updated
112
+ * FIXED: Order of preference for tags.
113
+ * ADDED: Support for css inlining, recipient preservation, whether or not to have the view content link in your Mandrill dashboard, tracking, signing, and return-path domains, using subaccounts, per recipient metadata, pool of ips, email scheduling, and asynchronous sending in wpMandrill::mail().
114
+ * REMOVED: The concept of 'verified domains' was completely removed from the plugin.
115
+ * ADDED: Tracking options in the settings page
116
+ * ADDED: New filter, mandrill_nl2br, that can be used to modify the value of the "Replace Line Feeds by <br>" setting, for specific messages. Check the How-To to see how it works.
117
+ * FIXED: Removing wrongly formatted attachments from the payload
118
+
119
  = 1.32 =
120
  * FIXED: Reordering constructors of Mandrill class to prevent the "Redefining already defined constructor" message
121
  * UPDATE: Favoring self:: instead of wpMandrill::
wpmandrill.php CHANGED
@@ -5,7 +5,7 @@ Description: wpMandrill sends emails, generated by WordPress using Mandrill.
5
  Author: Mandrill
6
  Author URI: http://mandrillapp.com/
7
  Plugin URI: http://connect.mailchimp.com/integrations/wpmandrill
8
- Version: 1.32
9
  Text Domain: wpmandrill
10
  */
11
  /* Copyright 2012 MailChimp (email : will@mailchimp.com )
@@ -105,6 +105,11 @@ class wpMandrill {
105
  add_settings_field('from-email', __('FROM Email', 'wpmandrill'), array(__CLASS__, 'askFromEmail'), 'wpmandrill', 'wpmandrill-addresses');
106
  add_settings_field('reply-to', __('Reply-To Email', 'wpmandrill'), array(__CLASS__, 'askReplyTo'), 'wpmandrill', 'wpmandrill-addresses');
107
 
 
 
 
 
 
108
  // Template
109
  add_settings_section('wpmandrill-templates', __('General Design', 'wpmandrill'), '__return_false', 'wpmandrill');
110
  add_settings_field('template', __('Template', 'wpmandrill'), array(__CLASS__, 'askTemplate'), 'wpmandrill', 'wpmandrill-templates');
@@ -130,7 +135,7 @@ class wpMandrill {
130
  add_action('wpm_update_stats', array(__CLASS__,'saveProcessedStats'));
131
 
132
  if ( !wp_next_scheduled( 'wpm_update_stats' ) ) {
133
- wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'wpm_update_stats');
134
  }
135
 
136
  register_deactivation_hook( __FILE__, array(__CLASS__,'deactivate') );
@@ -214,15 +219,13 @@ class wpMandrill {
214
 
215
  $ok = array();
216
  $ok['account'] = ( !self::isConnected() ) ? ' class="missing"' : '';
217
- $ok['domains'] = ( $ok['account'] != '' || !count(self::ListVerifiedDomains()) ) ? ' class="missing"' : '';
218
  $ok['email'] = ( $ok['account'] != '' || !self::getFromEmail() ) ? ' class="missing"' : '';
219
 
220
  $requirements = '';
221
- if ($ok['account'] . $ok['domains'] . $ok['email'] != '' ) {
222
  $requirements = '<p>' . __('To use this plugin you will need:', 'wpmandrill') . '</p>'
223
  . '<ol>'
224
  . '<li'.$ok['account'].'>'. __('Your Mandrill account.', 'wpmandrill') . '</li>'
225
- . '<li'.$ok['domains'].'>' . __('At least one domain defined in your Mandrill account.', 'wpmandrill') . '</li>'
226
  . '<li'.$ok['email'].'>' . __('A valid sender email address.', 'wpmandrill') . '</li>'
227
  . '</ol>';
228
  }
@@ -231,7 +234,7 @@ class wpMandrill {
231
  . '<p>' . __('Once you have properly configured the settings, the plugin will take care of all the emails sent through your WordPress installation.', 'wpmandrill').'</p>'
232
  . '<p>' . __('However, if you need to customize any part of the email before sending, you can do so by using the WordPress filter <strong>mandrill_payload</strong>.', 'wpmandrill').'</p>'
233
  . '<p>' . __('This filter has the same structure as Mandrill\'s API call <a href="http://mandrillapp.com/api/docs/messages.html#method=send" target="_blank">/messages/send</a>, except that it can have one additional parameter when the email is based on a template. The parameter is called "<em>template</em>", which is an associative array of two elements (the first element, a string whose key is "<em>template_name</em>", and a second parameter whose key is "<em>template_content</em>". Its value is an array with the same structure of the parameter "<em>template_content</em>" in the call <a href="http://mandrillapp.com/api/docs/messages.html#method=send-template" target="_blank">/messages/send-template</a>.)', 'wpmandrill').'</p>'
234
- . '<p>' . __('Note that if you\'re sending additional headers in your emails, the only valid headers are <em>From:</em>, <em>Reply-To:</em>, and <em>X-*:</em>. <em>Bcc:</em> is also valid, but Mandrill will send the blind carbon copy to only the first address, and the remaining will be silently discarted.', 'wpmandrill').'</p>'
235
  . '<p>' . __('Also note that if any error occurs while sending the email, the plugin will try to send the message again using the native WordPress mailing capabilities.', 'wpmandrill').'</p>'
236
  . '<p>' . __('Confirm that any change you made to the payload is in line with the <a href="http://mandrillapp.com/api/docs/" target="_blank">Mandrill\'s API\'s documentation</a>. Also, the <em>X-*:</em> headers, must be in line with the <a href="http://help.mandrill.com/forums/20689696-smtp-integration" target="_blank">SMTP API documentation</a>. By using this plugin, you agree that you and your website will adhere to <a href="http://www.mandrill.com/terms/" target="_blank">Mandrill\'s Terms of Use</a> and <a href="http://mandrill.com/privacy/" target="_blank">Privacy Policy</a>.', 'wpmandrill').'</p>'
237
  . '<p>' . __('if you have any question about Mandrill or this plugin, visit the <a href="http://help.mandrill.com/" target="_blank">Mandrill\'s Support Center</a>.', 'wpmandrill').'</p>'
@@ -373,6 +376,7 @@ class wpMandrill {
373
  echo wpMandrill_HowTos::show('auto');
374
  echo wpMandrill_HowTos::show('regular');
375
  echo wpMandrill_HowTos::show('filter');
 
376
  echo wpMandrill_HowTos::show('direct');
377
 
378
  ?>
@@ -390,7 +394,7 @@ class wpMandrill {
390
  static function formValidate($input) {
391
  self::getConnected();
392
 
393
- if ( !empty($input['from_domain']) && ( empty($input['from_username']) || !self::isDomainEnabled($input['from_domain']) ) ) {
394
  add_settings_error(
395
  'wpmandrill',
396
  'from-email',
@@ -400,7 +404,6 @@ class wpMandrill {
400
 
401
 
402
  $input['from_username'] = '';
403
- $input['from_domain'] = '';
404
  }
405
 
406
  // Preserving the Reply-To address
@@ -429,9 +432,8 @@ jQuery(document).bind( 'ready', function() {
429
 
430
  /******************************************************************
431
  ** Helper functions
432
- *******************************************************************
433
-
434
-
435
  /**
436
  * @return mixed
437
  */
@@ -498,21 +500,17 @@ jQuery(document).bind( 'ready', function() {
498
  return self::getOption('from_username');
499
  }
500
 
501
- /**
502
- * @return string|boolean
503
- */
504
- static function getFromDomain() {
505
-
506
- return self::getOption('from_domain');
507
- }
508
-
509
  /**
510
  * @return string|boolean
511
  */
512
  static function getFromEmail() {
513
- if ( self::getOption('from_username') && self::getOption('from_domain') ) {
514
- return self::getOption('from_username') . '@' . self::getOption('from_domain');
 
 
 
515
  }
 
516
  }
517
 
518
  /**
@@ -547,6 +545,22 @@ jQuery(document).bind( 'ready', function() {
547
  return self::getOption('nl2br');
548
  }
549
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
550
  /**
551
  * @return string|boolean
552
  */
@@ -600,42 +614,6 @@ jQuery(document).bind( 'ready', function() {
600
 
601
  return ( isset( $_GET['page'] ) && $_GET['page'] == 'wpmandrill' . $sufix);
602
  }
603
-
604
- /**
605
- * Return the list of the verified domains for the current users. Or false.
606
- *
607
- * @return array|bool
608
- */
609
- static function listVerifiedDomains() {
610
- $domains = array();
611
-
612
- self::getConnected();
613
- if ( !self::isConnected() ) return $domains;
614
-
615
- try {
616
- $domains = self::$mandrill->senders_domains();
617
- if ( !empty($domains) ) $domains = array_values($domains);
618
- } catch ( Exception $e ) {}
619
-
620
- return $domains;
621
- }
622
-
623
-
624
- /**
625
- * @return boolean
626
- */
627
- static function isDomainEnabled($domain) {
628
- if ( empty($domain) ) return false;
629
-
630
- $domains = self::ListVerifiedDomains();
631
- foreach ( $domains as $curdomain ) {
632
- if ( strtolower($curdomain['domain']) == strtolower($domain) ) {
633
- return true;
634
- }
635
- }
636
-
637
- return false;
638
- }
639
 
640
  /**
641
  * @return boolean
@@ -674,7 +652,6 @@ jQuery(document).bind( 'ready', function() {
674
  <ol>
675
  <li>That your web server has either cURL installed or is able to use fsock*() functions (if you don\'t know what this means, you may want to check with your hosting provider for more details);</li>
676
  <li>That your API key is active (this can be viewed on the <a href="https://mandrillapp.com/settings/index" target="_blank">SMTP & API Credentials</a> page in your Mandrill account);</li>
677
- <li>That the domain name you\'re using above is listed in the <a href="https://mandrillapp.com/settings/sending-domains" target="_blank">Sending Domains</a> for your Mandrill account.</li>
678
  </ol>', 'wpmandrill') . $test->get_error_message());
679
 
680
  return array_map('wp_strip_all_tags', $input);
@@ -726,31 +703,11 @@ jQuery(document).bind( 'ready', function() {
726
  echo '<div class="inside">';
727
 
728
  $from_username = self::getFromUsername();
729
- $from_domain = self::getFromDomain();
730
  $from_email = self::getFromEmail();
731
 
732
- $domains = self::ListVerifiedDomains();
733
- if ( !count($domains) ) {
734
-
735
- _e('No domains found.', 'wpmandrill');
736
-
737
- if ( $from_email ) {
738
- self::setOption('from_username', false);
739
- self::setOption('from_domain', false);
740
- self::setOption('from_email', false);
741
- }
742
-
743
- echo '</div>';
744
- return;
745
- }
746
-
747
  ?><?php _e('This address will be used as the sender of the outgoing emails:', 'wpmandrill'); ?><br />
748
- <input id="from_username" name="wpmandrill[from_username]" type="text" value="<?php esc_attr_e($from_username);?>" style="text-align:right;width:100px">@
749
- <select id="from_domain" name="wpmandrill[from_domain]"><?php
750
- foreach( $domains as $curdomain ) {
751
- ?><option value="<?php esc_attr_e($curdomain['domain']); ?>" <?php selected($curdomain['domain'], $from_domain); ?>><?php esc_html_e($curdomain['domain']); ?></option><?php
752
- }
753
- ?></select><br/><span class="setting-description"><small><em><?php _e('If you need to add a new domain, please visit your <a href="https://mandrillapp.com/settings/sending-domains" target="_blank">Mandrill Settings</a>', 'wpmandrill'); ?></em></small></span><?php
754
 
755
  echo '</div>';
756
  }
@@ -761,7 +718,7 @@ jQuery(document).bind( 'ready', function() {
761
  $from_name = self::getFromName();
762
 
763
  ?><?php _e('Name the recipients will see in their email clients:', 'wpmandrill'); ?><br />
764
- <input name="wpmandrill[from_name]" type="text" value="<?php esc_attr_e($from_name); ?>">
765
  <?php
766
 
767
  echo '</div>';
@@ -805,7 +762,7 @@ jQuery(document).bind( 'ready', function() {
805
  }
806
 
807
  ?><?php _e('Select the template to use:', 'wpmandrill'); ?><br />
808
- <select name="wpmandrill[template]">
809
  <option value="">-None-</option><?php
810
  foreach( $templates as $curtemplate ) {
811
  ?><option value="<?php esc_attr_e($curtemplate['name']); ?>" <?php selected($curtemplate['name'], $template); ?>><?php esc_html_e($curtemplate['name']); ?></option><?php
@@ -814,14 +771,37 @@ jQuery(document).bind( 'ready', function() {
814
 
815
  echo '</div>';
816
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
817
  static function asknl2br() {
818
  $nl2br = self::getnl2br();
819
  if ( $nl2br == '' ) $nl2br = 0;
820
  ?>
821
  <div class="inside">
822
  <?php _e('Replace all line feeds ("\n") by &lt;br/&gt; in the message body?', 'wpmandrill'); ?>
823
- <input name="wpmandrill[nl2br]" type="checkbox" <?php echo checked($nl2br,1); ?> value='1' /><br/>
824
- <span class="setting-description"><em><?php _e('<small>If you are sending HTML emails already keep this setting deactivated.<br/>But if you are sending text only emails (WordPress default) this option might help your emails look better.</small>', 'wpmandrill'); ?></em></span>
 
 
 
 
825
  </div><?php
826
  }
827
 
@@ -831,7 +811,7 @@ jQuery(document).bind( 'ready', function() {
831
  $tags = self::getTags();
832
 
833
  ?><?php _e('If there are tags that you want appended to every call, list them here, one per line:', 'wpmandrill'); ?><br />
834
- <textarea name="wpmandrill[tags]" cols="25" rows="3"><?php echo $tags; ?></textarea><br/>
835
  <span class="setting-description"><small><em><?php _e('Also keep in mind that you can add or remove tags using the <em><a href="#" onclick="jQuery(\'a#contextual-help-link\').trigger(\'click\');return false;">mandrill_payload</a></em> WordPress filter.', 'wpmandrill'); ?></em></small></span>
836
  <?php
837
 
@@ -862,7 +842,7 @@ jQuery(document).bind( 'ready', function() {
862
  */
863
  static function getTestEmailOption($field) {
864
 
865
- $email = get_option('wpmandrill' . '-test');
866
 
867
  if( isset( $email[$field] ) )
868
  return $email[$field];
@@ -880,7 +860,10 @@ jQuery(document).bind( 'ready', function() {
880
  */
881
  static function getRawStatistics() {
882
  self::getConnected();
883
- if ( !self::isConnected() ) return array();
 
 
 
884
 
885
  $stats = array();
886
  $final = array();
@@ -890,16 +873,21 @@ jQuery(document).bind( 'ready', function() {
890
  $data = array();
891
  $container = self::$mandrill->tags_list();
892
  foreach ( $container as $tag ) {
893
- $data[$tag['tag']] = self::$mandrill->tags_info($tag['tag']);
894
- if ( count($data) >= 40 ) break;
 
 
895
  }
896
  $stats['tags'] = $data;
897
 
898
  $data = array();
899
  $container = self::$mandrill->senders_list();
900
  foreach ( $container as $sender ) {
901
- $data[$sender['address']] = self::$mandrill->senders_info($sender['address']);
902
- if ( count($data) >= 20 ) break;
 
 
 
903
  }
904
  $stats['senders'] = $data;
905
 
@@ -941,8 +929,11 @@ jQuery(document).bind( 'ready', function() {
941
 
942
  static function getProcessedStats() {
943
  $stats = self::getRawStatistics();
944
- if ( empty($stats) ) return $stats;
945
-
 
 
 
946
  $graph_data = array();
947
  for ( $i = 0; $i < 24; $i++ ) {
948
  $graph_data['hourly']['delivered'][ sprintf('"%02s"',$i) ] = 0;
@@ -1023,12 +1014,15 @@ jQuery(document).bind( 'ready', function() {
1023
  */
1024
  static function getCurrentStats() {
1025
 
1026
- $stats = get_transient('wpmandrill'.'-stats');
1027
  if ( empty($stats) ) {
1028
- $stats = get_option('wpmandrill'.'-stats');
1029
-
1030
- if ( empty($stats) ) $stats = self::saveProcessedStats();
1031
 
 
 
 
 
1032
  }
1033
 
1034
  return $stats;
@@ -1042,8 +1036,10 @@ jQuery(document).bind( 'ready', function() {
1042
  static function saveProcessedStats() {
1043
  $stats = self::GetProcessedStats();
1044
  if ( !empty($stats) ) {
1045
- set_transient('wpmandrill'.'-stats', $stats, 60 * 60);
1046
- update_option('wpmandrill'.'-stats', $stats);
 
 
1047
  }
1048
 
1049
  return $stats;
@@ -1601,7 +1597,19 @@ JS;
1601
  * @param array $merge_vars Per-recipient merge variables, which override global merge variables with the same name.
1602
  * @param array $google_analytics_domains An array of strings indicating for which any matching URLs will automatically have Google Analytics parameters appended to their query string automatically.
1603
  * @param array|string $google_analytics_campaign Optional string indicating the value to set for the utm_campaign tracking parameter. If this isn't provided the email's from address will be used instead.
1604
- * @param array $meta_data Associative array of user metadata. Mandrill will store this metadata and make it available for retrieval. In addition, you can select up to 10 metadata fields to index and make searchable using the Mandrill search api.
 
 
 
 
 
 
 
 
 
 
 
 
1605
  * @return array|WP_Error
1606
  */
1607
  static function mail( $to, $subject, $html, $headers = '', $attachments = array(),
@@ -1609,8 +1617,8 @@ JS;
1609
  $from_name = '',
1610
  $from_email = '',
1611
  $template_name = '',
1612
- $track_opens = true,
1613
- $track_clicks = true,
1614
  $url_strip_qs = false,
1615
  $merge = true,
1616
  $global_merge_vars = array(),
@@ -1618,9 +1626,22 @@ JS;
1618
  $google_analytics_domains = array(),
1619
  $google_analytics_campaign = array(),
1620
  $meta_data = array(),
1621
- $important = false
1622
-
 
 
 
 
 
 
 
 
 
 
1623
  ) {
 
 
 
1624
  try {
1625
  extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'html', 'headers', 'attachments' ) ) );
1626
  $message = compact('html', 'subject', 'from_name', 'from_email', 'to', 'headers', 'attachments',
@@ -1631,7 +1652,18 @@ JS;
1631
  'google_analytics_domains',
1632
  'google_analytics_campaign',
1633
  'meta_data',
1634
- 'important'
 
 
 
 
 
 
 
 
 
 
 
1635
  );
1636
  return self::sendEmail($message, $tags, $template_name, $track_opens, $track_clicks);
1637
  } catch ( Exception $e ) {
@@ -1716,7 +1748,7 @@ JS;
1716
  break;
1717
 
1718
  case 'bcc':
1719
- // TODO: Mandrill's API only accept one BCC address. Other addresses will be silently discarted
1720
  $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
1721
 
1722
  $message['bcc_address'] = $bcc[0];
@@ -1746,7 +1778,7 @@ JS;
1746
  $message['headers']['Reply-To'] = trim(self::getReplyTo());
1747
  }
1748
 
1749
- // Checking the To: field
1750
  if( !is_array($message['to']) ) $message['to'] = explode(',', $message['to']);
1751
 
1752
  $processed_to = array();
@@ -1759,18 +1791,20 @@ JS;
1759
  }
1760
  $message['to'] = $processed_to;
1761
 
1762
- // Checking the From: field
1763
  if ( empty($message['from_email']) ) $message['from_email'] = self::getFromEmail();
1764
  if ( empty($message['from_name'] ) ) $message['from_name'] = self::getFromName();
1765
 
1766
- // Checking the tags.
1767
  $message['tags'] = self::findTags($tags);
1768
 
1769
- // Checking the attachments
1770
  if ( !empty($message['attachments']) ) {
1771
  $message['attachments'] = self::processAttachments($message['attachments']);
1772
  if ( is_wp_error($message['attachments']) ) {
1773
  throw new Exception('Invalid attachment (check http://eepurl.com/nXMa1 for supported file types).');
 
 
1774
  }
1775
  }
1776
  // Default values for other parameters
@@ -1779,7 +1813,9 @@ JS;
1779
  $message['track_clicks']= $track_clicks;
1780
 
1781
  // Supporting editable sections: Common transformations for the HTML part
1782
- if ( self::getnl2br() == 1 ) {
 
 
1783
  if ( is_array($message['html']) ) {
1784
  foreach ($message['html'] as &$value){
1785
  $value['content'] = preg_replace('#<(https?://[^*]+)>#', '$1', $value['content']);
@@ -1820,11 +1856,12 @@ JS;
1820
  }
1821
  }
1822
 
1823
- // Letting the user filter/change the message payload
1824
  $message['from_email'] = apply_filters('wp_mail_from', $message['from_email']);
1825
  $message['from_name'] = apply_filters('wp_mail_from_name', $message['from_name']);
1826
  $message = apply_filters('mandrill_payload', $message);
1827
 
 
1828
  if ( isset($message['force_native']) && $message['force_native'] ) throw new Exception('Manually falling back to native wp_mail()');
1829
 
1830
  // Setting the tags property correctly to be received by the Mandrill's API
@@ -1832,7 +1869,7 @@ JS;
1832
  if ( !is_array($message['tags']['general']) ) $message['tags']['general'] = array();
1833
  if ( !is_array($message['tags']['automatic']) ) $message['tags']['automatic'] = array();
1834
 
1835
- $message['tags'] = array_merge( $message['tags']['user'], $message['tags']['general'], $message['tags']['automatic'] );
1836
 
1837
  // Sending the message
1838
  if ( empty($message['template']) || empty($message['template']['name']) || empty($message['template']['content']) ) {
@@ -1851,8 +1888,8 @@ JS;
1851
  }
1852
  }
1853
 
1854
- static function processAttachments($attachments) {
1855
- if ( !is_array($attachments) )
1856
  $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
1857
 
1858
  foreach ( $attachments as $index => $attachment ) {
5
  Author: Mandrill
6
  Author URI: http://mandrillapp.com/
7
  Plugin URI: http://connect.mailchimp.com/integrations/wpmandrill
8
+ Version: 1.33
9
  Text Domain: wpmandrill
10
  */
11
  /* Copyright 2012 MailChimp (email : will@mailchimp.com )
105
  add_settings_field('from-email', __('FROM Email', 'wpmandrill'), array(__CLASS__, 'askFromEmail'), 'wpmandrill', 'wpmandrill-addresses');
106
  add_settings_field('reply-to', __('Reply-To Email', 'wpmandrill'), array(__CLASS__, 'askReplyTo'), 'wpmandrill', 'wpmandrill-addresses');
107
 
108
+ // Tracking
109
+ add_settings_section('wpmandrill-tracking', __('Tracking', 'wpmandrill'), '__return_false', 'wpmandrill');
110
+ add_settings_field('trackopens', __('Track opens', 'wpmandrill'), array(__CLASS__, 'askTrackOpens'), 'wpmandrill', 'wpmandrill-tracking');
111
+ add_settings_field('trackclicks', __('Track clicks', 'wpmandrill'), array(__CLASS__, 'askTrackClicks'), 'wpmandrill', 'wpmandrill-tracking');
112
+
113
  // Template
114
  add_settings_section('wpmandrill-templates', __('General Design', 'wpmandrill'), '__return_false', 'wpmandrill');
115
  add_settings_field('template', __('Template', 'wpmandrill'), array(__CLASS__, 'askTemplate'), 'wpmandrill', 'wpmandrill-templates');
135
  add_action('wpm_update_stats', array(__CLASS__,'saveProcessedStats'));
136
 
137
  if ( !wp_next_scheduled( 'wpm_update_stats' ) ) {
138
+ wp_schedule_event( current_time( 'timestamp', 1 ), 'hourly', 'wpm_update_stats');
139
  }
140
 
141
  register_deactivation_hook( __FILE__, array(__CLASS__,'deactivate') );
219
 
220
  $ok = array();
221
  $ok['account'] = ( !self::isConnected() ) ? ' class="missing"' : '';
 
222
  $ok['email'] = ( $ok['account'] != '' || !self::getFromEmail() ) ? ' class="missing"' : '';
223
 
224
  $requirements = '';
225
+ if ($ok['account'] . $ok['email'] != '' ) {
226
  $requirements = '<p>' . __('To use this plugin you will need:', 'wpmandrill') . '</p>'
227
  . '<ol>'
228
  . '<li'.$ok['account'].'>'. __('Your Mandrill account.', 'wpmandrill') . '</li>'
 
229
  . '<li'.$ok['email'].'>' . __('A valid sender email address.', 'wpmandrill') . '</li>'
230
  . '</ol>';
231
  }
234
  . '<p>' . __('Once you have properly configured the settings, the plugin will take care of all the emails sent through your WordPress installation.', 'wpmandrill').'</p>'
235
  . '<p>' . __('However, if you need to customize any part of the email before sending, you can do so by using the WordPress filter <strong>mandrill_payload</strong>.', 'wpmandrill').'</p>'
236
  . '<p>' . __('This filter has the same structure as Mandrill\'s API call <a href="http://mandrillapp.com/api/docs/messages.html#method=send" target="_blank">/messages/send</a>, except that it can have one additional parameter when the email is based on a template. The parameter is called "<em>template</em>", which is an associative array of two elements (the first element, a string whose key is "<em>template_name</em>", and a second parameter whose key is "<em>template_content</em>". Its value is an array with the same structure of the parameter "<em>template_content</em>" in the call <a href="http://mandrillapp.com/api/docs/messages.html#method=send-template" target="_blank">/messages/send-template</a>.)', 'wpmandrill').'</p>'
237
+ . '<p>' . __('Note that if you\'re sending additional headers in your emails, the only valid headers are <em>From:</em>, <em>Reply-To:</em>, and <em>X-*:</em>. <em>Bcc:</em> is also valid, but Mandrill will send the blind carbon copy to only the first address, and the remaining will be silently discarded.', 'wpmandrill').'</p>'
238
  . '<p>' . __('Also note that if any error occurs while sending the email, the plugin will try to send the message again using the native WordPress mailing capabilities.', 'wpmandrill').'</p>'
239
  . '<p>' . __('Confirm that any change you made to the payload is in line with the <a href="http://mandrillapp.com/api/docs/" target="_blank">Mandrill\'s API\'s documentation</a>. Also, the <em>X-*:</em> headers, must be in line with the <a href="http://help.mandrill.com/forums/20689696-smtp-integration" target="_blank">SMTP API documentation</a>. By using this plugin, you agree that you and your website will adhere to <a href="http://www.mandrill.com/terms/" target="_blank">Mandrill\'s Terms of Use</a> and <a href="http://mandrill.com/privacy/" target="_blank">Privacy Policy</a>.', 'wpmandrill').'</p>'
240
  . '<p>' . __('if you have any question about Mandrill or this plugin, visit the <a href="http://help.mandrill.com/" target="_blank">Mandrill\'s Support Center</a>.', 'wpmandrill').'</p>'
376
  echo wpMandrill_HowTos::show('auto');
377
  echo wpMandrill_HowTos::show('regular');
378
  echo wpMandrill_HowTos::show('filter');
379
+ echo wpMandrill_HowTos::show('nl2br');
380
  echo wpMandrill_HowTos::show('direct');
381
 
382
  ?>
394
  static function formValidate($input) {
395
  self::getConnected();
396
 
397
+ if ( empty($input['from_username']) ) {
398
  add_settings_error(
399
  'wpmandrill',
400
  'from-email',
404
 
405
 
406
  $input['from_username'] = '';
 
407
  }
408
 
409
  // Preserving the Reply-To address
432
 
433
  /******************************************************************
434
  ** Helper functions
435
+ *******************************************************************/
436
+
 
437
  /**
438
  * @return mixed
439
  */
500
  return self::getOption('from_username');
501
  }
502
 
 
 
 
 
 
 
 
 
503
  /**
504
  * @return string|boolean
505
  */
506
  static function getFromEmail() {
507
+ $from_email = self::getOption('from_username');
508
+ if ( !empty($from_email) && !strpos($from_email, '@') ) {
509
+ $from_email = self::getOption('from_username') . '@' . self::getOption('from_domain');
510
+ self::setOption('from_username', $from_email);
511
+ self::setOption('from_domain', null);
512
  }
513
+ return $from_email;
514
  }
515
 
516
  /**
545
  return self::getOption('nl2br');
546
  }
547
 
548
+ /**
549
+ * @return string|boolean
550
+ */
551
+ static function getTrackOpens() {
552
+
553
+ return self::getOption('trackopens');
554
+ }
555
+
556
+ /**
557
+ * @return string|boolean
558
+ */
559
+ static function getTrackClicks() {
560
+
561
+ return self::getOption('trackclicks');
562
+ }
563
+
564
  /**
565
  * @return string|boolean
566
  */
614
 
615
  return ( isset( $_GET['page'] ) && $_GET['page'] == 'wpmandrill' . $sufix);
616
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617
 
618
  /**
619
  * @return boolean
652
  <ol>
653
  <li>That your web server has either cURL installed or is able to use fsock*() functions (if you don\'t know what this means, you may want to check with your hosting provider for more details);</li>
654
  <li>That your API key is active (this can be viewed on the <a href="https://mandrillapp.com/settings/index" target="_blank">SMTP & API Credentials</a> page in your Mandrill account);</li>
 
655
  </ol>', 'wpmandrill') . $test->get_error_message());
656
 
657
  return array_map('wp_strip_all_tags', $input);
703
  echo '<div class="inside">';
704
 
705
  $from_username = self::getFromUsername();
 
706
  $from_email = self::getFromEmail();
707
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
708
  ?><?php _e('This address will be used as the sender of the outgoing emails:', 'wpmandrill'); ?><br />
709
+ <input id="from_username" name="wpmandrill[from_username]" type="text" value="<?php esc_attr_e($from_username);?>">
710
+ <br/><?php
 
 
 
 
711
 
712
  echo '</div>';
713
  }
718
  $from_name = self::getFromName();
719
 
720
  ?><?php _e('Name the recipients will see in their email clients:', 'wpmandrill'); ?><br />
721
+ <input id="from_name" name="wpmandrill[from_name]" type="text" value="<?php esc_attr_e($from_name); ?>">
722
  <?php
723
 
724
  echo '</div>';
762
  }
763
 
764
  ?><?php _e('Select the template to use:', 'wpmandrill'); ?><br />
765
+ <select id="template" name="wpmandrill[template]">
766
  <option value="">-None-</option><?php
767
  foreach( $templates as $curtemplate ) {
768
  ?><option value="<?php esc_attr_e($curtemplate['name']); ?>" <?php selected($curtemplate['name'], $template); ?>><?php esc_html_e($curtemplate['name']); ?></option><?php
771
 
772
  echo '</div>';
773
  }
774
+
775
+ static function askTrackOpens() {
776
+ $track = self::getTrackOpens();
777
+ if ( $track == '' ) $track = 0;
778
+ ?>
779
+ <div class="inside">
780
+ <input id="trackopens" name="wpmandrill[trackopens]" type="checkbox" <?php echo checked($track,1); ?> value='1' /><br/>
781
+ </div><?php
782
+ }
783
+
784
+ static function askTrackClicks() {
785
+ $track = self::getTrackClicks();
786
+ if ( $track == '' ) $track = 0;
787
+ ?>
788
+ <div class="inside">
789
+ <input id="trackclicks" name="wpmandrill[trackclicks]" type="checkbox" <?php echo checked($track,1); ?> value='1' /><br/>
790
+ </div><?php
791
+ }
792
+
793
  static function asknl2br() {
794
  $nl2br = self::getnl2br();
795
  if ( $nl2br == '' ) $nl2br = 0;
796
  ?>
797
  <div class="inside">
798
  <?php _e('Replace all line feeds ("\n") by &lt;br/&gt; in the message body?', 'wpmandrill'); ?>
799
+ <input id="nl2br" name="wpmandrill[nl2br]" type="checkbox" <?php echo checked($nl2br,1); ?> value='1' /><br/>
800
+ <span class="setting-description">
801
+ <em>
802
+ <?php _e('<small>If you are sending HTML emails already keep this setting deactivated.<br/>But if you are sending text only emails (WordPress default) this option might help your emails look better.</small>', 'wpmandrill'); ?><br/>
803
+ <?php _e('<small>You can change the value of this setting on the fly by using the <strong><a href="#" onclick="jQuery(\'a#contextual-help-link\').trigger(\'click\');return false;">wpmandrill_nl2br</a></strong> filter.</small>', 'wpmandrill'); ?>
804
+ </em></span>
805
  </div><?php
806
  }
807
 
811
  $tags = self::getTags();
812
 
813
  ?><?php _e('If there are tags that you want appended to every call, list them here, one per line:', 'wpmandrill'); ?><br />
814
+ <textarea id="tags" name="wpmandrill[tags]" cols="25" rows="3"><?php echo $tags; ?></textarea><br/>
815
  <span class="setting-description"><small><em><?php _e('Also keep in mind that you can add or remove tags using the <em><a href="#" onclick="jQuery(\'a#contextual-help-link\').trigger(\'click\');return false;">mandrill_payload</a></em> WordPress filter.', 'wpmandrill'); ?></em></small></span>
816
  <?php
817
 
842
  */
843
  static function getTestEmailOption($field) {
844
 
845
+ $email = get_option('wpmandrill-test');
846
 
847
  if( isset( $email[$field] ) )
848
  return $email[$field];
860
  */
861
  static function getRawStatistics() {
862
  self::getConnected();
863
+ if ( !self::isConnected() ) {
864
+ error_log( date('Y-m-d H:i:s') . " wpMandrill::getRawStatistics: Not Connected to Mandrill \n" );
865
+ return array();
866
+ }
867
 
868
  $stats = array();
869
  $final = array();
873
  $data = array();
874
  $container = self::$mandrill->tags_list();
875
  foreach ( $container as $tag ) {
876
+ try {
877
+ $data[$tag['tag']] = self::$mandrill->tags_info($tag['tag']);
878
+ if ( count($data) >= 40 ) break;
879
+ } catch ( Exception $e ) {}
880
  }
881
  $stats['tags'] = $data;
882
 
883
  $data = array();
884
  $container = self::$mandrill->senders_list();
885
  foreach ( $container as $sender ) {
886
+ try {
887
+ $sender_info_data = self::$mandrill->senders_info($sender['address']);
888
+ $data[$sender['address']] = $sender_info_data;
889
+ if ( count($data) >= 20 ) break;
890
+ } catch ( Exception $e ) {}
891
  }
892
  $stats['senders'] = $data;
893
 
929
 
930
  static function getProcessedStats() {
931
  $stats = self::getRawStatistics();
932
+ if ( empty($stats) ) {
933
+ error_log( date('Y-m-d H:i:s') . " wpMandrill::getProcessedStats (Empty Response from ::getRawStatistics)\n" );
934
+ return $stats;
935
+ }
936
+
937
  $graph_data = array();
938
  for ( $i = 0; $i < 24; $i++ ) {
939
  $graph_data['hourly']['delivered'][ sprintf('"%02s"',$i) ] = 0;
1014
  */
1015
  static function getCurrentStats() {
1016
 
1017
+ $stats = get_transient('wpmandrill-stats');
1018
  if ( empty($stats) ) {
1019
+ error_log( date('Y-m-d H:i:s') . " wpMandrill::getCurrentStats (Empty Transient. Getting persistent copy)\n" );
1020
+ $stats = get_option('wpmandrill-stats');
 
1021
 
1022
+ if ( empty($stats) ) {
1023
+ error_log( date('Y-m-d H:i:s') . " wpMandrill::getCurrentStats (Empty persistent copy. Getting data from Mandrill)\n" );
1024
+ $stats = self::saveProcessedStats();
1025
+ }
1026
  }
1027
 
1028
  return $stats;
1036
  static function saveProcessedStats() {
1037
  $stats = self::GetProcessedStats();
1038
  if ( !empty($stats) ) {
1039
+ set_transient('wpmandrill-stats', $stats, 60 * 60);
1040
+ update_option('wpmandrill-stats', $stats);
1041
+ } else {
1042
+ error_log( date('Y-m-d H:i:s') . " wpMandrill::saveProcessedStats (Empty Response from ::GetProcessedStats)\n" );
1043
  }
1044
 
1045
  return $stats;
1597
  * @param array $merge_vars Per-recipient merge variables, which override global merge variables with the same name.
1598
  * @param array $google_analytics_domains An array of strings indicating for which any matching URLs will automatically have Google Analytics parameters appended to their query string automatically.
1599
  * @param array|string $google_analytics_campaign Optional string indicating the value to set for the utm_campaign tracking parameter. If this isn't provided the email's from address will be used instead.
1600
+ * @param array $meta_data Associative array of user metadata. Mandrill will store this metadata and make it available for retrieval. In addition, you can select up to 10 metadata fields to index and make searchable using the Mandrill search api.
1601
+ * @param boolean $important Set the important flag to true for the current email
1602
+ * @param boolean $inline_css whether or not to automatically inline all CSS styles provided in the message HTML - only for HTML documents less than 256KB in size
1603
+ * @param boolean $preserve_recipients whether or not to expose all recipients in to "To" header for each email
1604
+ * @param boolean $view_content_link set to false to remove content logging for sensitive emails
1605
+ * @param string $tracking_domain a custom domain to use for tracking opens and clicks instead of mandrillapp.com
1606
+ * @param string $signing_domain a custom domain to use for SPF/DKIM signing instead of mandrill (for "via" or "on behalf of" in email clients)
1607
+ * @param string $return_path_domain a custom domain to use for the messages's return-path
1608
+ * @param string $subaccount the unique id of a subaccount for this message - must already exist or will fail with an error
1609
+ * @param array $recipient_metadata Per-recipient metadata that will override the global values specified in the metadata parameter.
1610
+ * @param string $ip_pool the name of the dedicated ip pool that should be used to send the message. If you do not have any dedicated IPs, this parameter has no effect. If you specify a pool that does not exist, your default pool will be used instead.
1611
+ * @param string $send_at when this message should be sent as a UTC timestamp in YYYY-MM-DD HH:MM:SS format. Read more about it at https://mandrillapp.com/api/docs/messages.JSON.html#method=send
1612
+ * @param boolean $async enable a background sending mode that is optimized for bulk sending. Read more about it at https://mandrillapp.com/api/docs/messages.JSON.html#method=send
1613
  * @return array|WP_Error
1614
  */
1615
  static function mail( $to, $subject, $html, $headers = '', $attachments = array(),
1617
  $from_name = '',
1618
  $from_email = '',
1619
  $template_name = '',
1620
+ $track_opens = null,
1621
+ $track_clicks = null,
1622
  $url_strip_qs = false,
1623
  $merge = true,
1624
  $global_merge_vars = array(),
1626
  $google_analytics_domains = array(),
1627
  $google_analytics_campaign = array(),
1628
  $meta_data = array(),
1629
+ $important = false,
1630
+ $inline_css = null,
1631
+ $preserve_recipients=null,
1632
+ $view_content_link=null,
1633
+ $tracking_domain=null,
1634
+ $signing_domain=null,
1635
+ $return_path_domain=null,
1636
+ $subaccount=null,
1637
+ $recipient_metadata=null,
1638
+ $ip_pool=null,
1639
+ $send_at=null,
1640
+ $async=null
1641
  ) {
1642
+ if ( $track_opens === null ) $track_opens = self::getTrackOpens();
1643
+ if ( $track_clicks === null ) $track_clicks = self::getTrackClicks();
1644
+
1645
  try {
1646
  extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'html', 'headers', 'attachments' ) ) );
1647
  $message = compact('html', 'subject', 'from_name', 'from_email', 'to', 'headers', 'attachments',
1652
  'google_analytics_domains',
1653
  'google_analytics_campaign',
1654
  'meta_data',
1655
+ 'important',
1656
+ 'inline_css',
1657
+ 'preserve_recipients',
1658
+ 'view_content_link',
1659
+ 'tracking_domain',
1660
+ 'signing_domain',
1661
+ 'return_path_domain',
1662
+ 'subaccount',
1663
+ 'recipient_metadata',
1664
+ 'ip_pool',
1665
+ 'send_at',
1666
+ 'async'
1667
  );
1668
  return self::sendEmail($message, $tags, $template_name, $track_opens, $track_clicks);
1669
  } catch ( Exception $e ) {
1748
  break;
1749
 
1750
  case 'bcc':
1751
+ // TODO: Mandrill's API only accept one BCC address. Other addresses will be silently discarded
1752
  $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
1753
 
1754
  $message['bcc_address'] = $bcc[0];
1778
  $message['headers']['Reply-To'] = trim(self::getReplyTo());
1779
  }
1780
 
1781
+ // Checking To: field
1782
  if( !is_array($message['to']) ) $message['to'] = explode(',', $message['to']);
1783
 
1784
  $processed_to = array();
1791
  }
1792
  $message['to'] = $processed_to;
1793
 
1794
+ // Checking From: field
1795
  if ( empty($message['from_email']) ) $message['from_email'] = self::getFromEmail();
1796
  if ( empty($message['from_name'] ) ) $message['from_name'] = self::getFromName();
1797
 
1798
+ // Checking tags.
1799
  $message['tags'] = self::findTags($tags);
1800
 
1801
+ // Checking attachments
1802
  if ( !empty($message['attachments']) ) {
1803
  $message['attachments'] = self::processAttachments($message['attachments']);
1804
  if ( is_wp_error($message['attachments']) ) {
1805
  throw new Exception('Invalid attachment (check http://eepurl.com/nXMa1 for supported file types).');
1806
+ } elseif ( !is_array($message['attachments']) ) { // some plugins return this value malformed.
1807
+ unset($message['attachments']);
1808
  }
1809
  }
1810
  // Default values for other parameters
1813
  $message['track_clicks']= $track_clicks;
1814
 
1815
  // Supporting editable sections: Common transformations for the HTML part
1816
+ $nl2br = self::getnl2br() == 1;
1817
+ $nl2br = apply_filters('mandrill_nl2br', $nl2br, $message);
1818
+ if ( $nl2br ) {
1819
  if ( is_array($message['html']) ) {
1820
  foreach ($message['html'] as &$value){
1821
  $value['content'] = preg_replace('#<(https?://[^*]+)>#', '$1', $value['content']);
1856
  }
1857
  }
1858
 
1859
+ // Letting user to filter/change the message payload
1860
  $message['from_email'] = apply_filters('wp_mail_from', $message['from_email']);
1861
  $message['from_name'] = apply_filters('wp_mail_from_name', $message['from_name']);
1862
  $message = apply_filters('mandrill_payload', $message);
1863
 
1864
+ // if user doesn't want to process this email by wp_mandrill, so be it.
1865
  if ( isset($message['force_native']) && $message['force_native'] ) throw new Exception('Manually falling back to native wp_mail()');
1866
 
1867
  // Setting the tags property correctly to be received by the Mandrill's API
1869
  if ( !is_array($message['tags']['general']) ) $message['tags']['general'] = array();
1870
  if ( !is_array($message['tags']['automatic']) ) $message['tags']['automatic'] = array();
1871
 
1872
+ $message['tags'] = array_merge( $message['tags']['general'], $message['tags']['automatic'], $message['tags']['user'] );
1873
 
1874
  // Sending the message
1875
  if ( empty($message['template']) || empty($message['template']['name']) || empty($message['template']['content']) ) {
1888
  }
1889
  }
1890
 
1891
+ static function processAttachments($attachments = array()) {
1892
+ if ( !is_array($attachments) && $attachments )
1893
  $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
1894
 
1895
  foreach ( $attachments as $index => $attachment ) {