WooCommerce MailChimp - Version 1.3.2

Version Description

  • Fix for headers already sent message. Tested with WordPress 4.0 and WooCommerce 2.2.*
Download this release

Release Info

Developer anderly
Plugin Icon 128x128 WooCommerce MailChimp
Version 1.3.2
Comparing to
See all releases

Code changes from version 1.3.1 to 1.3.2

README.md CHANGED
@@ -1,4 +1,6 @@
1
  ## WooCommerce MailChimp ##
 
 
2
 
3
  WooCommerce MailChimp provides simple and flexible MailChimp integration for WooCommerce.
4
 
@@ -64,6 +66,9 @@ If you need help, have problems, want to leave feedback or want to provide const
64
 
65
  ### Changelog
66
 
 
 
 
67
  #### 1.3.1
68
  * Fix for MailChimp merge vars bug introduced in v1.3
69
 
1
  ## WooCommerce MailChimp ##
2
+ [![WordPress Plugin version](http://img.shields.io/badge/plugin-v1.3.2-blue.svg?style=flat)](https://wordpress.org/plugins/woocommerce-mailchimp/)
3
+ [![License](http://img.shields.io/badge/license-GPLv3-red.svg?style=flat)](http://opensource.org/licenses/GPL-3.0)
4
 
5
  WooCommerce MailChimp provides simple and flexible MailChimp integration for WooCommerce.
6
 
66
 
67
  ### Changelog
68
 
69
+ #### 1.3.2
70
+ * Fix for headers already sent message. Tested with WordPress 4.0 and WooCommerce 2.2.*
71
+
72
  #### 1.3.1
73
  * Fix for MailChimp merge vars bug introduced in v1.3
74
 
classes/class-ss-wc-integration-mailchimp.php CHANGED
@@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
9
  *
10
  * @class SS_WC_Integration_MailChimp
11
  * @extends WC_Integration
12
- * @version 1.3.1
13
  * @package WooCommerce MailChimp
14
  * @author Saint Systems
15
  */
@@ -34,13 +34,14 @@ class SS_WC_Integration_MailChimp extends WC_Integration {
34
  // Load the settings.
35
  $this->init_settings();
36
 
37
- // We need the API key to set up for the lists in teh form fields
38
  $this->api_key = $this->get_option( 'api_key' );
 
 
39
 
40
  $this->init_form_fields();
41
 
42
  // Get setting values
43
- $this->enabled = $this->get_option( 'enabled' );
44
  $this->occurs = $this->get_option( 'occurs' );
45
  $this->list = $this->get_option( 'list' );
46
  $this->double_optin = $this->get_option( 'double_optin' );
@@ -82,7 +83,7 @@ class SS_WC_Integration_MailChimp extends WC_Integration {
82
  // Check required fields
83
  if ( ! $this->api_key ) {
84
 
85
- echo '<div class="error"><p>' . sprintf( __('MailChimp error: Please enter your api key <a href="%s">here</a>', 'ss_wc_mailchimp'), admin_url('admin.php?page=woocommerce&tab=integration&section=mailchimp' ) ) . '</p></div>';
86
 
87
  return;
88
 
@@ -97,7 +98,7 @@ class SS_WC_Integration_MailChimp extends WC_Integration {
97
  * @access public
98
  * @return void
99
  */
100
- public function order_status_changed( $id, $status = 'new', $new_status = 'pending' ) {
101
 
102
  if ( $this->is_valid() && $new_status == $this->occurs ) {
103
 
@@ -159,12 +160,14 @@ class SS_WC_Integration_MailChimp extends WC_Integration {
159
  */
160
  function init_form_fields() {
161
 
162
- if ( is_admin() ) {
163
 
164
- $lists = $this->get_lists();
165
- if ($lists === false ) {
166
- $lists = array ();
167
- }
 
 
168
 
169
  $mailchimp_lists = $this->has_api_key() ? array_merge( array( '' => __('Select a list...', 'ss_wc_mailchimp' ) ), $lists ) : array( '' => __( 'Enter your key and save to see your lists', 'ss_wc_mailchimp' ) );
170
  //$mailchimp_interest_groupings = $this->has_list() ? array_merge( array( '' => __('Select an interest grouping...', 'ss_wc_mailchimp' ) ), $this->get_interest_groupings( $this->list ) ) : array( '' => __( 'Please select a list to see your interest groupings.', 'ss_wc_mailchimp' ) );
@@ -296,13 +299,12 @@ class SS_WC_Integration_MailChimp extends WC_Integration {
296
  if ( ! $mailchimp_lists = get_transient( 'ss_wc_mailchimp_list_' . md5( $this->api_key ) ) ) {
297
 
298
  $mailchimp_lists = array();
299
- $mailchimp = new MCAPI( $this->api_key );
300
- $retval = $mailchimp->lists();
301
 
302
- if ( $mailchimp->errorCode ) {
303
-
304
- echo '<div class="error"><p>' . sprintf( __( 'Unable to load lists() from MailChimp: (%s) %s', 'ss_wc_mailchimp' ), $mailchimp->errorCode, $mailchimp->errorMessage ) . '</p></div>';
305
 
 
 
306
  return false;
307
 
308
  } else {
@@ -317,6 +319,22 @@ class SS_WC_Integration_MailChimp extends WC_Integration {
317
  return $mailchimp_lists;
318
  }
319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  /**
321
  * get_interest_groupings function.
322
  *
9
  *
10
  * @class SS_WC_Integration_MailChimp
11
  * @extends WC_Integration
12
+ * @version 1.3.2
13
  * @package WooCommerce MailChimp
14
  * @author Saint Systems
15
  */
34
  // Load the settings.
35
  $this->init_settings();
36
 
37
+ // We need the API key to set up for the lists in the form fields
38
  $this->api_key = $this->get_option( 'api_key' );
39
+ $this->mailchimp = new MCAPI( $this->api_key );
40
+ $this->enabled = $this->get_option( 'enabled' );
41
 
42
  $this->init_form_fields();
43
 
44
  // Get setting values
 
45
  $this->occurs = $this->get_option( 'occurs' );
46
  $this->list = $this->get_option( 'list' );
47
  $this->double_optin = $this->get_option( 'double_optin' );
83
  // Check required fields
84
  if ( ! $this->api_key ) {
85
 
86
+ echo '<div class="error"><p>' . sprintf( __('WooCommerce MailChimp error: Plugin is enabled but no api key provided. Please enter your api key <a href="%s">here</a>.', 'ss_wc_mailchimp'), WOOCOMMERCE_MAILCHIMP_SETTINGS_URL ) . '</p></div>';
87
 
88
  return;
89
 
98
  * @access public
99
  * @return void
100
  */
101
+ public function order_status_changed( $id, $status = 'new', $new_status = 'pending' ) {
102
 
103
  if ( $this->is_valid() && $new_status == $this->occurs ) {
104
 
160
  */
161
  function init_form_fields() {
162
 
163
+ if ( is_admin() && !is_ajax() ) {
164
 
165
+ if ( $this->enabled && $this->has_api_key() ) {
166
+ $lists = $this->get_lists();
167
+ if ($lists === false ) {
168
+ $lists = array ();
169
+ }
170
+ }
171
 
172
  $mailchimp_lists = $this->has_api_key() ? array_merge( array( '' => __('Select a list...', 'ss_wc_mailchimp' ) ), $lists ) : array( '' => __( 'Enter your key and save to see your lists', 'ss_wc_mailchimp' ) );
173
  //$mailchimp_interest_groupings = $this->has_list() ? array_merge( array( '' => __('Select an interest grouping...', 'ss_wc_mailchimp' ) ), $this->get_interest_groupings( $this->list ) ) : array( '' => __( 'Please select a list to see your interest groupings.', 'ss_wc_mailchimp' ) );
299
  if ( ! $mailchimp_lists = get_transient( 'ss_wc_mailchimp_list_' . md5( $this->api_key ) ) ) {
300
 
301
  $mailchimp_lists = array();
302
+ $retval = $this->mailchimp->lists();
 
303
 
304
+ if ( $this->mailchimp->errorCode ) {
 
 
305
 
306
+ add_action( 'admin_notices', array( $this, 'mailchimp_api_error_msg' ) );
307
+ add_action( 'network_admin_notices', array( $this, 'mailchimp_api_error_msg' ) );
308
  return false;
309
 
310
  } else {
319
  return $mailchimp_lists;
320
  }
321
 
322
+ /**
323
+ * Display message to user if there is an issue with the MailChimp API call
324
+ *
325
+ * @since 1.0
326
+ * @param void
327
+ * @return html the message for the user
328
+ */
329
+ public function mailchimp_api_error_msg() {
330
+
331
+ $html = '<div class="error">';
332
+ $html .= '<p>' . sprintf( __( 'Unable to load lists from MailChimp: (%s) %s.', 'ss_wc_mailchimp' ), $this->mailchimp->errorCode, $this->mailchimp->errorMessage ) . sprintf( __( ' Please check your <a href="' . WOOCOMMERCE_MAILCHIMP_SETTINGS_URL . '">settings' . '</a>', 'ss_wc_mailchimp' ) ) . '</p>';
333
+ $html .= '</div>';
334
+ echo $html;
335
+
336
+ }
337
+
338
  /**
339
  * get_interest_groupings function.
340
  *
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: anderly, saintsystems
3
  Tags: woocommerce, mailchimp
4
  Requires at least: 3.5.1
5
- Tested up to: 3.8.1
6
- Stable tag: 1.3.1
7
  License: GPLv3
8
 
9
  Simple and flexible MailChimp integration for WooCommerce.
@@ -78,6 +78,9 @@ If you need help, have problems, want to leave feedback or want to provide const
78
 
79
  == Changelog ==
80
 
 
 
 
81
  = 1.3.1 =
82
  * Fix for MailChimp merge vars bug introduced in v1.3
83
 
2
  Contributors: anderly, saintsystems
3
  Tags: woocommerce, mailchimp
4
  Requires at least: 3.5.1
5
+ Tested up to: 4.0
6
+ Stable tag: 1.3.2
7
  License: GPLv3
8
 
9
  Simple and flexible MailChimp integration for WooCommerce.
78
 
79
  == Changelog ==
80
 
81
+ = 1.3.2 =
82
+ * Fix for headers already sent message. Tested with WordPress 4.0 and WooCommerce 2.2.*
83
+
84
  = 1.3.1 =
85
  * Fix for MailChimp merge vars bug introduced in v1.3
86
 
woocommerce-mailchimp.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: WooCommerce MailChimp provides simple MailChimp integration for WooCommerce.
6
  * Author: Adam Anderly
7
  * Author URI: http://anderly.com
8
- * Version: 1.3.1
9
  * Text Domain: ss_wc_mailchimp
10
  * Domain Path: languages
11
  *
@@ -25,6 +25,18 @@ function woocommerce_mailchimp_init() {
25
 
26
  load_plugin_textdomain( 'ss_wc_mailchimp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
27
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  include_once( 'classes/class-ss-wc-integration-mailchimp.php' );
29
 
30
  /**
@@ -39,16 +51,8 @@ function woocommerce_mailchimp_init() {
39
 
40
  function action_links( $links ) {
41
 
42
- global $woocommerce;
43
-
44
- $settings_url = admin_url( 'admin.php?page=woocommerce_settings&tab=integration&section=mailchimp' );
45
-
46
- if ( $woocommerce->version >= '2.1' ) {
47
- $settings_url = admin_url( 'admin.php?page=wc-settings&tab=integration&section=mailchimp' );
48
- }
49
-
50
  $plugin_links = array(
51
- '<a href="' . $settings_url . '">' . __( 'Settings', 'ss_wc_mailchimp' ) . '</a>',
52
  );
53
 
54
  return array_merge( $plugin_links, $links );
5
  * Description: WooCommerce MailChimp provides simple MailChimp integration for WooCommerce.
6
  * Author: Adam Anderly
7
  * Author URI: http://anderly.com
8
+ * Version: 1.3.2
9
  * Text Domain: ss_wc_mailchimp
10
  * Domain Path: languages
11
  *
25
 
26
  load_plugin_textdomain( 'ss_wc_mailchimp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
27
 
28
+ global $woocommerce;
29
+
30
+ $settings_url = admin_url( 'admin.php?page=woocommerce_settings&tab=integration&section=mailchimp' );
31
+
32
+ if ( $woocommerce->version >= '2.1' ) {
33
+ $settings_url = admin_url( 'admin.php?page=wc-settings&tab=integration&section=mailchimp' );
34
+ }
35
+
36
+ if ( ! defined( 'WOOCOMMERCE_MAILCHIMP_SETTINGS_URL' ) ) {
37
+ define( 'WOOCOMMERCE_MAILCHIMP_SETTINGS_URL', $settings_url );
38
+ }
39
+
40
  include_once( 'classes/class-ss-wc-integration-mailchimp.php' );
41
 
42
  /**
51
 
52
  function action_links( $links ) {
53
 
 
 
 
 
 
 
 
 
54
  $plugin_links = array(
55
+ '<a href="' . WOOCOMMERCE_MAILCHIMP_SETTINGS_URL . '">' . __( 'Settings', 'ss_wc_mailchimp' ) . '</a>',
56
  );
57
 
58
  return array_merge( $plugin_links, $links );