Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Parameter Name in wpMandrill Plugin - 'meta_data' should be 'metadata' #93

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion css/mandrill.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@
.stuffbox div.inside { padding-bottom: 10px;}

.stuffbox table.form-table { margin: 3px 3px 3px 10px; width: auto; }
.stuffbox h2 { text-decoration: underline; }
.stuffbox h2 { text-decoration: underline; }

.stuffbox span.settings_sub_header {padding: 0px 10px; }
13 changes: 11 additions & 2 deletions lib/mandrill.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,17 @@ function request($method, $args = array(), $http = 'POST', $output = 'json') {
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);

}
}

Expand Down
83 changes: 68 additions & 15 deletions lib/wpMandrill.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ static function on_load() {
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') ) {
Expand Down Expand Up @@ -102,13 +104,13 @@ static function adminInit() {
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', 'wpmandrill'), array(__CLASS__, 'asknl2brWooCommerce'), 'wpmandrill', 'wpmandrill-templates');
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');
Expand All @@ -124,6 +126,9 @@ static function adminInit() {
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
Expand Down Expand Up @@ -254,17 +259,21 @@ static function showContextualHelp() {
* 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);
Expand Down Expand Up @@ -348,6 +357,21 @@ static function showReportPage() {
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'
)
)
);
}

/**
* Processes submitted settings from.
*/
Expand Down Expand Up @@ -448,6 +472,9 @@ static function setOption( $name, $value ) {
* @return string|boolean
*/
static function getAPIKey() {
if( defined('SEWM_API_KEY') ){
return SEWM_API_KEY;
}

return self::getOption('api_key');
}
Expand Down Expand Up @@ -536,6 +563,13 @@ static function getnl2brWooCommerce() {
return self::getOption('nl2br_woocommerce');
}

/**
* @return string|boolean
*/
static function gethideDashboardWidget() {
return self::getOption('hide_dashboard_widget');
}

/**
* @return string|boolean
*/
Expand Down Expand Up @@ -671,8 +705,13 @@ static function sendTestEmail($input) {
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
Expand Down Expand Up @@ -813,7 +852,6 @@ static function asknl2brWooCommerce() {
if ( $nl2br_woocommerce == '' ) $nl2br_woocommerce = 0;
?>
<div class="inside">
<?php _e('Fix for WooCommerce emails', 'wpmandrill'); ?>
<input id="nl2br_woocommere" name="wpmandrill[nl2br_woocommerce]" type="checkbox" <?php echo checked($nl2br_woocommerce,1); ?> value='1' /><br/>
<span class="setting-description">
<em>
Expand All @@ -835,6 +873,15 @@ static function askTags() {
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
Expand Down Expand Up @@ -1023,9 +1070,15 @@ static function getProcessedStats() {

/**
* 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) ) {
Expand Down Expand Up @@ -1059,7 +1112,7 @@ static function saveProcessedStats() {
}

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() || !apply_filters( 'wpmandrill_enable_widgets', true ) ) return;
Expand Down Expand Up @@ -1615,7 +1668,7 @@ static function getAjaxStats() {
* @param array $merge_vars Per-recipient merge variables, which override global merge variables with the same name.
* @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.
* @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.
* @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.
* @param array $metadata 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.
* @param boolean $important Set the important flag to true for the current email
* @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
* @param boolean $preserve_recipients whether or not to expose all recipients in to "To" header for each email
Expand Down Expand Up @@ -1643,7 +1696,7 @@ static function mail( $to, $subject, $html, $headers = '', $attachments = array(
$merge_vars = array(),
$google_analytics_domains = array(),
$google_analytics_campaign = array(),
$meta_data = array(),
$metadata = array(),
$important = false,
$inline_css = null,
$preserve_recipients=null,
Expand All @@ -1669,7 +1722,7 @@ static function mail( $to, $subject, $html, $headers = '', $attachments = array(
'merge_vars',
'google_analytics_domains',
'google_analytics_campaign',
'meta_data',
'metadata',
'important',
'inline_css',
'preserve_recipients',
Expand Down
18 changes: 16 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: MillerMediaNow, mikemm01, MC_Will, MC_Amanda, cornelraiu-1, crstau
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: 5.6
Stable tag: 1.2.12
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.
Expand All @@ -27,6 +27,8 @@ There are a few levels of integrations between your WordPress installation and t
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 ==
Expand Down Expand Up @@ -110,6 +112,18 @@ If your account has more than 20 senders registered or more than 40 tags used, t
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

Expand Down
Binary file modified screenshot-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
?>
<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>
Expand Down
6 changes: 3 additions & 3 deletions wpmandrill.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.2.12
Version: 1.3.1
Requires PHP: 5.6
Text Domain: send-emails-with-mandrill
*/
Expand Down Expand Up @@ -32,7 +32,7 @@

// Define plugin constants
if ( !defined('SEWM_VERSION'))
define( 'SEWM_VERSION', '1.2.11' );
define( 'SEWM_VERSION', '1.3.1' );

if ( !defined( 'SEWM_BASE' ) )
define( 'SEWM_BASE', plugin_basename( __FILE__ ) );
Expand All @@ -46,4 +46,4 @@
include( plugin_dir_path( __FILE__ ) . 'lib/pluginActivation.class.php');
include( plugin_dir_path( __FILE__ ) . 'lib/wpMandrill.class.php');

wpMandrill::on_load();
wpMandrill::on_load();