72048172 by Jeff Balicki

mandrill update

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent aef5a431
Showing 35 changed files with 589 additions and 459 deletions
![Send Emails with Mandrill](https://ps.w.org/send-emails-with-mandrill/assets/banner-772x250.jpg)
# Send Emails with Mandrill
This is a fork of the official wpMandrill plugin for Wordpress, since it is no longer being actively supported. We encourage any developers to contribute to making this plugin better as we are actively maintaining this repository for the community's benefit.
Our plugin can be downloaded for free from the WordPress repository here:
https://wordpress.org/plugins/send-emails-with-mandrill/
Original wpMandrill plugin can be found here:
https://wordpress.org/plugins/wpmandrill/
Please help us gain visibility on this plugin by giving us a five-star rating on the WordPress plugin page here:
https://wordpress.org/support/plugin/send-emails-with-mandrill/reviews/#new-post .
# For developers contributing to this repository
For those of you forking this repository, please submit any pull requests to the `develop` branch. `develop` acts as the stable pre-release branch of the plugin. When new versions are released, `develop` will be merged into `master` where the code will then be tagged with the release's version number.
When submitting fixes to issues or new features/bug fixes, please make sure to branch and submit pull requests for each individually so we can effectively QA each one for accurately.
Also, thank you! We need developers like you to help us make this a great plugin for the whole WordPress community.
---
##### Miller Media offers maintenance, design and custom development for WordPress as a service. If you need help with your site, don't hestiate to visit the [Miller Media website](https://www.millermedia.io) or contact us at [support@miller-media.com](mailto:support@miller-media.com)
......@@ -64,5 +64,10 @@
max-width: 90% !important;
margin-top:15px;
}
.stuffbox h3 { cursor: default !important; padding: 3px 3px 3px 10px; }
.stuffbox h3, .stuffbox h2 { cursor: default !important; padding: 3px 3px 3px 10px; }
.stuffbox div.inside { padding-bottom: 10px;}
.stuffbox table.form-table { margin: 3px 3px 3px 10px; width: auto; }
.stuffbox h2 { text-decoration: underline; }
.stuffbox span.settings_sub_header {padding: 0px 10px; }
\ No newline at end of file
......
......@@ -18,8 +18,8 @@ JSON.stringify = JSON.stringify || function (obj) {
}
};
jQuery(document).bind( 'ready', function() {
jQuery('#filter,#display').bind('change keyup', function() {
jQuery( function() {
jQuery('#filter,#display').on('change keyup', function() {
if ( jQuery("#filter option:selected").val() == 'none' ) {
var display = 'block';
......@@ -30,7 +30,7 @@ jQuery(document).bind( 'ready', function() {
jQuery('#all_time').css('display',display);
showStats();
});
jQuery('.columns-prefs, #collapse-button').bind('click', function () {
jQuery('.columns-prefs, #collapse-button').on('click', function () {
redrawDashboardWidget();
});
......
......@@ -259,14 +259,6 @@ msgstr "No tienes suficiente permisología para acceder a esta página."
msgid "Send Test"
msgstr "Enviar Prueba"
#: wpmandrill.php:313
msgid "Latest from Mandrill..."
msgstr "Lo último de Mandrill..."
#: wpmandrill.php:327
msgid "News from MailChimp..."
msgstr "Noticias de MailChimp"
#: wpmandrill.php:356
msgid "Mandrill How-Tos"
msgstr "Mandrill: ¿Cómo hago?"
......
......@@ -255,14 +255,6 @@ msgstr ""
msgid "Send Email"
msgstr ""
#: wpmandrill.php:295
msgid "Latest from Mandrill..."
msgstr ""
#: wpmandrill.php:309
msgid "News from MailChimp..."
msgstr ""
#: wpmandrill.php:336
msgid "Mandrill How-Tos"
msgstr ""
......
......@@ -96,8 +96,17 @@ class Mandrill {
if( 200 == $response_code ) {
return $body;
} else {
error_log("wpMandrill Error: Error {$body['code']}: {$body['message']}");
throw new Mandrill_Exception( "wpMandrill Error: {$body['code']}: {$body['message']}", $response_code);
if( !is_array( $body ) ) {
$code = 'Unknown';
$message = 'Unknown';
} else {
$code = 'Unknown' ? !array_key_exists('code', $body) : $body['code'];
$message = 'Unknown' ? !array_key_exists('message', $body) : $body['message'];
}
error_log("wpMandrill Error: Error {$code}: {$message}");
throw new Mandrill_Exception("wpMandrill Error: {$code}: {$message}", $response_code);
}
}
......@@ -292,36 +301,6 @@ class Mandrill {
}
/**
* @link https://mandrillapp.com/api/docs/urls.html#method=list
*
* @return array|Mandrill_Exception
*/
function urls_list() {
return $this->request('urls/list');
}
/**
* @link https://mandrillapp.com/api/docs/urls.html#method=time-series
*
* @return array|Mandrill_Exception
*/
function urls_time_series($name) {
return $this->request('urls/time-series', array('name' => $name) );
}
/**
* @link https://mandrillapp.com/api/docs/urls.html#method=search
*
* @return array|Mandrill_Exception
*/
function urls_search($q) {
return $this->request('urls/search', array('q' => $q) );
}
/**
* @link https://mandrillapp.com/api/docs/webhooks.html#method=add
*
* @return array|Mandrill_Exception
......@@ -428,9 +407,7 @@ class Mandrill {
if( function_exists('curl_init') && function_exists('curl_exec') ) {
if( !ini_get('safe_mode') ){
set_time_limit(2 * 60);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
......@@ -508,7 +485,6 @@ class Mandrill {
list($headers, $response) = explode("\r\n\r\n", $response, 2);
if(ini_get("magic_quotes_runtime")) $response = stripslashes($response);
$info = array('http_code' => 200);
} else {
ob_end_clean();
......@@ -539,17 +515,16 @@ class Mandrill {
if ( !function_exists('set_magic_quotes') ) {
function set_magic_quotes($value) { return true;}
}
// if (strnatcmp(phpversion(),'6') >= 0) {
// $magic_quotes = get_magic_quotes_runtime();
// set_magic_quotes_runtime(0);
// }
if ( !function_exists('get_magic_quotes_runtime') ) {
function get_magic_quotes_runtime() { return false; }
}
if ( !function_exists('set_magic_quotes_runtime') ) {
function set_magic_quotes_runtime($value) { return true; }
}
$file_buffer = file_get_contents($path);
$file_buffer = chunk_split(base64_encode($file_buffer), 76, "\n");
// if (strnatcmp(phpversion(),'6') >= 0) set_magic_quotes_runtime($magic_quotes);
$mime_type = '';
if ( function_exists('finfo_open') && function_exists('finfo_file') ) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
......
<?php
class pluginActivation
{
function __construct()
{
add_action('admin_init', array($this, 'check_version'));
if (!self::compatible_version()) {
return;
}
}
static function activation_check()
{
if (!self::compatible_version()) {
deactivate_plugins(SEWM_BASE);
wp_die(__('Send Emails with Mandrill requires PHP 5.6 or higher. Please upgrade your version of PHP to activate.', 'send-emails-with-mandrill'));
}
}
function check_version()
{
if (!self::compatible_version()) {
if (is_plugin_active(SEWM_BASE)) {
deactivate_plugins(SEWM_BASE);
add_action('admin_notices', array($this, 'disabled_notice'));
if (isset($_GET['activate'])) {
unset($_GET['activate']);
}
}
}
}
function disabled_notice()
{
echo '<div class="notice notice-error is-dismissible"><p>' . esc_html__('Send Emails with Mandrill requires PHP 5.6 or higher. Please upgrade your version of PHP to activate.', 'send-emails-with-mandrill') . '</p></div>';
}
static function compatible_version()
{
if (version_compare(PHP_VERSION, '5.6', '<'))
return false;
// Add sanity checks for other version requirements here
return true;
}
}
global $pluginCheck;
$pluginCheck = new pluginActivation();
register_activation_hook(__FILE__, array('pluginActivation', 'activation_check'));
\ No newline at end of file
<?php
/*
Plugin Name: wpMandrill
Description: wpMandrill sends emails, generated by WordPress using Mandrill.
Author: Mandrill
Author URI: http://mandrillapp.com/
Plugin URI: http://connect.mailchimp.com/integrations/transactional-emails-from-wordpress
Version: 1.33
Text Domain: wpmandrill
*/
/* Copyright 2012 MailChimp (email : will@mailchimp.com )
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation using version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
wpMandrill::on_load();
/* Attach native mail function */
add_action( 'wp_mail_native', array( 'wpMandrill', 'wp_mail_native' ), 10, 5 );
class wpMandrill {
const DEBUG = false;
......@@ -43,17 +19,16 @@ class wpMandrill {
add_action('admin_init', array(__CLASS__, 'adminInit'));
add_action('admin_menu', array(__CLASS__, 'adminMenu'));
add_filter('contextual_help', array(__CLASS__, 'showContextualHelp'), 10, 3);
add_action('admin_print_footer_scripts', array(__CLASS__,'openContextualHelp'));
add_action('wp_ajax_get_mandrill_stats', array(__CLASS__,'getAjaxStats'));
add_action('wp_ajax_get_dashboard_widget_stats', array(__CLASS__,'showDashboardWidget'));
add_action('admin_post_sewm_fetch_new', array(__CLASS__, 'fetchNewDashboardData') );
load_plugin_textdomain('wpmandrill', false, dirname( plugin_basename( __FILE__ ) ).'/lang');
if( function_exists('wp_mail') ) {
self::$conflict = true;
add_action('admin_notices', array(__CLASS__, 'adminNotices'));
return;
}
......@@ -62,18 +37,11 @@ class wpMandrill {
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
try {
$sent = wpMandrill::mail( $to, $subject, $message, $headers, $attachments );
if ( is_wp_error($sent)
|| !isset($sent[0]['status'])
|| ($sent[0]['status'] != 'sent' && $sent[0]['status'] != 'queued') ) {
return wpMandrill::wp_mail_native( $to, $subject, $message, $headers, $attachments );
}
return true;
$response = wpMandrill::mail( $to, $subject, $message, $headers, $attachments );
return wpMandrill::evaluate_response( $response );
} catch ( Exception $e ) {
return wpMandrill::wp_mail_native( $to, $subject, $message, $headers, $attachments );
error_log( 'Mandrill error: ' . $e->getMessage() );
do_action( 'wp_mail_native', $to, $subject, $message, $headers, $attachments );
}
}
}
......@@ -81,6 +49,31 @@ class wpMandrill {
}
/**
* Evaluate response from Mandrill API.
*
* @param WP_Error|array
*/
static function evaluate_response( $response ) {
if ( is_wp_error( $response ) )
throw new Exception( $response->get_error_message() );
if ( !isset( $response[0]['status'] ) )
throw new Exception( 'Email status was not provided in response.' );
if (
'rejected' === $response[0]['status']
&& isset( $response[0]['reject_reason'] )
&& 'hard-bounce' !== $response[0]['reject_reason'] # Exclude hard bounces (email address doesn't exist).
)
throw new Exception( 'Email was rejected due to the following reason: ' . $response[0]['reject_reason'] . '.' );
if ( !in_array( $response[0]['status'], array( 'sent', 'queued' ) ) )
throw new Exception( 'Email was not sent or queued. Response: ' . json_encode( $response ) );
return true;
}
/**
* Sets up options page and sections.
*/
static function adminInit() {
......@@ -104,20 +97,24 @@ class wpMandrill {
add_settings_field('from-name', __('FROM Name', 'wpmandrill'), array(__CLASS__, 'askFromName'), 'wpmandrill', 'wpmandrill-addresses');
add_settings_field('from-email', __('FROM Email', 'wpmandrill'), array(__CLASS__, 'askFromEmail'), 'wpmandrill', 'wpmandrill-addresses');
add_settings_field('reply-to', __('Reply-To Email', 'wpmandrill'), array(__CLASS__, 'askReplyTo'), 'wpmandrill', 'wpmandrill-addresses');
add_settings_field('subaccount', __('Sub Account', 'wpmandrill'), array(__CLASS__, 'askSubAccount'), 'wpmandrill', 'wpmandrill-addresses');
// Tracking
add_settings_section('wpmandrill-tracking', __('Tracking', 'wpmandrill'), '__return_false', 'wpmandrill');
add_settings_field('trackopens', __('Track opens', 'wpmandrill'), array(__CLASS__, 'askTrackOpens'), 'wpmandrill', 'wpmandrill-tracking');
add_settings_field('trackclicks', __('Track clicks', 'wpmandrill'), array(__CLASS__, 'askTrackClicks'), 'wpmandrill', 'wpmandrill-tracking');
// Template
// General Design
add_settings_section('wpmandrill-templates', __('General Design', 'wpmandrill'), '__return_false', 'wpmandrill');
add_settings_field('template', __('Template', 'wpmandrill'), array(__CLASS__, 'askTemplate'), 'wpmandrill', 'wpmandrill-templates');
add_settings_field('nl2br', __('Content', 'wpmandrill'), array(__CLASS__, 'asknl2br'), 'wpmandrill', 'wpmandrill-templates');
if( self::isWooCommerceActive() )
add_settings_field('nl2br-woocommerce', __('WooCommerce Fix', 'wpmandrill'), array(__CLASS__, 'asknl2brWooCommerce'), 'wpmandrill', 'wpmandrill-templates');
// Tags
add_settings_section('wpmandrill-tags', __('General Tags', 'wpmandrill'), '__return_false', 'wpmandrill');
add_settings_field('tags', __('&nbsp;', 'wpmandrill'), array(__CLASS__, 'askTags'), 'wpmandrill', 'wpmandrill-tags');
add_settings_field('tags', __('Tags', 'wpmandrill'), array(__CLASS__, 'askTags'), 'wpmandrill', 'wpmandrill-tags');
if ( self::isConfigured() ) {
// Email Test
......@@ -129,6 +126,16 @@ class wpMandrill {
add_settings_field('email-message', __('Message', 'wpmandrill'), array(__CLASS__, 'askTestEmailMessage'), 'wpmandrill-test', 'mandrill-email-test');
}
// Misc. Plugin Settings
add_settings_section('wpmandrill-misc', __('Miscellaneous', 'wpmandrill'), function(){ echo "<span class='settings_sub_header'>Settings for WordPress plugin. Does not affect email delivery functionality or design.</span>"; }, 'wpmandrill');
add_settings_field('hide_dashboard_widget', __('Hide WP Dashboard Widget', 'wpmandrill'), array(__CLASS__, 'hideDashboardWidget'), 'wpmandrill', 'wpmandrill-misc');
}
// Fix for WooCommerce
if( self::getnl2brWooCommerce() ) {
add_action( 'woocommerce_email', function() {
add_filter( 'mandrill_nl2br', '__return_false' );
}, 10, 1 );
}
// Activate the cron job that will update the stats
......@@ -157,8 +164,9 @@ class wpMandrill {
'wpmandrill',
array(__CLASS__,'showOptionsPage')
);
add_action( 'load-'.self::$settings, array(__CLASS__,'showContextualHelp'));
if( self::isConfigured() ) {
if( self::isConfigured() && apply_filters( 'wpmandrill_enable_reports', true ) ) {
if (current_user_can('manage_options')) self::$report = add_dashboard_page(
__('Mandrill Reports', 'wpmandrill'),
__('Mandrill Reports', 'wpmandrill'),
......@@ -167,9 +175,9 @@ class wpMandrill {
array(__CLASS__,'showReportPage')
);
if ( self::isPluginPage('-reports') ) {
wp_register_script('flot', plugins_url('/js/flot/jquery.flot.js', __FILE__), array('jquery'), null, true);
wp_register_script('flotstack', plugins_url('/js/flot/jquery.flot.stack.js', __FILE__), array('flot'), null, true);
wp_register_script('flotresize', plugins_url('/js/flot/jquery.flot.resize.js', __FILE__), array('flot'), null, true);
wp_register_script('flot', SEWM_URL . 'js/flot/jquery.flot.js', array('jquery'), SEWM_VERSION, true);
wp_register_script('flotstack', SEWM_URL . 'js/flot/jquery.flot.stack.js', array('flot'), SEWM_VERSION, true);
wp_register_script('flotresize', SEWM_URL . 'js/flot/jquery.flot.resize.js', array('flot'), SEWM_VERSION, true);
wp_enqueue_script('flot');
wp_enqueue_script('flotstack');
wp_enqueue_script('flotresize');
......@@ -177,9 +185,9 @@ class wpMandrill {
}
}
wp_register_style( 'mandrill_stylesheet', plugins_url('/css/mandrill.css', __FILE__) );
wp_register_style( 'mandrill_stylesheet', SEWM_URL . 'css/mandrill.css', array(), SEWM_VERSION );
wp_enqueue_style( 'mandrill_stylesheet' );
wp_register_script('mandrill', plugins_url('/js/mandrill.js', __FILE__), array(), null, true);
wp_register_script('mandrill', SEWM_URL . 'js/mandrill.js', array(), SEWM_VERSION, true);
wp_enqueue_script('mandrill');
}
......@@ -205,7 +213,7 @@ class wpMandrill {
static function showAdminEnqueueScripts($hook_suffix) {
if( $hook_suffix == self::$report && self::isConnected() ) {
wp_register_script('mandrill-report-script', plugins_url("js/mandrill.js", __FILE__), array('flot'), null, true);
wp_register_script('mandrill-report-script', SEWM_URL . "js/mandrill.js", array('flot'), null, true);
wp_enqueue_script('mandrill-report-script');
}
}
......@@ -213,8 +221,8 @@ class wpMandrill {
/**
* Generates source of contextual help panel.
*/
static function showContextualHelp($contextual_help, $screen_id, $screen) {
if ($screen_id == self::$settings) {
static function showContextualHelp() {
$screen = get_current_screen();
self::getConnected();
$ok = array();
......@@ -230,7 +238,7 @@ class wpMandrill {
. '</ol>';
}
return $requirements
$requirements = $requirements
. '<p>' . __('Once you have properly configured the settings, the plugin will take care of all the emails sent through your WordPress installation.', 'wpmandrill').'</p>'
. '<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>'
. '<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>'
......@@ -239,26 +247,33 @@ class wpMandrill {
. '<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>'
. '<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>'
;
}
return $contextual_help;
$screen->add_help_tab( array(
'id' => 'tab1',
'title' => __('Setup'),
'content' => '<p>' . __( $requirements) . '</p>',
) );
}
/**
* Adds link to settings page in list of plugins
*/
static function showPluginActionLinks($actions, $plugin_file) {
static $plugin;
if (!isset($plugin))
$plugin = plugin_basename(__FILE__);
// The code below no longer returns the current filename; @todo to update this to non-hard coded values
// static $plugin;
//
// if (!isset($plugin))
// $plugin = plugin_basename(__FILE__);
if ($plugin == $plugin_file) {
$plugin = 'send-emails-with-mandrill/wpmandrill.php';
$settings = array('settings' => '<a href="options-general.php?page=wpmandrill">' . __('Settings', 'wpmandrill') . '</a>');
if ($plugin == $plugin_file) {
$settings = array('settings' => '<a href="'.admin_url("/options-general.php?page=wpmandrill").'">' . __('Settings', 'wpmandrill') . '</a>');
self::getConnected();
if ( self::isConnected() ) {
$report = array('report' => '<a href="index.php?page=wpmandrill-reports">' . __('Reports', 'wpmandrill') . '</a>');
$report = array('report' => '<a href="'.self::getReportsDashboardURL().'">' . __('Reports', 'wpmandrill') . '</a>');
$actions = array_merge($settings, $actions, $report);
} else {
$actions = array_merge($settings, $actions);
......@@ -284,8 +299,8 @@ class wpMandrill {
self::getConnected();
?>
<div class="wrap">
<div class="icon32" style="background: url('<?php echo plugins_url('images/mandrill-head-icon.png',__FILE__); ?>');"><br /></div>
<div class="wrap">
<div class="icon32" style="background: url('<?php echo SEWM_URL . 'images/mandrill-head-icon.png'; ?>');"><br /></div>
<h2><?php _e('Mandrill Settings', 'wpmandrill'); ?> <small><a href="options-general.php?page=<?php echo 'wpmandrill'; ?>&show=how-tos">view how-tos</a></small></h2>
<div style="float: left;width: 70%;">
......@@ -312,53 +327,7 @@ class wpMandrill {
<?php } ?>
</div>
<div style="float: left;width: 20%;">
<?php
$rss = fetch_feed('http://blog.mandrill.com/feeds/all.atom.xml');
$maxitems = 0;
if (!is_wp_error( $rss ) ) {
$maxitems = $rss->get_item_quantity(5);
$rss_items = $rss->get_items(0, $maxitems);
}
if ( $maxitems > 0 ) {
?>
<div class="mcnews mandrill">
<h3 class="mcnews_header"><?php _e('Latest from Mandrill...', 'wpmandrill'); ?></h3>
<ul>
<?php
foreach ( $rss_items as $item ) { ?>
<li>
<a href='<?php echo esc_url( $item->get_permalink() ); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo esc_html( $item->get_title() ); ?></a>
</li>
<?php } ?>
</ul>
</div>
<?php } ?>
<div class="mcnews">
<h3 class="mcnews_header"><?php _e('News from MailChimp...', 'wpmandrill'); ?></h3><?php
$rss = fetch_feed('http://mailchimp.com/blog/feed');
if (!is_wp_error( $rss ) ) {
$maxitems = $rss->get_item_quantity(5);
$rss_items = $rss->get_items(0, $maxitems);
} ?>
<ul>
<?php if ($maxitems == 0) echo '<li>No news!</li>';
else
foreach ( $rss_items as $item ) { ?>
<li>
<a href='<?php echo esc_url( $item->get_permalink() ); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo esc_html( $item->get_title() ); ?></a>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
<?php
}
......@@ -366,11 +335,11 @@ class wpMandrill {
self::getConnected();
?>
<div class="wrap">
<div class="icon32" style="background: url('<?php echo plugins_url('images/mandrill-head-icon.png',__FILE__); ?>');"><br /></div>
<div class="wrap">
<div class="icon32" style="background: url('<?php echo SEWM_URL . 'images/mandrill-head-icon.png'; ?>');"><br /></div>
<h2><?php _e('Mandrill How-Tos', 'wpmandrill'); ?> <small><a href="options-general.php?page=<?php echo 'wpmandrill'; ?>">back to settings</a></small></h2>
<?php
require plugin_dir_path( __FILE__ ) . '/how-tos.php';
require SEWM_PATH . '/how-tos.php';
echo wpMandrill_HowTos::show('intro');
echo wpMandrill_HowTos::show('auto');
......@@ -385,7 +354,22 @@ class wpMandrill {
}
static function showReportPage() {
require plugin_dir_path( __FILE__ ) . '/stats.php';
require SEWM_PATH . '/stats.php';
}
static function getReportsDashboardURL($args=[]){
$get_params = !empty($args) ? '&'.http_build_query( $args ) : '';
return admin_url('/index.php?page=wpmandrill-reports'.$get_params);
}
static function fetchNewDashboardData() {
wp_redirect(
self::getReportsDashboardURL(
array(
'fetch_new' => 'asap'
)
)
);
}
/**
......@@ -422,17 +406,17 @@ class wpMandrill {
return;
?>
<script type="text/javascript">
jQuery(document).bind( 'ready', function() {
<script type="text/javascript">
jQuery(document).on( 'ready', function() {
jQuery('a#contextual-help-link').trigger('click');
});
</script>
});
</script>
<?php
}
/******************************************************************
** Helper functions
*******************************************************************/
/******************************************************************
** Helper functions
*******************************************************************/
/**
* @return mixed
......@@ -457,7 +441,7 @@ jQuery(document).bind( 'ready', function() {
static function getConnected() {
if ( !isset(self::$mandrill) ) {
try {
require_once( plugin_dir_path( __FILE__ ) . '/lib/mandrill.class.php');
require_once( SEWM_PATH . '/lib/mandrill.class.php');
self::$mandrill = new Mandrill( self::getAPIKey() );
} catch ( Exception $e ) {}
}
......@@ -488,6 +472,9 @@ jQuery(document).bind( 'ready', function() {
* @return string|boolean
*/
static function getAPIKey() {
if( defined('SEWM_API_KEY') ){
return SEWM_API_KEY;
}
return self::getOption('api_key');
}
......@@ -532,6 +519,14 @@ jQuery(document).bind( 'ready', function() {
/**
* @return string|boolean
*/
static function getSubAccount() {
return self::getOption('subaccount');
}
/**
* @return string|boolean
*/
static function getTemplate() {
return self::getOption('template');
......@@ -548,6 +543,36 @@ jQuery(document).bind( 'ready', function() {
/**
* @return string|boolean
*/
static function isWooCommerceActive() {
// If WooCommerce is not active, we can ignore
if ( !class_exists( 'WooCommerce' ) ) {
return false;
}
return true;
}
/**
* @return string|boolean
*/
static function getnl2brWooCommerce() {
if( !self::isWooCommerceActive() )
return false;
return self::getOption('nl2br_woocommerce');
}
/**
* @return string|boolean
*/
static function gethideDashboardWidget() {
return self::getOption('hide_dashboard_widget');
}
/**
* @return string|boolean
*/
static function getTrackOpens() {
return self::getOption('trackopens');
......@@ -625,7 +650,7 @@ jQuery(document).bind( 'ready', function() {
$templates = self::$mandrill->templates_list();
foreach ( $templates as $curtemplate ) {
if ( $curtemplate['name'] == $template ) {
if ( $curtemplate['name'] == $template || $curtemplate['slug'] == $template) {
return true;
}
}
......@@ -680,8 +705,13 @@ jQuery(document).bind( 'ready', function() {
static function askAPIKey() {
echo '<div class="inside">';
$api_key = self::getOption('api_key');
$api_key = self::getAPIKey();
if( defined('SEWM_API_KEY') ) {
?>API Key globally defined.<?php
} else {
?><input id='api_key' name='wpmandrill[api_key]' size='45' type='text' value="<?php esc_attr_e( $api_key ); ?>" /><?php
}
if ( empty($api_key) ) {
?><br/><span class="setting-description"><small><em><?php _e('To get your API key, please visit your <a href="http://mandrillapp.com/settings/index" target="_blank">Mandrill Settings</a>', 'wpmandrill'); ?></em></small></span><?php
......@@ -731,7 +761,19 @@ jQuery(document).bind( 'ready', function() {
?><?php _e('This address will be used as the recipient where replies from the users will be sent to:', 'wpmandrill'); ?><br />
<input id="reply_to" name="wpmandrill[reply_to]" type="text" value="<?php esc_attr_e($reply_to);?>"><br/>
<span class="setting-description"><small><em><?php _e('Leave blank to use the FROM Email. If you want to override this setting, you must use the <em><a href="#" onclick="jQuery(\'a#contextual-help-link\').trigger(\'click\');return false;">mandrill_payload</a></em> WordPress filter.', 'wpmandrill'); ?></em></small></span><?php
<span class="setting-description"><br /><small><em><?php _e('Leave blank to use the FROM Email. If you want to override this setting, you must use the <em><a href="#" onclick="jQuery(\'a#contextual-help-link\').trigger(\'click\');return false;">mandrill_payload</a></em> WordPress filter.', 'wpmandrill'); ?></em></small></span><?php
echo '</div>';
}
static function askSubAccount() {
echo '<div class="inside">';
$subaccount = self::getSubAccount();
?><?php _e('Name of the sub account you wish to use (optional):', 'wpmandrill'); ?><br />
<input id="subaccount" name="wpmandrill[subaccount]" type="text" value="<?php esc_attr_e($subaccount); ?>">
<?php
echo '</div>';
}
......@@ -767,7 +809,7 @@ jQuery(document).bind( 'ready', function() {
foreach( $templates as $curtemplate ) {
?><option value="<?php esc_attr_e($curtemplate['name']); ?>" <?php selected($curtemplate['name'], $template); ?>><?php esc_html_e($curtemplate['name']); ?></option><?php
}
?></select><br/><span class="setting-description"><em><?php _e('<small>The selected template must have a <strong><em>mc:edit="main"</em></strong> placeholder defined. The message will be shown there.</small>', 'wpmandrill'); ?></em></span><?php
?></select><br/><span class="setting-description"><em><?php _e('<br /><small>The selected template must have a <strong><em>mc:edit="main"</em></strong> placeholder defined. The message will be shown there.</small>', 'wpmandrill'); ?></em></span><?php
echo '</div>';
}
......@@ -799,8 +841,21 @@ jQuery(document).bind( 'ready', function() {
<input id="nl2br" name="wpmandrill[nl2br]" type="checkbox" <?php echo checked($nl2br,1); ?> value='1' /><br/>
<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'); ?><br/>
<?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'); ?>
<?php _e('<br /><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/>
<?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;">mandrill_nl2br</a></strong> filter.</small>', 'wpmandrill'); ?>
</em></span>
</div><?php
}
static function asknl2brWooCommerce() {
$nl2br_woocommerce = self::getnl2brWooCommerce();
if ( $nl2br_woocommerce == '' ) $nl2br_woocommerce = 0;
?>
<div class="inside">
<input id="nl2br_woocommere" name="wpmandrill[nl2br_woocommerce]" type="checkbox" <?php echo checked($nl2br_woocommerce,1); ?> value='1' /><br/>
<span class="setting-description">
<em>
<?php _e('<br /><small>Check this if your WooCommerce emails are spaced incorrectly after enabling the <br/> setting above.</small>', 'wpmandrill'); ?>
</em></span>
</div><?php
}
......@@ -810,14 +865,23 @@ jQuery(document).bind( 'ready', function() {
$tags = self::getTags();
?><?php _e('If there are tags that you want appended to every call, list them here, one per line:', 'wpmandrill'); ?><br />
?><?php _e('If there are tags that you want appended to every call, list them here, one per line:<br />', 'wpmandrill'); ?><br />
<textarea id="tags" name="wpmandrill[tags]" cols="25" rows="3"><?php echo $tags; ?></textarea><br/>
<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>
<span class="setting-description"><br /><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>
<?php
echo '</div>';
}
static function hideDashboardWidget() {
$hideDashboardWidget = self::getHideDashboardWidget();
if ( $hideDashboardWidget == '' ) $hideDashboardWidget = 0;
?>
<div class="inside">
<input id="hide_dashboard_widget" name="wpmandrill[hide_dashboard_widget]" type="checkbox" <?php echo checked($hideDashboardWidget,1); ?> value='1' /><br/>
<?php
}
static function askTestEmailTo() {
echo '<div class="inside">';
?><input id='email_to' name='wpmandrill-test[email_to]' size='45' type='text' value="<?php esc_attr_e( self::getTestEmailOption('email_to') ); ?>"/><?php
......@@ -851,9 +915,9 @@ jQuery(document).bind( 'ready', function() {
}
/******************************************************************
** Stats-related functions
*******************************************************************/
/******************************************************************
** Stats-related functions
*******************************************************************/
/**
* @return array
......@@ -891,11 +955,7 @@ jQuery(document).bind( 'ready', function() {
}
$stats['senders'] = $data;
$stats['urls'] = self::$mandrill->urls_list();
$final['general'] = $stats['user'];
$final['urls'] = $stats['urls'];
$final['stats'] = array();
$final['stats']['hourly']['senders'] = array();;
......@@ -1010,9 +1070,15 @@ jQuery(document).bind( 'ready', function() {
/**
* Try to get the current stats from cache. First, using a transient, if it has expired, it returns the latest
* saved stats if found... and if there's none saved, it creates it diretly from Mandrill.
* saved stats if found... and if there's none saved, it creates it directly from Mandrill.
*/
static function getCurrentStats() {
if( is_array($_GET) ){
if( array_key_exists('fetch_new', $_GET) && $_GET['fetch_new']=='asap'){
$stats = self::saveProcessedStats();
return $stats;
}
}
$stats = get_transient('wpmandrill-stats');
if ( empty($stats) ) {
......@@ -1037,7 +1103,7 @@ jQuery(document).bind( 'ready', function() {
$stats = self::GetProcessedStats();
if ( !empty($stats) ) {
set_transient('wpmandrill-stats', $stats, 60 * 60);
update_option('wpmandrill-stats', $stats);
update_option('wpmandrill-stats', $stats, false);
} else {
error_log( date('Y-m-d H:i:s') . " wpMandrill::saveProcessedStats (Empty Response from ::GetProcessedStats)\n" );
}
......@@ -1046,10 +1112,10 @@ jQuery(document).bind( 'ready', function() {
}
static function addDashboardWidgets() {
if (!current_user_can('manage_options')) return;
if (!current_user_can('manage_options') || self::getOption('hide_dashboard_widget')) return;
self::getConnected();
if ( !self::isConnected() ) return;
if ( !self::isConnected() || !apply_filters( 'wpmandrill_enable_widgets', true ) ) return;
$widget_id = 'mandrill_widget';
......@@ -1203,16 +1269,16 @@ jQuery(document).bind( 'ready', function() {
$js = '';
if ( !$isAjaxCall ) {
$js .= '
<script type="text/javascript" src="'.plugins_url('/js/flot/jquery.flot.js', __FILE__).'"></script>
<script type="text/javascript" src="'.plugins_url('/js/flot/jquery.flot.stack.js', __FILE__).'"></script>
<script type="text/javascript" src="'.plugins_url('/js/flot/jquery.flot.resize.js', __FILE__).'"></script>';
<script type="text/javascript" src="'.SEWM_URL . 'js/flot/jquery.flot.js"></script>
<script type="text/javascript" src="'.SEWM_URL . 'js/flot/jquery.flot.stack.js"></script>
<script type="text/javascript" src="'.SEWM_URL . 'js/flot/jquery.flot.resize.js"></script>';
$js .= '
<div style="height:400px;">
<div id="filtered_recent" style="height:400px;">Loading...</div>
</div>
<script type="text/javascript">
jQuery(document).bind( \'ready\', function() {
jQuery(document).on( \'ready\', function() {
';
}
$js .= <<<JS
......@@ -1235,7 +1301,7 @@ jQuery(document).bind( \'ready\', function() {
}).appendTo("body").fadeIn(200);
}
var previousPoint = null;
jQuery("#filtered_recent").bind("plothover", function (event, pos, item) {
jQuery("#filtered_recent").on("plothover", function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
......@@ -1257,11 +1323,16 @@ jQuery(document).bind( \'ready\', function() {
previousPoint = null;
}
});
jQuery(function () {
var hbounces= [{$bounces['recent']}];
var hopens = [{$opens['recent']}];
var huopens = [{$unopens['recent']}];
if ( ! jQuery("#mandrill_widget").is(":visible") ) {
return;
}
jQuery.plot(jQuery("#filtered_recent"),
[ { data: hbounces, label: "{$lit['bounced']}" },
{ data: hopens, label: "{$lit['opened']}" },
......@@ -1468,7 +1539,7 @@ var ounopened = [{$ounopened}]
jQuery(function () {
var previousPoint = null;
jQuery("#filtered_recent").bind("plothover", function (event, pos, item) {
jQuery("#filtered_recent").on("plothover", function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
......@@ -1490,7 +1561,7 @@ jQuery(function () {
previousPoint = null;
}
});
jQuery("#filtered_oldest").bind("plothover", function (event, pos, item) {
jQuery("#filtered_oldest").on("plothover", function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
......@@ -1576,9 +1647,9 @@ JS;
}
/******************************************************************
** Function to actually send the emails
*******************************************************************
/******************************************************************
** Function to actually send the emails
*******************************************************************
/**
* @param string|array $to recipients, array or comma-separated string
* @param string $subject email subject
......@@ -1676,9 +1747,7 @@ JS;
* @return boolean
*/
static function wp_mail_native( $to, $subject, $message, $headers = '', $attachments = array() ) {
error_log( "\nwpMandrill::wp_mail_native: $to ($subject)\n" );
require plugin_dir_path( __FILE__ ) . '/legacy/function.wp_mail.php';
require SEWM_PATH . '/legacy/function.wp_mail.php';
}
/**
......@@ -1749,7 +1818,7 @@ JS;
case 'bcc':
// TODO: Mandrill's API only accept one BCC address. Other addresses will be silently discarded
$bcc = array_merge( (array) $bcc, explode( ',', $content ) );
$bcc = explode( ',', $content );
$message['bcc_address'] = $bcc[0];
break;
......@@ -1786,7 +1855,7 @@ JS;
if ( is_array($email) ) {
$processed_to[] = $email;
} else {
$processed_to[] = array( 'email' => $email );
$processed_to[] = self::ensureEmailFormatting( $email );
}
}
$message['to'] = $processed_to;
......@@ -1856,6 +1925,9 @@ JS;
}
}
// Add subaccount if specified in settings
if ( !empty(self::getSubAccount()) ) $message['subaccount'] = self::getSubAccount();
// Letting user to filter/change the message payload
$message['from_email'] = apply_filters('wp_mail_from', $message['from_email']);
$message['from_name'] = apply_filters('wp_mail_from_name', $message['from_name']);
......@@ -1908,8 +1980,8 @@ JS;
global $wp_version;
if ( ! function_exists( 'get_plugins' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$plugin_folder = get_plugins( '/' . plugin_basename( dirname( __FILE__ ) ) );
$plugin_file = basename( ( __FILE__ ) );
$plugin_folder = get_plugins( '/' . dirname( SEWM_BASE ) );
$plugin_file = basename( SEWM_BASE );
$me = $plugin_folder[$plugin_file]['Version'];
$php = phpversion();
......@@ -1917,13 +1989,34 @@ JS;
return "wpMandrill/$me (PHP/$php; WP/$wp)";
}
/**
* Ensures the email field sent to Mandrill is formatted accordingly for emails with the name formatting
*
* @param $email
* @param string $type
* @return array
*/
static function ensureEmailFormatting( $email, $type = 'to' ) {
if( preg_match( '/(.*)<(.+)>/', $email, $matches ) ) {
if ( count( $matches ) == 3 ) {
return array(
'email' => $matches[2],
'name' => $matches[1],
'type' => $type
);
}
}
return array( 'email' => $email );
}
}
function wpMandrill_transformJSArray(&$value, $key, $params = 0) {
if ( is_array($params) ) {
$format = isset($params[0]) ? $params[0] : 0;
$day_keys = isset($params[1]) ? $params[1] : array();
}
switch ( $format ) {
case 0:
$value = "[$key,$value]";
......@@ -1933,6 +2026,5 @@ function wpMandrill_transformJSArray(&$value, $key, $params = 0) {
$value = "[$key,$value]";
break;
}
}
}
?>
\ No newline at end of file
......
=== Send Emails with Mandrill ===
Contributors: MillerMediaNow, mikemm01, MC_Will, MC_Amanda, cornelraiu-1, crstauf, bizmatebiz, andrewhilson, anthonywnz, srumery, ronald2020, ilanio, sanderteirlynck
Tags: mandrill, mailchimp, transactional email, email, email reliability, smtp, wp_mail, email templates
Requires PHP: 5.6
Requires at least: 3.0
Tested up to: 6.1.1
Stable tag: 1.3.1
License: GPLv2
The Send Emails with Mandrill plugin sends emails that are generated by WordPress through Mandrill, a transactional email service powered by MailChimp.
== Description ==
**Did you find this plugin helpful?** Please consider [leaving a 5-star review](https://wordpress.org/support/view/plugin-reviews/send-emails-with-mandrill/).
Note: This is a forked version of the now unsupported <a href="https://wordpress.org/plugins/wpmandrill/">wpMandrill</a> plugin. The notes below are copied over from the original plugin and will be updated as relevant updates become available. Please help by contributing to the GitHub repository [Send Emails With Mandrill on GitHub](https://github.com/Miller-Media/send-emails-with-mandrill)
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.
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.
You can also use your own templates that have been added to your MailChimp account and shared with your Mandrill account.
There are a few levels of integrations between your WordPress installation and this plugin:
1. The simplest option: Install it, configure it, and Send Emails with Mandrill will start sending your emails through Mandrill.
1. If you need to fine tune certain emails, you can change any email by creating a filter for the **mandrill_payload** hook.
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**
Enable the connection by entering a valid API key in the settings page or adding the line `define('SEWM_API_KEY', '{YOUR_API_KEY}')` your site's wp-config.php file.
Spanish translation available.
== Installation ==
1. Upload `Send Emails with Mandrill` to the `/wp-content/plugins/` directory
1. Activate the plugin through the _Plugins_ menu in WordPress
1. Configure plugin in _Settings > Mandrill_
== Frequently Asked Questions ==
= Why do I need a Mandrill API key? =
In order to use this plugin, you have to provide one of your Mandrill API keys. That's currently the only way we can get access to your Mandrill account.
= Do I need a MailChimp account? =
Yes. If you aren't currently on a MailChimp Monthly Plan, you'll first need to upgrade or switch to a Monthly Plan. Once you have upgraded you can follow the steps [here](https://mailchimp.com/help/add-or-remove-mandrill/) to add Mandrill to your account.
= Are all emails routed through Mandrill? =
Yes. We try to send every single email sent through your WordPress installation. We also try to process your headers and attachments.
If the sending fails for any reason, the plugin will try to send it again using the WordPress wp_mail function.
= What if I need to send some of my emails using the native wp_mail() function?
Use the mandrill_payload filter and add a new parameter called 'force_native' to the $message variable, and set it to true:
$message['force_native'] = true;
= My emails are broken and show weird CSS code =
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 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:
function my_function($nl2br, $message) {
if ( in_array('wp_retrieve_password', $message['tags']['automatic']) ) {
$nl2br = false;
}
return $nl2br;
}
add_filter('mandrill_nl2br', 'my_function');
= Is there any way to check what's going on? =
If we couldn't send your email through Mandrill, we'll try to leave the Mandrill response in your server's log so that's your first stop.
Additionally, if you set the WP_DEBUG constant (defined in your wp-config.php file) to true, you'll see some messages added by the plugin in key parts of the process.
= I am getting an Invalid API Key message and I'm sure my API is valid!
Please verify the following:
1. That your API key is active (this can be viewed on the SMTP & API Credentials page in your Mandrill account);
2. 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);
3. That the domain name you're using above is listed in the Sending Domains for your Mandrill account.
== Request ==
If you find that a part of this plugin isn't working, please don't simply click the Wordpress "It's broken" button. Let us know what's broken in [its support forum](https://wordpress.org/support/plugin/send-emails-with-mandrill/) so we can make it better. Our [mind-reading device](http://www.youtube.com/watch?v=cCTlonSwePs) still needs some tweaking.
== Localizations ==
Send Emails with Mandrill is currently localized in the following languages:
* Spanish (es_ES)
== Known Issues ==
* Daily statistics will show data for the first 20 senders (emails) registered.
* Daily statistics will show data for the first 40 tags registered.
If your account has more than 20 senders registered or more than 40 tags used, the detailed daily statisticas might show incompleted data.
== Screenshots ==
1. Settings screen
2. Statistics
3. Dashboard widget
4. Dashboard widget Settings
== Changelog ==
= 1.3.1 =
* Check for error messages parameters before processing (was throwing an error)
= 1.3 =
* Added setting to turn off Dashboard Widget
* Added ability to manually fetch new data from Reports screen
* Added ability to define API key as SEWM_API_KEY in wp-config.php file
* Minor error handling adjustments
= 1.2.13 =
* Setting to disable <br /> setting for WooCommerce emails due to layout issues from recent WooCommerce updates
= 1.2.12 =
* Updates to deprecated jQuery functions
= 1.2.9 =
* Removed deprecated contextual_help() function and added add_help_tab()
= 1.2.8 =
* Add wpmandrill_enable_reports and wpmandrill_enable_widgets filters to programmatically disable the reports dashboard and widget if desired.
= 1.2.7 =
* Removed code added for previous Mandrill outage
= 1.2.6 =
* Updated messaging on how to handle the upcoming Mandrill outage
* Bug fix for memcache overload when loading Mandrill reports page on high traffic sites
= 1.2.5 =
* Updated plugin screenshots for WordPress repository
* Added support/setting for Mandrill subaccount
* Removed discontinued Mandrill API endpoint support (URL tracking)
= 1.2.4 =
* Removed RSS Feeds due to WordPress core bugs (SimplePie library)
* CSS adjustments
* Fixed false negatives when used in conjunction with Contact Form 7 and other mail sending programs
= 1.2.3 =
* Fixed WooCommerce checkout issue (class scope bug)
= 1.2.2 =
* More detailed error logging for failed e-mails
* Added email formatting to include 'name'
= 1.2.1 =
* PHP warning fix
= 1.2 =
* Added ability to override wp_mail_native function with a WordPress action
* 404 console fixes
* Various undefined variable fixes
= 1.1 =
* Added support for PHP 7.2
* Removed support for PHP < 5.6
* Added plugin activation compatibility checks
= 1.0 =
* Initial release
......@@ -36,7 +36,13 @@ $lit['clickrate'] = __('Click Rate','wpmandrill');
?>
<div id="alltime_report">
<h3><?php echo sprintf(__('All-time statistics since %s: ', 'wpmandrill'),date('m/d/Y',strtotime($stats['general']['created_at']))); ?></h3>
<hr />
<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="POST">
<input name="action" value="sewm_fetch_new" type="hidden" />
<?php submit_button('Fetch new data'); ?>
<h5 style="margin-top:0px;">Note: Fetching new data can take a long time</h5>
</form>
<hr />
<div id="alltime_report_canvas">
<div class="stat_box"><?php _e('Reputation:', 'wpmandrill'); ?><br/><span><?php echo $stats['general']['reputation']?>%</span></div>
<div class="stat_box"><?php _e('Quota:', 'wpmandrill'); ?><br/><span><?php echo $stats['general']['hourly_quota']?> <?php _e('sends/hour', 'wpmandrill'); ?></span></div>
......@@ -152,7 +158,7 @@ var dclickrates = [<?php echo implode(',',$dcrate);?>]
var dticks = [<?php echo implode(',',array_keys($stats['graph']['daily']['delivered']));?>]
jQuery(function () {
var previousPoint = null;
jQuery("#hourly_report_canvas").bind("plothover", function (event, pos, item) {
jQuery("#hourly_report_canvas").on("plothover", function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
......@@ -174,7 +180,7 @@ jQuery(function () {
previousPoint = null;
}
});
jQuery("#daily_report_canvas").bind("plothover", function (event, pos, item) {
jQuery("#daily_report_canvas").on("plothover", function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
......
<?php
/*
Plugin Name: Send E-mails with Mandrill
Description: Send e-mails using Mandrill. This is a forked version of the now unsupported plugin <a href="https://wordpress.org/plugins/wpmandrill/">wpMandrill</a>.
Author: Miller Media ( Matt Miller )
Author URI: http://www.millermedia.io
Version: 1.3.1
Requires PHP: 5.6
Text Domain: send-emails-with-mandrill
*/
/* Copyright 2012 MailChimp (email : will@mailchimp.com )
Copyright 2018 Miller Media (email : support@miller-media.com )
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation using version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if ( ! defined( 'ABSPATH' ) ) exit;
// Define plugin constants
if ( !defined('SEWM_VERSION'))
define( 'SEWM_VERSION', '1.3.1' );
if ( !defined( 'SEWM_BASE' ) )
define( 'SEWM_BASE', plugin_basename( __FILE__ ) );
if ( !defined( 'SEWM_URL' ) )
define( 'SEWM_URL', plugin_dir_url( __FILE__ ) );
if ( !defined( 'SEWM_PATH' ) )
define( 'SEWM_PATH', plugin_dir_path( __FILE__ ) );
include( plugin_dir_path( __FILE__ ) . 'lib/pluginActivation.class.php');
include( plugin_dir_path( __FILE__ ) . 'lib/wpMandrill.class.php');
wpMandrill::on_load();
=== wpMandrill ===
Contributors: MC_Will
Tags: mandrill, mailchimp, transactional email, email, email reliability, smtp, wp_mail, email templates
Requires at least: 3.0
Tested up to: 3.8
Stable tag: trunk
License: GPLv2
The wpMandrill plugin sends emails that are generated by WordPress through Mandrill, a transactional email service powered by MailChimp.
== Description ==
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.
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.
You can also use your own templates that have been added to your MailChimp account and shared with your Mandrill account.
There are a few levels of integrations between your WordPress installation and this plugin:
1. The simplest option: Install it, configure it, and wpMandrill will start sending your emails through Mandrill.
1. If you need to fine tune certain emails, you can change any email by creating a filter for the **mandrill_payload** hook.
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**
This plugin is currently released as **beta** for early adopter evaluation and finalizing of the initial feature set.
Spanish translation available.
== Installation ==
1. Upload `wpMandrill` to the `/wp-content/plugins/` directory
1. Activate the plugin through the _Plugins_ menu in WordPress
1. Configure plugin in _Settings > Mandrill_
== Frequently Asked Questions ==
= Why do I need a Mandrill API key? =
In order to use this plugin, you have to provide one of your Mandrill API keys. That's currently the only way we can get access to your Mandrill account.
= Do I need a MailChimp account? =
Nop.
= Are all emails routed through Mandrill? =
Yes. We try to send every single email sent through your WordPress installation. We also try to process your headers and attachments.
If the sending fails for any reason, the plugin will try to send it again using the WordPress wp_mail function.
= What if I need to send some of my emails using the native wp_mail() function?
Use the mandrill_payload filter and add a new parameter called 'force_native' to the $message variable, and set it to true:
$message['force_native'] = true;
= My emails are broken and show weird CSS code =
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 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:
function my_function($nl2br, $message) {
if ( in_array('wp_retrieve_password', $message['tags']['automatic']) ) {
$nl2br = false;
}
return $nl2br;
}
add_filter('mandrill_nl2br', 'my_function');
= Is there any way to check what's going on? =
If we couldn't send your email through Mandrill, we'll try to leave the Mandrill response in your server's log so that's your first stop.
Additionaly, if you set the WP_DEBUG constant (defined in your wp-config.php file) to true, you'll see some messages added by the plugin in key parts of the process.
= I am getting an Invalid API Key message and I'm sure my API is valid!
Please verify the following:
1. That your API key is active (this can be viewed on the SMTP & API Credentials page in your Mandrill account);
1. 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);
1. That the domain name you're using above is listed in the Sending Domains for your Mandrill account.
== Request ==
If you find that a part of this plugin isn't working, please don't simply click the Wordpress "It's broken" button. Let us know what's broken in [its support forum](http://wordpress.org/tags/wpmandrill?forum_id=10) so we can make it better. Our [mind-reading device](http://www.youtube.com/watch?v=cCTlonSwePs) still needs some tweaking.
== Localizations ==
wpMandrill is currently localized in the following languages:
* Spanish (es_ES)
== Known Issues ==
* Daily statistics will show data for the first 20 senders (emails) registered.
* Daily statistics will show data for the first 40 tags registered.
If your account has more than 20 senders registered or more than 40 tags used, the detailed daily statisticas might show incompleted data.
== Screenshots ==
1. Settings screen
2. Statistics
3. Dashboard widget
4. Dashboard widget Settings
== Changelog ==
= 1.33 =
* ADDED: Logging messages to trace a bug where the stats are not getting 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 <br>" setting, for specific messages. Check the How-To to see how it works.
* FIXED: Removing wrongly formatted attachments from the payload
= 1.32 =
* FIXED: Reordering constructors of Mandrill class to prevent the "Redefining already defined constructor" message
* UPDATE: Favoring self:: instead of wpMandrill::
= 1.31 =
* FIXED: Some PHP 5.3 installations don't have the finfo_open available so we're now checking for the function instead of the PHP version
= 1.30 =
* FIXED: Multiples To: recipients where not being handling correctly.
= 1.29 =
* ADDED: wp_mail, wp_mail_from, and wp_mail_from_name filters. ** Thanks Mike Little! **
* ADDED: Support for "important" emails.
* UPDATED: Wordpress wp_mail function code.
* ADDED: wpMandrill User-Agent
= 1.28 =
* ADDED: If you want to fall back some of your emails to the native wp_mail function, now you can do it by using the mandrill_payload filter and setting a parameter called 'force_native' to true.
* REMOVED: Mime type checking on attachments.
* ADDED: Sending MIME TYPE of attachments to Mandrill only when wpMandrill is able to find it.
= 1.27 =
* FIXED: Removing php short tags. ** Thanks Kailey Lampert! **
= 1.26 =
* UPDATED: Now Mandrill accepts any content type and so does wpMandrill.
* FIXED: Queued messages were triggering the native wp_mail function. ** Thanks Scott Connerly! **
= 1.25 =
* FIXED: Undefined WPDOMAIN constant in stats.php
= 1.24 =
* UPDATED: Dashboard widget shown only to those capable of manage_options
* ADDED: CURL calls doesn't verify SSL certificates anymore. ** Thanks Bruno Braga! **
* ADDED: Adding support for editable regions. ** Thanks dennissmolek **
* FIXED: Using a literal as the textdomain instead of a constant. ** Thanks Joost! **
* FIXED: Cleaning some unused variables. ** Thanks Joost! **
* FIXED: Removed checking of sender domain at send time.
= 1.23 =
* FIXED: JS Alerts in wrong places...
= 1.22 =
* UPDATED: Replacing Highcharts in favor of Flot
* ADD: Cron job to fetch stats
= 1.21 =
* FIXED: Logging wrong error messages when sending emails with no attachments
* FIXED: Attachments that Mandrill doesn't support were discarded instead of sending the email (with attachment) through the native wp_mail function.
* ADDED: Added support Audio and Video file attachments.
* FIXED: Valid Domains matching is NOT case-sensitive now.
* FIXED: Better error reporting on Dashboard widgets.
* FIXED: Validating FROM: email address after mandrill_payload has been processed.
= 1.20 =
* ADDED: Mandrill's Privacy Policy and Terms of Use
* FIXED: Sending more than one attachment was failing
* FIXED: Doing a Ping call only when displaying the API Key on the settings page
* ADDED: Support for Global Merge Vars, Per-Recipient Merge Vars, Google Analytics, and Meta Data in wpMandrill::mail()
* FIXED: Logging error messages even if WP_DEBUG is false.
= 1.12 =
* FIXED: Issue with the CSS declaration of the RSS icon displayed on the settings page. ** Thanks Nicholas Ciske! **
* FIXED: Highcharts' Exporting module not loaded for dashboard widget
* FIXED: Removing unnecessary pings to MandrillApp.com and instanciating the API client on demand ** Thanks Per Wiklander! **
= 1.11 =
* ADDED: screenshot-4.jpg
* FIXED: Emails delivered % in Mandrill stats
* ADDED: Limiting the numbers of senders that the Mandrill stats reports.
* FIXED: Limiting the numbers of days to 30 in Daily Sending Volume graph in Mandrill stats reports.
* ADDED: Visual notification in the dashboard widget while loading.
* ADDED: Support for sockets when CURL is not present.
= 1.10 =
* ADDED: Blank .po file for other translations :)
* ADDED: Some debugging messages just in case need arises.
* ADDED: Adding GNU license
* ADDED: Mandrill's blog RSS
= 1.09 =
* ADDED: Reply-To Setting
* ADDED: Replacing line feed by <br> setting.
= 1.08 =
* FIXED: Wrong references to self:: in wp_mail introduce in 1.04 :(
= 1.07 =
* FIXED: Removing notices in the dashboard widget when there's no open or click data in the last 7 days.
* FIXED: No having general tags defined were causing a validation error. ** Thanks Max Rice! **
* FIXED: Daily stats showing some hourly stats.
* UPDATED: Spanish translation updated.
* FIXED: Speeding dashboard widget results.
= 1.06 =
* FIXED: Some installations were reporting valid API keys as invalid due to a restrictive server configuration regarding Time-Out.
= 1.05 =
* FIXED: Contextual help tab getting open in all admin pages when plugin was not configured correctly.
* FIXED: Some references to verified domains. All domains are now verified in Mandrill.
* FIXED: Mandrill Class was returning Exceptions in two places (not throwing them).
= 1.03 =
* FIXED: Test email were using an old function.
* FIXED: Some data type checking to avoid PHP warnings.
= 1.02 =
* FIXED: Dashboard widget title was displaying incorrectly when a filter was defined.
= 1.01 =
* REMOVED: How-To Plugin
* ADDED: How-To page
= 1.0 =
* Public release