diff --git a/css/mandrill.css b/css/mandrill.css index 4e063bb..465dbbf 100644 --- a/css/mandrill.css +++ b/css/mandrill.css @@ -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; } \ No newline at end of file +.stuffbox h2 { text-decoration: underline; } + +.stuffbox span.settings_sub_header {padding: 0px 10px; } \ No newline at end of file diff --git a/lib/mandrill.class.php b/lib/mandrill.class.php index 690c667..c8335a3 100644 --- a/lib/mandrill.class.php +++ b/lib/mandrill.class.php @@ -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); + } } diff --git a/lib/wpMandrill.class.php b/lib/wpMandrill.class.php index 31f5b3f..4d5a391 100644 --- a/lib/wpMandrill.class.php +++ b/lib/wpMandrill.class.php @@ -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') ) { @@ -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'); @@ -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 "Settings for WordPress plugin. Does not affect email delivery functionality or design."; }, 'wpmandrill'); + add_settings_field('hide_dashboard_widget', __('Hide WP Dashboard Widget', 'wpmandrill'), array(__CLASS__, 'hideDashboardWidget'), 'wpmandrill', 'wpmandrill-misc'); } // Fix for WooCommerce @@ -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' => '' . __('Settings', 'wpmandrill') . ''); + if ($plugin == $plugin_file) { + $settings = array('settings' => '' . __('Settings', 'wpmandrill') . ''); + self::getConnected(); if ( self::isConnected() ) { - $report = array('report' => '' . __('Reports', 'wpmandrill') . ''); + $report = array('report' => '' . __('Reports', 'wpmandrill') . ''); $actions = array_merge($settings, $actions, $report); } else { $actions = array_merge($settings, $actions); @@ -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. */ @@ -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'); } @@ -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 */ @@ -671,8 +705,13 @@ static function sendTestEmail($input) { static function askAPIKey() { echo '