MailChimp Forms by MailMunch - Version 2.0.7

Version Description

Download this release

Release Info

Developer mailmunch
Plugin Icon 128x128 MailChimp Forms by MailMunch
Version 2.0.7
Comparing to
See all releases

Code changes from version 2.0.6 to 2.0.7

includes/class-mailchimp-mailmunch.php CHANGED
@@ -18,6 +18,7 @@ define( 'MAILCHIMP_MAILMUNCH_URL', "http://wordpress.mailmunch.co" );
18
  define( 'MAILCHIMP_MAILMUNCH_HOME_URL', "http://www.mailmunch.co" );
19
  define( 'MAILCHIMP_MAILMUNCH_SLUG', "mailchimp-mailmunch" );
20
  define( 'MAILCHIMP_MAILMUNCH_PREFIX', 'mc_mm' );
 
21
 
22
  /**
23
  * The core plugin class.
18
  define( 'MAILCHIMP_MAILMUNCH_HOME_URL', "http://www.mailmunch.co" );
19
  define( 'MAILCHIMP_MAILMUNCH_SLUG', "mailchimp-mailmunch" );
20
  define( 'MAILCHIMP_MAILMUNCH_PREFIX', 'mc_mm' );
21
+ define( 'MAILCHIMP_MAILMUNCH_VERSION', '2.0.7' );
22
 
23
  /**
24
  * The core plugin class.
includes/class-mailmunch-api.php CHANGED
@@ -63,17 +63,16 @@
63
  if (empty($siteId)) $siteId = $this->getSiteId();
64
  if (empty($siteId)) return false;
65
 
66
- $sites = $this->getSites();
67
- $s = false;
68
- if (count($sites)) {
69
- foreach ($sites as $site) {
70
- if (intval($site->id) == intval($siteId)) {
71
- $s = $site;
72
- break;
73
- }
74
- }
75
  }
76
- return $s;
 
 
 
77
  }
78
 
79
  function getLists($siteId=null) {
@@ -91,9 +90,12 @@
91
  $list = $this->createList($listName);
92
  if ($list) {
93
  $site = $this->getSite();
94
- $integration = $this->createIntegration($site->id, $list->id, $accessToken, $externalListId );
95
- return $integration;
 
 
96
  }
 
97
  }
98
 
99
  function findOrCreateSite() {
@@ -194,7 +196,7 @@
194
  );
195
 
196
  $this->requestType = 'post';
197
- $request = $this->ping('/wordpress/migrate_user.json', array(), true);
198
  $this->headers = $currentHeaders;
199
 
200
  if( is_wp_error( $request ) ) {
@@ -357,24 +359,21 @@
357
  delete_option($this->getPrefix(). 'mailchimp_list_id');
358
  }
359
 
360
- function ping($path, $options=array(), $skipTokenAuth=false, $retries=0) {
361
- $retries++;
362
- if ($retries > 3) return new WP_Error('broke', 'Internal Server Error');
363
-
364
  $type = $this->requestType;
365
  $url = $this->base_url. $path;
366
 
367
- if (!$skipTokenAuth) {
368
- $parsedUrl = parse_url($url);
369
- $parseUrlQuery = isset($parsedUrl['query']) ? $parsedUrl['query'] : null;
370
- if (!empty($parseUrlQuery)) {
371
- $url .= '&token='. $this->getUserToken();
372
- }
373
- else {
374
- $url .= '?token='. $this->getUserToken();
375
- }
376
  }
377
 
 
 
378
  $args = array(
379
  'headers' => $this->headers,
380
  'timeout' => 120,
@@ -392,11 +391,10 @@
392
  return new WP_Error( 'broke', "Internal Server Error" );
393
  }
394
 
395
- if (!$skipTokenAuth) {
396
  if (!is_wp_error( $request ) && isset($request['response']['code']) && $request['response']['code'] == 401) {
397
  $this->signOutUser();
398
- $this->ensureUser();
399
- return $this->ping($path, $options, $skipTokenAuth, $retries);
400
  }
401
  }
402
 
63
  if (empty($siteId)) $siteId = $this->getSiteId();
64
  if (empty($siteId)) return false;
65
 
66
+ $this->requestType = 'get';
67
+ $request = $this->ping('/sites/'. $siteId);
68
+
69
+ if( is_wp_error( $request ) ) {
70
+ return false;
 
 
 
 
71
  }
72
+
73
+ $site = $request['body'];
74
+ $result = json_decode($site);
75
+ return $result;
76
  }
77
 
78
  function getLists($siteId=null) {
90
  $list = $this->createList($listName);
91
  if ($list) {
92
  $site = $this->getSite();
93
+ if (!empty($site)) {
94
+ $integration = $this->createIntegration($site->id, $list->id, $accessToken, $externalListId );
95
+ return $integration;
96
+ }
97
  }
98
+ return false;
99
  }
100
 
101
  function findOrCreateSite() {
196
  );
197
 
198
  $this->requestType = 'post';
199
+ $request = $this->ping('/wordpress/migrate_user.json', array(), false);
200
  $this->headers = $currentHeaders;
201
 
202
  if( is_wp_error( $request ) ) {
359
  delete_option($this->getPrefix(). 'mailchimp_list_id');
360
  }
361
 
362
+ function ping($path, $options=array(), $useTokenAuth=true) {
 
 
 
363
  $type = $this->requestType;
364
  $url = $this->base_url. $path;
365
 
366
+ $parsedUrl = parse_url($url);
367
+ $parseUrlQuery = isset($parsedUrl['query']) ? $parsedUrl['query'] : null;
368
+ if (!empty($parseUrlQuery)) {
369
+ $url .= '&version='. MAILCHIMP_MAILMUNCH_VERSION;
370
+ }
371
+ else {
372
+ $url .= '?version='. MAILCHIMP_MAILMUNCH_VERSION;
 
 
373
  }
374
 
375
+ if ($useTokenAuth) { $url .= '&token='. $this->getUserToken(); }
376
+
377
  $args = array(
378
  'headers' => $this->headers,
379
  'timeout' => 120,
391
  return new WP_Error( 'broke', "Internal Server Error" );
392
  }
393
 
394
+ if ($useTokenAuth) {
395
  if (!is_wp_error( $request ) && isset($request['response']['code']) && $request['response']['code'] == 401) {
396
  $this->signOutUser();
397
+ return new WP_Error( 'broke', 'Unauthorized. Please try again.');
 
398
  }
399
  }
400
 
mailchimp-mailmunch.php CHANGED
@@ -16,7 +16,7 @@
16
  * Plugin Name: MailChimp Forms by MailMunch
17
  * Plugin URI: http://connect.mailchimp.com/integrations/mailmunch-email-list-builder
18
  * Description: The MailChimp plugin allows you to quickly and easily add signup forms for your MailChimp lists. Popup, Embedded, Top Bar and a variety of different options available.
19
- * Version: 2.0.6
20
  * Author: MailMunch
21
  * Author URI: http://www.mailmunch.co
22
  * License: GPL-2.0+
16
  * Plugin Name: MailChimp Forms by MailMunch
17
  * Plugin URI: http://connect.mailchimp.com/integrations/mailmunch-email-list-builder
18
  * Description: The MailChimp plugin allows you to quickly and easily add signup forms for your MailChimp lists. Popup, Embedded, Top Bar and a variety of different options available.
19
+ * Version: 2.0.7
20
  * Author: MailMunch
21
  * Author URI: http://www.mailmunch.co
22
  * License: GPL-2.0+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: mailchimp,mailchimp form,mailchimp newsletter,mailchimp plugin,newsletter,
4
 
5
  Requires at least: 3.0.1
6
  Tested up to: 4.2
7
- Stable tag: 2.0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
4
 
5
  Requires at least: 3.0.1
6
  Tested up to: 4.2
7
+ Stable tag: 2.0.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10