Version Description
Download this release
Release Info
Developer | anderly |
Plugin | WooCommerce MailChimp |
Version | 2.3.5 |
Comparing to | |
See all releases |
Code changes from version 2.3.4 to 2.3.5
assets/js/woocommerce-mailchimp-admin.js
CHANGED
@@ -66,7 +66,7 @@ var SS_WC_MailChimp = function($) {
|
|
66 |
$apiKey.change(function() {
|
67 |
checkApiKey($apiKey.val(), true);
|
68 |
});
|
69 |
-
checkApiKey($apiKey.val(), false)
|
70 |
|
71 |
$mainList.change(function() {
|
72 |
if ($mainList.val()) {
|
@@ -127,7 +127,7 @@ var SS_WC_MailChimp = function($) {
|
|
127 |
} //end function initAccount
|
128 |
|
129 |
function initLists() {
|
130 |
-
$listsLoadingIndicator = $('<div id="ss_wc_mailchimp_loading_lists" class="woocommerce-mailchimp-loading"><span class="woocommerce-mailchimp-loading-indicator"> '+
|
131 |
$mainList.after($listsLoadingIndicator.hide());
|
132 |
|
133 |
} //end function initLists
|
@@ -141,13 +141,13 @@ var SS_WC_MailChimp = function($) {
|
|
141 |
var grouping;
|
142 |
var $options = $interestGroups.children('option').clone();
|
143 |
|
144 |
-
$interestGroups.attr('data-placeholder',
|
145 |
|
146 |
$interestGroups.select2('destroy').select2();
|
147 |
var groupsMessage = $('#ss-wc-mailchimp-groups-msg').length > 0 ? $('#ss-wc-mailchimp-groups-msg') : $('<div id="ss-wc-mailchimp-groups-msg" style="display: inline-block"/>');
|
148 |
$interestGroups.after(groupsMessage);
|
149 |
if ($options.length === 0) {
|
150 |
-
groupsMessage.text(
|
151 |
$interestGroups.siblings('.select2-container').remove();
|
152 |
groupsMessage.show();
|
153 |
} else {
|
@@ -156,7 +156,7 @@ var SS_WC_MailChimp = function($) {
|
|
156 |
}
|
157 |
|
158 |
// Add the loading indicator for groups (set to hidden by default)
|
159 |
-
$interestGroupsLoadingIndicator = $('<div id="ss_wc_mailchimp_loading_groups" class="woocommerce-mailchimp-loading"><span class="woocommerce-mailchimp-loading-indicator"> '+
|
160 |
$interestGroups.parent().append($interestGroupsLoadingIndicator.hide());
|
161 |
|
162 |
} //end function initGroups
|
@@ -166,13 +166,13 @@ var SS_WC_MailChimp = function($) {
|
|
166 |
// Reinitialize the <optgroup> elements by splitting out the option names
|
167 |
var $options = $tags.children('option').clone();
|
168 |
|
169 |
-
$tags.attr('data-placeholder',
|
170 |
|
171 |
$tags.select2('destroy').select2();
|
172 |
var tagsMessage = $('#ss-wc-mailchimp-tags-msg').length > 0 ? $('#ss-wc-mailchimp-tags-msg') : $('<div id="ss-wc-mailchimp-tags-msg" style="display: inline-block"/>');
|
173 |
$tags.after(tagsMessage);
|
174 |
if ($options.length === 0) {
|
175 |
-
tagsMessage.text(
|
176 |
$tags.siblings('.select2-container').remove();
|
177 |
tagsMessage.show();
|
178 |
} else {
|
@@ -181,12 +181,14 @@ var SS_WC_MailChimp = function($) {
|
|
181 |
}
|
182 |
|
183 |
// Add the loading indicator for tags (set to hidden by default)
|
184 |
-
$tagsLoadingIndicator = $('<div id="ss_wc_mailchimp_loading_tags" class="woocommerce-mailchimp-loading"><span class="woocommerce-mailchimp-loading-indicator"> '+
|
185 |
$tags.parent().append($tagsLoadingIndicator.hide());
|
186 |
|
187 |
} //end function initTags
|
188 |
|
189 |
-
function checkApiKey(apiKey, shouldLoadLists
|
|
|
|
|
190 |
|
191 |
if ( $apiKey.val() === '' ) {
|
192 |
toggleAllSettings('hide');
|
@@ -204,12 +206,13 @@ var SS_WC_MailChimp = function($) {
|
|
204 |
$accountIndicator = $accountLoadingIndicator.children().first();
|
205 |
$accountIndicator.removeClass('success').removeClass('error');
|
206 |
$accountIndicator.addClass('loading');
|
207 |
-
$accountIndicator.html(' '+
|
208 |
$.post(
|
209 |
ajaxurl,
|
210 |
{
|
211 |
'action': '' + namespace_prefixed('get_account'),
|
212 |
-
'data': { 'api_key': apiKey }
|
|
|
213 |
},
|
214 |
function(response) {
|
215 |
console.log(response);
|
@@ -221,7 +224,7 @@ var SS_WC_MailChimp = function($) {
|
|
221 |
} catch (err) {
|
222 |
console.error(err);
|
223 |
$accountIndicator.addClass('error');
|
224 |
-
$accountIndicator.html(' '+
|
225 |
return;
|
226 |
}
|
227 |
|
@@ -233,7 +236,7 @@ var SS_WC_MailChimp = function($) {
|
|
233 |
|
234 |
if ( ! result.account_id ) {
|
235 |
$accountIndicator.addClass('error');
|
236 |
-
$accountIndicator.html(' '+
|
237 |
return;
|
238 |
}
|
239 |
|
@@ -263,7 +266,8 @@ var SS_WC_MailChimp = function($) {
|
|
263 |
ajaxurl,
|
264 |
{
|
265 |
'action': '' + namespace_prefixed('get_lists'),
|
266 |
-
'data': { 'api_key': apiKey }
|
|
|
267 |
},
|
268 |
function(response) {
|
269 |
console.log(response);
|
@@ -275,7 +279,7 @@ var SS_WC_MailChimp = function($) {
|
|
275 |
result = $.parseJSON(response);
|
276 |
} catch (err) {
|
277 |
console.error(err);
|
278 |
-
alert(
|
279 |
}
|
280 |
|
281 |
if (result) {
|
@@ -313,7 +317,8 @@ var SS_WC_MailChimp = function($) {
|
|
313 |
ajaxurl,
|
314 |
{
|
315 |
'action': '' + namespace_prefixed('get_interest_groups'),
|
316 |
-
'data': { 'api_key': apiKey, 'list_id': listId }
|
|
|
317 |
},
|
318 |
function(response) {
|
319 |
console.log(response);
|
@@ -325,7 +330,7 @@ var SS_WC_MailChimp = function($) {
|
|
325 |
result = $.parseJSON(response);
|
326 |
} catch (err) {
|
327 |
console.error(err);
|
328 |
-
alert(
|
329 |
}
|
330 |
|
331 |
if (result.error) {
|
@@ -376,7 +381,8 @@ var SS_WC_MailChimp = function($) {
|
|
376 |
ajaxurl,
|
377 |
{
|
378 |
'action': '' + namespace_prefixed('get_tags'),
|
379 |
-
'data': { 'api_key': apiKey, 'list_id': listId }
|
|
|
380 |
},
|
381 |
function(response) {
|
382 |
console.log(response);
|
@@ -388,7 +394,7 @@ var SS_WC_MailChimp = function($) {
|
|
388 |
result = $.parseJSON(response);
|
389 |
} catch (err) {
|
390 |
console.error(err);
|
391 |
-
alert(
|
392 |
}
|
393 |
|
394 |
if (result.error) {
|
66 |
$apiKey.change(function() {
|
67 |
checkApiKey($apiKey.val(), true);
|
68 |
});
|
69 |
+
checkApiKey($apiKey.val(), false);
|
70 |
|
71 |
$mainList.change(function() {
|
72 |
if ($mainList.val()) {
|
127 |
} //end function initAccount
|
128 |
|
129 |
function initLists() {
|
130 |
+
$listsLoadingIndicator = $('<div id="ss_wc_mailchimp_loading_lists" class="woocommerce-mailchimp-loading"><span class="woocommerce-mailchimp-loading-indicator"> '+SSWCMC.messages.connecting_to_mailchimp+'</span></div>');
|
131 |
$mainList.after($listsLoadingIndicator.hide());
|
132 |
|
133 |
} //end function initLists
|
141 |
var grouping;
|
142 |
var $options = $interestGroups.children('option').clone();
|
143 |
|
144 |
+
$interestGroups.attr('data-placeholder', SSWCMC.messages.select_groups_placeholder);
|
145 |
|
146 |
$interestGroups.select2('destroy').select2();
|
147 |
var groupsMessage = $('#ss-wc-mailchimp-groups-msg').length > 0 ? $('#ss-wc-mailchimp-groups-msg') : $('<div id="ss-wc-mailchimp-groups-msg" style="display: inline-block"/>');
|
148 |
$interestGroups.after(groupsMessage);
|
149 |
if ($options.length === 0) {
|
150 |
+
groupsMessage.text(SSWCMC.messages.interest_groups_not_enabled);
|
151 |
$interestGroups.siblings('.select2-container').remove();
|
152 |
groupsMessage.show();
|
153 |
} else {
|
156 |
}
|
157 |
|
158 |
// Add the loading indicator for groups (set to hidden by default)
|
159 |
+
$interestGroupsLoadingIndicator = $('<div id="ss_wc_mailchimp_loading_groups" class="woocommerce-mailchimp-loading"><span class="woocommerce-mailchimp-loading-indicator"> '+SSWCMC.messages.connecting_to_mailchimp+'</span></div>');
|
160 |
$interestGroups.parent().append($interestGroupsLoadingIndicator.hide());
|
161 |
|
162 |
} //end function initGroups
|
166 |
// Reinitialize the <optgroup> elements by splitting out the option names
|
167 |
var $options = $tags.children('option').clone();
|
168 |
|
169 |
+
$tags.attr('data-placeholder', SSWCMC.messages.select_tags_placeholder);
|
170 |
|
171 |
$tags.select2('destroy').select2();
|
172 |
var tagsMessage = $('#ss-wc-mailchimp-tags-msg').length > 0 ? $('#ss-wc-mailchimp-tags-msg') : $('<div id="ss-wc-mailchimp-tags-msg" style="display: inline-block"/>');
|
173 |
$tags.after(tagsMessage);
|
174 |
if ($options.length === 0) {
|
175 |
+
tagsMessage.text(SSWCMC.messages.tags_not_enabled);
|
176 |
$tags.siblings('.select2-container').remove();
|
177 |
tagsMessage.show();
|
178 |
} else {
|
181 |
}
|
182 |
|
183 |
// Add the loading indicator for tags (set to hidden by default)
|
184 |
+
$tagsLoadingIndicator = $('<div id="ss_wc_mailchimp_loading_tags" class="woocommerce-mailchimp-loading"><span class="woocommerce-mailchimp-loading-indicator"> '+SSWCMC.messages.connecting_to_mailchimp+'</span></div>');
|
185 |
$tags.parent().append($tagsLoadingIndicator.hide());
|
186 |
|
187 |
} //end function initTags
|
188 |
|
189 |
+
function checkApiKey(apiKey, shouldLoadLists) {
|
190 |
+
|
191 |
+
shouldLoadLists = false;
|
192 |
|
193 |
if ( $apiKey.val() === '' ) {
|
194 |
toggleAllSettings('hide');
|
206 |
$accountIndicator = $accountLoadingIndicator.children().first();
|
207 |
$accountIndicator.removeClass('success').removeClass('error');
|
208 |
$accountIndicator.addClass('loading');
|
209 |
+
$accountIndicator.html(' '+SSWCMC.messages.connecting_to_mailchimp);
|
210 |
$.post(
|
211 |
ajaxurl,
|
212 |
{
|
213 |
'action': '' + namespace_prefixed('get_account'),
|
214 |
+
'data': { 'api_key': apiKey },
|
215 |
+
'nonce': SSWCMC.nonces.get_account
|
216 |
},
|
217 |
function(response) {
|
218 |
console.log(response);
|
224 |
} catch (err) {
|
225 |
console.error(err);
|
226 |
$accountIndicator.addClass('error');
|
227 |
+
$accountIndicator.html(' '+SSWCMC.messages.error_loading_account);
|
228 |
return;
|
229 |
}
|
230 |
|
236 |
|
237 |
if ( ! result.account_id ) {
|
238 |
$accountIndicator.addClass('error');
|
239 |
+
$accountIndicator.html(' '+SSWCMC.messages.error_loading_account);
|
240 |
return;
|
241 |
}
|
242 |
|
266 |
ajaxurl,
|
267 |
{
|
268 |
'action': '' + namespace_prefixed('get_lists'),
|
269 |
+
'data': { 'api_key': apiKey },
|
270 |
+
'nonce': SSWCMC.nonces.get_lists
|
271 |
},
|
272 |
function(response) {
|
273 |
console.log(response);
|
279 |
result = $.parseJSON(response);
|
280 |
} catch (err) {
|
281 |
console.error(err);
|
282 |
+
alert(SSWCMC.messages.error_loading_lists);
|
283 |
}
|
284 |
|
285 |
if (result) {
|
317 |
ajaxurl,
|
318 |
{
|
319 |
'action': '' + namespace_prefixed('get_interest_groups'),
|
320 |
+
'data': { 'api_key': apiKey, 'list_id': listId },
|
321 |
+
'nonce': SSWCMC.nonces.get_interest_groups
|
322 |
},
|
323 |
function(response) {
|
324 |
console.log(response);
|
330 |
result = $.parseJSON(response);
|
331 |
} catch (err) {
|
332 |
console.error(err);
|
333 |
+
alert(SSWCMC.messages.error_loading_groups);
|
334 |
}
|
335 |
|
336 |
if (result.error) {
|
381 |
ajaxurl,
|
382 |
{
|
383 |
'action': '' + namespace_prefixed('get_tags'),
|
384 |
+
'data': { 'api_key': apiKey, 'list_id': listId },
|
385 |
+
'nonce': SSWCMC.nonces.get_tags
|
386 |
},
|
387 |
function(response) {
|
388 |
console.log(response);
|
394 |
result = $.parseJSON(response);
|
395 |
} catch (err) {
|
396 |
console.error(err);
|
397 |
+
alert(SSWCMC.messages.error_loading_tags);
|
398 |
}
|
399 |
|
400 |
if (result.error) {
|
includes/class-ss-wc-mailchimp-admin-notices.php
CHANGED
@@ -38,26 +38,27 @@ class SS_WC_MailChimp_Admin_Notices {
|
|
38 |
*/
|
39 |
public function dismiss_notice() {
|
40 |
|
41 |
-
// No dismiss sent
|
42 |
if ( empty( $_GET['sswcmc-dismiss'] ) ) {
|
43 |
return;
|
44 |
}
|
45 |
|
46 |
-
// Invalid nonce
|
47 |
-
if ( !wp_verify_nonce( $_GET['sswcmc-dismiss'], 'dismiss' ) ) {
|
48 |
return;
|
49 |
}
|
50 |
|
51 |
-
|
|
|
|
|
52 |
|
53 |
-
//
|
54 |
-
$dismissed_notices = (array)get_transient( 'ss_wc_mailchimp_dismissed_notices' );
|
55 |
|
56 |
$dismissed_notices[] = $notice_id;
|
57 |
|
58 |
$dismissed_notices = array_unique( $dismissed_notices );
|
59 |
|
60 |
-
// Remind users every 30 days
|
61 |
set_transient( 'ss_wc_mailchimp_dismissed_notices', $dismissed_notices, DAY_IN_SECONDS * 30 );
|
62 |
|
63 |
}
|
@@ -73,21 +74,22 @@ class SS_WC_MailChimp_Admin_Notices {
|
|
73 |
* @param string $notice Notice array, set using `add_notice()`.
|
74 |
* @return boolean True: show notice; False: hide notice
|
75 |
*/
|
76 |
-
function
|
77 |
|
78 |
// There are no dismissed notices.
|
79 |
-
if( empty( self::$dismissed_notices ) ) {
|
80 |
return true;
|
81 |
}
|
82 |
|
83 |
-
// Has the
|
84 |
-
$is_dismissed = !empty( $notice['dismiss'] ) && in_array( $notice['dismiss'], self::$dismissed_notices );
|
85 |
|
86 |
return $is_dismissed ? false : true;
|
87 |
}
|
88 |
|
89 |
/**
|
90 |
* Get admin notices
|
|
|
91 |
* @since 1.12
|
92 |
* @return array
|
93 |
*/
|
@@ -113,7 +115,7 @@ class SS_WC_MailChimp_Admin_Notices {
|
|
113 |
return false;
|
114 |
}
|
115 |
|
116 |
-
//
|
117 |
if ( ! is_super_admin() ) {
|
118 |
return false;
|
119 |
}
|
@@ -132,38 +134,39 @@ class SS_WC_MailChimp_Admin_Notices {
|
|
132 |
|
133 |
/**
|
134 |
* Modify the notices displayed
|
|
|
135 |
* @since 2.0.13
|
136 |
*/
|
137 |
$notices = apply_filters( 'ss_wc_mailchimp/admin/notices', self::$admin_notices );
|
138 |
|
139 |
-
if( empty( $notices ) || ! $this->check_show_multisite_notices() ) {
|
140 |
return;
|
141 |
}
|
142 |
|
143 |
-
//
|
144 |
-
self::$dismissed_notices = isset( $_GET['show-dismissed-notices'] ) ? array() : (array)get_transient( 'ss_wc_mailchimp_dismissed_notices' );
|
145 |
|
146 |
-
foreach( $notices as $notice ) {
|
147 |
|
148 |
-
if( false === $this->
|
149 |
continue;
|
150 |
}
|
151 |
|
152 |
echo '<div id="message" class="notice '. sswcmc_sanitize_html_class( $notice['class'] ).'">';
|
153 |
|
154 |
-
if( !empty( $notice['title'] ) ) {
|
155 |
-
echo '<h3>'.esc_html( $notice['title'] ) .'</h3>';
|
156 |
}
|
157 |
|
158 |
-
echo wpautop( $notice['message'] );
|
159 |
|
160 |
-
if( !empty( $notice['dismiss'] ) ) {
|
161 |
|
162 |
-
$dismiss = esc_attr($notice['dismiss']);
|
163 |
|
164 |
$url = esc_url( add_query_arg( array( 'sswcmc-dismiss' => wp_create_nonce( 'dismiss' ), 'notice' => $dismiss ) ) );
|
165 |
|
166 |
-
echo wpautop( '<a href="'
|
167 |
}
|
168 |
|
169 |
echo '<div class="clear"></div>';
|
@@ -171,17 +174,18 @@ class SS_WC_MailChimp_Admin_Notices {
|
|
171 |
|
172 |
}
|
173 |
|
174 |
-
//
|
175 |
self::$admin_notices = array();
|
176 |
}
|
177 |
|
178 |
/**
|
179 |
* Add a notice to be displayed in the admin.
|
|
|
180 |
* @param array $notice Array with `class` and `message` keys. The message is not escaped.
|
181 |
*/
|
182 |
public static function add_notice( $notice = array() ) {
|
183 |
|
184 |
-
if( !isset( $notice['message'] ) ) {
|
185 |
do_action( 'ss_wc_mailchimp_log_error', 'SSWCMC_Admin[add_notice] Notice not set', $notice );
|
186 |
return;
|
187 |
}
|
38 |
*/
|
39 |
public function dismiss_notice() {
|
40 |
|
|
|
41 |
if ( empty( $_GET['sswcmc-dismiss'] ) ) {
|
42 |
return;
|
43 |
}
|
44 |
|
45 |
+
// Invalid nonce.
|
46 |
+
if ( ! wp_verify_nonce( sanitize_key( $_GET['sswcmc-dismiss'] ), 'dismiss' ) ) {
|
47 |
return;
|
48 |
}
|
49 |
|
50 |
+
if ( isset( $_GET['notice'] ) ) {
|
51 |
+
$notice_id = esc_attr( sanitize_text_field( wp_unslash( $_GET['notice'] ) ) );
|
52 |
+
}
|
53 |
|
54 |
+
// Don't display a message if use has dismissed the message for this version.
|
55 |
+
$dismissed_notices = (array) get_transient( 'ss_wc_mailchimp_dismissed_notices' );
|
56 |
|
57 |
$dismissed_notices[] = $notice_id;
|
58 |
|
59 |
$dismissed_notices = array_unique( $dismissed_notices );
|
60 |
|
61 |
+
// Remind users every 30 days.
|
62 |
set_transient( 'ss_wc_mailchimp_dismissed_notices', $dismissed_notices, DAY_IN_SECONDS * 30 );
|
63 |
|
64 |
}
|
74 |
* @param string $notice Notice array, set using `add_notice()`.
|
75 |
* @return boolean True: show notice; False: hide notice
|
76 |
*/
|
77 |
+
public function maybe_show_notice( $notice ) {
|
78 |
|
79 |
// There are no dismissed notices.
|
80 |
+
if ( empty( self::$dismissed_notices ) ) {
|
81 |
return true;
|
82 |
}
|
83 |
|
84 |
+
// Has the notice been dismissed?
|
85 |
+
$is_dismissed = ! empty( $notice['dismiss'] ) && in_array( $notice['dismiss'], self::$dismissed_notices );
|
86 |
|
87 |
return $is_dismissed ? false : true;
|
88 |
}
|
89 |
|
90 |
/**
|
91 |
* Get admin notices
|
92 |
+
*
|
93 |
* @since 1.12
|
94 |
* @return array
|
95 |
*/
|
115 |
return false;
|
116 |
}
|
117 |
|
118 |
+
// Or, they don't have admin capabilities.
|
119 |
if ( ! is_super_admin() ) {
|
120 |
return false;
|
121 |
}
|
134 |
|
135 |
/**
|
136 |
* Modify the notices displayed
|
137 |
+
*
|
138 |
* @since 2.0.13
|
139 |
*/
|
140 |
$notices = apply_filters( 'ss_wc_mailchimp/admin/notices', self::$admin_notices );
|
141 |
|
142 |
+
if ( empty( $notices ) || ! $this->check_show_multisite_notices() ) {
|
143 |
return;
|
144 |
}
|
145 |
|
146 |
+
// Don't display a message if use has dismissed the message for this version.
|
147 |
+
self::$dismissed_notices = isset( $_GET['show-dismissed-notices'] ) ? array() : (array) get_transient( 'ss_wc_mailchimp_dismissed_notices' );
|
148 |
|
149 |
+
foreach ( $notices as $notice ) {
|
150 |
|
151 |
+
if ( false === $this->maybe_show_notice( $notice ) ) {
|
152 |
continue;
|
153 |
}
|
154 |
|
155 |
echo '<div id="message" class="notice '. sswcmc_sanitize_html_class( $notice['class'] ).'">';
|
156 |
|
157 |
+
if ( ! empty( $notice['title'] ) ) {
|
158 |
+
echo '<h3>' . esc_html( $notice['title'] ) . '</h3>';
|
159 |
}
|
160 |
|
161 |
+
echo esc_html( wpautop( $notice['message'] ) );
|
162 |
|
163 |
+
if ( ! empty( $notice['dismiss'] ) ) {
|
164 |
|
165 |
+
$dismiss = esc_attr( $notice['dismiss'] );
|
166 |
|
167 |
$url = esc_url( add_query_arg( array( 'sswcmc-dismiss' => wp_create_nonce( 'dismiss' ), 'notice' => $dismiss ) ) );
|
168 |
|
169 |
+
echo wpautop( '<a href="' . $url . '" data-notice="' . $dismiss . '" class="button-small button button-secondary">' . esc_html__( 'Dismiss', 'woocommerce-mailchimp' ) . '</a>' );
|
170 |
}
|
171 |
|
172 |
echo '<div class="clear"></div>';
|
174 |
|
175 |
}
|
176 |
|
177 |
+
// Reset the notices handler.
|
178 |
self::$admin_notices = array();
|
179 |
}
|
180 |
|
181 |
/**
|
182 |
* Add a notice to be displayed in the admin.
|
183 |
+
*
|
184 |
* @param array $notice Array with `class` and `message` keys. The message is not escaped.
|
185 |
*/
|
186 |
public static function add_notice( $notice = array() ) {
|
187 |
|
188 |
+
if ( ! isset( $notice['message'] ) ) {
|
189 |
do_action( 'ss_wc_mailchimp_log_error', 'SSWCMC_Admin[add_notice] Notice not set', $notice );
|
190 |
return;
|
191 |
}
|
includes/class-ss-wc-mailchimp-handler.php
CHANGED
@@ -2,22 +2,25 @@
|
|
2 |
/**
|
3 |
* WooCommerce MailChimp Handler
|
4 |
*
|
5 |
-
* @author
|
6 |
-
* @package
|
7 |
-
* @version
|
8 |
*/
|
9 |
|
10 |
-
|
11 |
|
12 |
if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
13 |
|
14 |
/**
|
|
|
|
|
15 |
* @class SS_WC_MailChimp_Handler
|
16 |
*/
|
17 |
final class SS_WC_MailChimp_Handler {
|
18 |
|
19 |
/**
|
20 |
* Plugin singleton instance
|
|
|
21 |
* @var SS_WC_MailChimp_Handler
|
22 |
*/
|
23 |
private static $instance = null;
|
@@ -30,21 +33,23 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
30 |
*/
|
31 |
public function __construct() {
|
32 |
|
33 |
-
$this->id
|
34 |
-
$this->namespace
|
35 |
-
$this->label
|
36 |
-
$this->sswcmc
|
37 |
$this->register_hooks();
|
38 |
|
39 |
} //end function __construct
|
40 |
|
41 |
/**
|
|
|
|
|
42 |
* @return SS_WC_MailChimp_Handler
|
43 |
*/
|
44 |
public static function get_instance() {
|
45 |
|
46 |
if ( empty( self::$instance ) ) {
|
47 |
-
self::$instance = new self;
|
48 |
}
|
49 |
|
50 |
return self::$instance;
|
@@ -60,31 +65,31 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
60 |
public function register_hooks() {
|
61 |
|
62 |
// We would use the 'woocommerce_new_order' action but first name, last name and email address (order meta) is not yet available,
|
63 |
-
// so instead we use the 'woocommerce_checkout_update_order_meta' action hook which fires after the checkout process on the "thank you" page
|
64 |
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'order_status_changed' ), 1000, 1 );
|
65 |
|
66 |
-
//
|
67 |
add_action( 'woocommerce_order_status_changed', array( $this, 'order_status_changed' ), 10, 3 );
|
68 |
|
69 |
$opt_in_checkbox_display_location = $this->sswcmc->opt_in_checkbox_display_location();
|
70 |
|
71 |
-
// Maybe add an "opt-in" field to the checkout
|
72 |
-
$opt_in_checkbox_display_location = !empty( $opt_in_checkbox_display_location ) ? $opt_in_checkbox_display_location : 'woocommerce_review_order_before_submit';
|
73 |
|
74 |
-
// Old opt-in checkbox display locations
|
75 |
$old_opt_in_checkbox_display_locations = array(
|
76 |
'billing' => 'woocommerce_after_checkout_billing_form',
|
77 |
-
'order'
|
78 |
);
|
79 |
|
80 |
-
// Map old billing/order checkbox display locations to new format
|
81 |
if ( array_key_exists( $opt_in_checkbox_display_location, $old_opt_in_checkbox_display_locations ) ) {
|
82 |
$opt_in_checkbox_display_location = $old_opt_in_checkbox_display_locations[ $opt_in_checkbox_display_location ];
|
83 |
}
|
84 |
|
85 |
add_action( $opt_in_checkbox_display_location, array( $this, 'maybe_add_checkout_fields' ) );
|
86 |
|
87 |
-
// Maybe save the "opt-in" field on the checkout
|
88 |
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'maybe_save_checkout_fields' ) );
|
89 |
|
90 |
add_action( 'wp_ajax_ss_wc_mailchimp_get_account', array( $this, 'ajax_get_account' ) );
|
@@ -102,27 +107,30 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
102 |
} //end function ensure_tab
|
103 |
|
104 |
/**
|
105 |
-
*
|
106 |
*
|
107 |
* @access public
|
|
|
|
|
|
|
108 |
* @return void
|
109 |
*/
|
110 |
public function order_status_changed( $id, $status = 'new', $new_status = 'pending' ) {
|
111 |
if ( $this->sswcmc->is_valid() && $new_status === $this->sswcmc->occurs() ) {
|
112 |
-
// Get WC
|
113 |
$order = $this->wc_get_order( $id );
|
114 |
|
115 |
-
//
|
116 |
$subscribe_customer = get_post_meta( $id, 'ss_wc_mailchimp_opt_in', true );
|
117 |
|
118 |
-
$order_id
|
119 |
-
$order_billing_email
|
120 |
$order_billing_first_name = method_exists( $order, 'get_billing_first_name' ) ? $order->get_billing_first_name() : $order->billing_first_name;
|
121 |
-
$order_billing_last_name
|
122 |
|
123 |
$list_id = $this->sswcmc->get_list();
|
124 |
|
125 |
-
$this->log( sprintf( __(
|
126 |
|
127 |
// Queue the subscription.
|
128 |
as_schedule_single_action( time(), 'queue_ss_wc_mailchimp_maybe_subscribe', array( $order_id ), 'sswcmc' );
|
@@ -140,17 +148,19 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
140 |
|
141 |
try {
|
142 |
|
|
|
|
|
143 |
if ( ! isset( $_POST['data'] ) ) {
|
144 |
-
throw new Exception( __(
|
145 |
}
|
146 |
|
147 |
-
if ( ! $_POST['data']['api_key'] || empty( $_POST['data']['api_key'] ) ) {
|
148 |
|
149 |
throw new Exception( __( 'Please enter an api key.', 'woocommerce-mailchimp' ) );
|
150 |
|
151 |
}
|
152 |
|
153 |
-
$api_key = sanitize_text_field( $_POST['data']['api_key'] );
|
154 |
|
155 |
$account = $this->sswcmc->mailchimp()->get_account( $api_key );
|
156 |
|
@@ -158,11 +168,11 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
158 |
|
159 |
} catch ( Exception $e ) {
|
160 |
|
161 |
-
return $this->
|
162 |
|
163 |
}
|
164 |
|
165 |
-
return $this->
|
166 |
|
167 |
} //end function ajax_get_account
|
168 |
|
@@ -176,13 +186,15 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
176 |
|
177 |
try {
|
178 |
|
179 |
-
|
180 |
|
181 |
-
|
|
|
|
|
182 |
|
183 |
}
|
184 |
|
185 |
-
$api_key = sanitize_text_field( $_POST['data']['api_key'] );
|
186 |
|
187 |
$lists = $this->sswcmc->mailchimp( $api_key )->get_lists();
|
188 |
|
@@ -190,11 +202,11 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
190 |
|
191 |
} catch ( Exception $e ) {
|
192 |
|
193 |
-
return $this->
|
194 |
|
195 |
}
|
196 |
|
197 |
-
return $this->
|
198 |
|
199 |
} //end function ajax_get_lists
|
200 |
|
@@ -208,20 +220,22 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
208 |
|
209 |
try {
|
210 |
|
211 |
-
|
|
|
|
|
212 |
|
213 |
-
return $this->
|
214 |
|
215 |
}
|
216 |
|
217 |
-
if ( ! $_POST['data']['list_id'] || empty( $_POST['data']['list_id'] ) ) {
|
218 |
|
219 |
-
return $this->
|
220 |
|
221 |
}
|
222 |
|
223 |
-
$api_key = sanitize_text_field( $_POST['data']['api_key'] );
|
224 |
-
$list_id = sanitize_text_field( $_POST['data']['list_id'] );
|
225 |
|
226 |
$interest_groups = $this->sswcmc->mailchimp( $api_key )->get_interest_categories_with_interests( $list_id );
|
227 |
|
@@ -229,11 +243,11 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
229 |
|
230 |
} catch ( Exception $e ) {
|
231 |
|
232 |
-
return $this->
|
233 |
|
234 |
}
|
235 |
|
236 |
-
return $this->
|
237 |
|
238 |
} //end function ajax_get_interest_groups
|
239 |
|
@@ -247,20 +261,22 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
247 |
|
248 |
try {
|
249 |
|
250 |
-
|
251 |
|
252 |
-
|
|
|
|
|
253 |
|
254 |
}
|
255 |
|
256 |
-
if ( ! $_POST['data']['list_id'] || empty( $_POST['data']['list_id'] ) ) {
|
257 |
|
258 |
-
return $this->
|
259 |
|
260 |
}
|
261 |
|
262 |
-
$api_key = sanitize_text_field( $_POST['data']['api_key'] );
|
263 |
-
$list_id = sanitize_text_field( $_POST['data']['list_id'] );
|
264 |
|
265 |
$tags = $this->sswcmc->mailchimp( $api_key )->get_tags( $list_id );
|
266 |
|
@@ -268,11 +284,11 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
268 |
|
269 |
} catch ( Exception $e ) {
|
270 |
|
271 |
-
return $this->
|
272 |
|
273 |
}
|
274 |
|
275 |
-
return $this->
|
276 |
|
277 |
} //end function ajax_get_tags
|
278 |
|
@@ -286,44 +302,47 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
286 |
|
287 |
try {
|
288 |
|
289 |
-
|
|
|
|
|
290 |
|
291 |
-
return $this->
|
292 |
|
293 |
}
|
294 |
|
295 |
-
if (
|
296 |
|
297 |
-
return $this->
|
298 |
|
299 |
}
|
300 |
|
301 |
-
$api_key = sanitize_text_field( $_POST['data']['api_key'] );
|
302 |
-
$list_id = sanitize_text_field( $_POST['data']['list_id'] );
|
303 |
|
304 |
$merge_fields = $this->sswcmc->mailchimp( $api_key )->get_merge_fields( $list_id );
|
305 |
|
306 |
$results = $merge_fields;
|
307 |
|
308 |
-
}
|
309 |
-
catch ( Exception $e ) {
|
310 |
|
311 |
-
return $this->
|
312 |
|
313 |
}
|
314 |
|
315 |
-
return $this->
|
316 |
|
317 |
} //end function ajax_get_merge_fields
|
318 |
|
319 |
-
|
|
|
|
|
|
|
|
|
|
|
320 |
|
321 |
-
|
322 |
-
// header('Content-Type: application/json');
|
323 |
-
echo json_encode( $response );
|
324 |
-
exit();
|
325 |
|
326 |
-
} //end function
|
327 |
|
328 |
/**
|
329 |
* WooCommerce 2.2 support for wc_get_order
|
@@ -331,8 +350,9 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
331 |
* @since 1.2.1
|
332 |
*
|
333 |
* @access private
|
334 |
-
* @param int $order_id
|
335 |
-
*
|
|
|
336 |
*/
|
337 |
private function wc_get_order( $order_id ) {
|
338 |
if ( function_exists( 'wc_get_order' ) ) {
|
@@ -344,43 +364,41 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
344 |
|
345 |
/**
|
346 |
* Get message
|
|
|
|
|
|
|
347 |
* @return string Error
|
348 |
*/
|
349 |
private function get_message( $message, $type = 'error' ) {
|
350 |
ob_start();
|
351 |
|
352 |
?>
|
353 |
-
<div class="<?php echo $type ?>">
|
354 |
-
<p><?php echo $message ?></p>
|
355 |
</div>
|
356 |
<?php
|
357 |
return ob_get_clean();
|
358 |
}
|
359 |
|
360 |
/**
|
361 |
-
*
|
362 |
*
|
363 |
* @access public
|
364 |
-
* @param
|
365 |
-
* @param int $order_id
|
366 |
-
* @param mixed $first_name
|
367 |
-
* @param mixed $last_name
|
368 |
-
* @param mixed $email
|
369 |
-
* @param string $listid (default: 'false')
|
370 |
* @return void
|
371 |
*/
|
372 |
public function maybe_subscribe( $order_id ) {
|
373 |
|
374 |
-
//
|
375 |
$subscribe_customer = get_post_meta( $order_id, 'ss_wc_mailchimp_opt_in', true );
|
376 |
|
377 |
-
// Get the subscribe options
|
378 |
$subscribe_options = $this->sswcmc->get_subscribe_options_for_order( $order_id );
|
379 |
|
380 |
-
$email
|
381 |
$list_id = $subscribe_options['list_id'];
|
382 |
|
383 |
-
$this->log( sprintf( __(
|
384 |
|
385 |
if ( ! $email ) {
|
386 |
return; // Email is required.
|
@@ -402,30 +420,32 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
402 |
extract( $options );
|
403 |
|
404 |
// Log.
|
405 |
-
$this->log( sprintf( __(
|
406 |
|
407 |
do_action( 'ss_wc_mailchimp_before_subscribe', $subscribe_customer, $subscribe_options, $order_id );
|
408 |
|
409 |
// If the 'ss_wc_mailchimp_opt_in' meta value isn't set
|
410 |
// (because 'display_opt_in' wasn't enabled at the time the order was placed)
|
411 |
-
// or the 'ss_wc_mailchimp_opt_in' is yes, subscriber the customer
|
412 |
-
|
413 |
if ( ! empty( $list_id ) && ( ! $subscribe_customer || empty( $subscribe_customer ) || 'yes' === $subscribe_customer ) ) {
|
414 |
// Call API.
|
415 |
$api_response = $this->sswcmc->mailchimp()->subscribe( $list_id, $email, $email_type, $merge_tags, $interest_groups, $double_opt_in, $tags );
|
416 |
|
417 |
// Log api response.
|
418 |
-
$this->log( sprintf( __(
|
419 |
|
420 |
-
if (
|
421 |
// Format error message.
|
422 |
-
$error_response = sprintf( __(
|
423 |
|
424 |
// Log the error response.
|
425 |
$this->log( $error_response );
|
426 |
|
427 |
// New hook for failing operations.
|
428 |
-
do_action( 'ss_wc_mailchimp_subscription_failed', $email, array(
|
|
|
|
|
|
|
429 |
|
430 |
// Email admin.
|
431 |
$admin_email = get_option( 'admin_email' );
|
@@ -433,7 +453,10 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
433 |
wp_mail( $admin_email, __( 'WooCommerce Mailchimp subscription failed', 'woocommerce-mailchimp' ), $error_response );
|
434 |
} else {
|
435 |
// Hook on success.
|
436 |
-
do_action( 'ss_wc_mailchimp_subscription_success', $email, array(
|
|
|
|
|
|
|
437 |
}
|
438 |
}
|
439 |
|
@@ -446,21 +469,14 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
446 |
*
|
447 |
* @since 1.1
|
448 |
*/
|
449 |
-
function maybe_add_checkout_fields() {
|
450 |
|
451 |
if ( $this->sswcmc->is_valid() ) {
|
452 |
if ( $this->sswcmc->display_opt_in() ) {
|
453 |
do_action( 'ss_wc_mailchimp_before_opt_in_checkbox' );
|
454 |
|
455 |
-
echo apply_filters( 'ss_wc_mailchimp_opt_in_checkbox', '<p class="form-row woocommerce-mailchimp-opt-in"><label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox" for="ss_wc_mailchimp_opt_in"><input type="checkbox" name="ss_wc_mailchimp_opt_in" id="ss_wc_mailchimp_opt_in" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" value="yes"' . ($this->sswcmc->opt_in_checkbox_default_status()
|
456 |
-
|
457 |
-
// 'type' => 'checkbox',
|
458 |
-
// 'class' => array('woocommerce-mailchimp-opt-in'),
|
459 |
-
// 'label' => esc_html( $this->sswcmc->opt_in_label() ),
|
460 |
-
// 'custom_attributes' => array(
|
461 |
-
// 'for' => '2ss_wc_mailchimp_opt_in',
|
462 |
-
// ),
|
463 |
-
// ), $this->sswcmc->opt_in_checkbox_default_status() == 'checked' );
|
464 |
do_action( 'ss_wc_mailchimp_after_opt_in_checkbox' );
|
465 |
}
|
466 |
}
|
@@ -469,11 +485,13 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
469 |
/**
|
470 |
* When the checkout form is submitted, save opt-in value.
|
471 |
*
|
472 |
-
* @
|
|
|
|
|
473 |
*/
|
474 |
-
function maybe_save_checkout_fields( $order_id ) {
|
475 |
if ( $this->sswcmc->display_opt_in() ) {
|
476 |
-
$opt_in = isset( $_POST[
|
477 |
|
478 |
update_post_meta( $order_id, 'ss_wc_mailchimp_opt_in', $opt_in );
|
479 |
}
|
@@ -483,6 +501,8 @@ if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
|
483 |
* Helper log function for debugging
|
484 |
*
|
485 |
* @since 1.2.2
|
|
|
|
|
486 |
*/
|
487 |
private function log( $message ) {
|
488 |
if ( is_array( $message ) || is_object( $message ) ) {
|
2 |
/**
|
3 |
* WooCommerce MailChimp Handler
|
4 |
*
|
5 |
+
* @author Saint Systems
|
6 |
+
* @package WooCommerce MailChimp
|
7 |
+
* @version 2.0
|
8 |
*/
|
9 |
|
10 |
+
defined( 'ABSPATH' ) || exit;
|
11 |
|
12 |
if ( ! class_exists( 'SS_WC_MailChimp_Handler' ) ) {
|
13 |
|
14 |
/**
|
15 |
+
* Handler class.
|
16 |
+
*
|
17 |
* @class SS_WC_MailChimp_Handler
|
18 |
*/
|
19 |
final class SS_WC_MailChimp_Handler {
|
20 |
|
21 |
/**
|
22 |
* Plugin singleton instance
|
23 |
+
*
|
24 |
* @var SS_WC_MailChimp_Handler
|
25 |
*/
|
26 |
private static $instance = null;
|
33 |
*/
|
34 |
public function __construct() {
|
35 |
|
36 |
+
$this->id = 'mailchimp';
|
37 |
+
$this->namespace = 'ss_wc_' . $this->id;
|
38 |
+
$this->label = __( 'MailChimp', 'woocommerce-mailchimp' );
|
39 |
+
$this->sswcmc = SSWCMC();
|
40 |
$this->register_hooks();
|
41 |
|
42 |
} //end function __construct
|
43 |
|
44 |
/**
|
45 |
+
* Get the instance.
|
46 |
+
*
|
47 |
* @return SS_WC_MailChimp_Handler
|
48 |
*/
|
49 |
public static function get_instance() {
|
50 |
|
51 |
if ( empty( self::$instance ) ) {
|
52 |
+
self::$instance = new self();
|
53 |
}
|
54 |
|
55 |
return self::$instance;
|
65 |
public function register_hooks() {
|
66 |
|
67 |
// We would use the 'woocommerce_new_order' action but first name, last name and email address (order meta) is not yet available,
|
68 |
+
// so instead we use the 'woocommerce_checkout_update_order_meta' action hook which fires after the checkout process on the "thank you" page.
|
69 |
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'order_status_changed' ), 1000, 1 );
|
70 |
|
71 |
+
// Hook into woocommerce order status changed hook to handle the desired subscription event trigger.
|
72 |
add_action( 'woocommerce_order_status_changed', array( $this, 'order_status_changed' ), 10, 3 );
|
73 |
|
74 |
$opt_in_checkbox_display_location = $this->sswcmc->opt_in_checkbox_display_location();
|
75 |
|
76 |
+
// Maybe add an "opt-in" field to the checkout.
|
77 |
+
$opt_in_checkbox_display_location = ! empty( $opt_in_checkbox_display_location ) ? $opt_in_checkbox_display_location : 'woocommerce_review_order_before_submit';
|
78 |
|
79 |
+
// Old opt-in checkbox display locations.
|
80 |
$old_opt_in_checkbox_display_locations = array(
|
81 |
'billing' => 'woocommerce_after_checkout_billing_form',
|
82 |
+
'order' => 'woocommerce_review_order_before_submit',
|
83 |
);
|
84 |
|
85 |
+
// Map old billing/order checkbox display locations to new format.
|
86 |
if ( array_key_exists( $opt_in_checkbox_display_location, $old_opt_in_checkbox_display_locations ) ) {
|
87 |
$opt_in_checkbox_display_location = $old_opt_in_checkbox_display_locations[ $opt_in_checkbox_display_location ];
|
88 |
}
|
89 |
|
90 |
add_action( $opt_in_checkbox_display_location, array( $this, 'maybe_add_checkout_fields' ) );
|
91 |
|
92 |
+
// Maybe save the "opt-in" field on the checkout.
|
93 |
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'maybe_save_checkout_fields' ) );
|
94 |
|
95 |
add_action( 'wp_ajax_ss_wc_mailchimp_get_account', array( $this, 'ajax_get_account' ) );
|
107 |
} //end function ensure_tab
|
108 |
|
109 |
/**
|
110 |
+
* Order status changed function.
|
111 |
*
|
112 |
* @access public
|
113 |
+
* @param string $id The order id.
|
114 |
+
* @param string $status The current status.
|
115 |
+
* @param string $new_status The new status.
|
116 |
* @return void
|
117 |
*/
|
118 |
public function order_status_changed( $id, $status = 'new', $new_status = 'pending' ) {
|
119 |
if ( $this->sswcmc->is_valid() && $new_status === $this->sswcmc->occurs() ) {
|
120 |
+
// Get WC .
|
121 |
$order = $this->wc_get_order( $id );
|
122 |
|
123 |
+
// Get the ss_wc_mailchimp_opt_in value from the post meta ("order_custom_fields" was removed with WooCommerce 2.1).
|
124 |
$subscribe_customer = get_post_meta( $id, 'ss_wc_mailchimp_opt_in', true );
|
125 |
|
126 |
+
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
|
127 |
+
$order_billing_email = method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email;
|
128 |
$order_billing_first_name = method_exists( $order, 'get_billing_first_name' ) ? $order->get_billing_first_name() : $order->billing_first_name;
|
129 |
+
$order_billing_last_name = method_exists( $order, 'get_billing_last_name' ) ? $order->get_billing_last_name() : $order->billing_last_name;
|
130 |
|
131 |
$list_id = $this->sswcmc->get_list();
|
132 |
|
133 |
+
$this->log( sprintf( __( '%1$s(): Queueing maybe subscribe ($subscribe_customer: %2$s) for customer (%3$s) to list %4$s for order (%5$s)', 'woocommerce-mailchimp' ), __METHOD__, $subscribe_customer, $order_billing_email, $list_id, $order_id ) );
|
134 |
|
135 |
// Queue the subscription.
|
136 |
as_schedule_single_action( time(), 'queue_ss_wc_mailchimp_maybe_subscribe', array( $order_id ), 'sswcmc' );
|
148 |
|
149 |
try {
|
150 |
|
151 |
+
check_ajax_referer( 'sswcmc_get_account', 'nonce' );
|
152 |
+
|
153 |
if ( ! isset( $_POST['data'] ) ) {
|
154 |
+
throw new Exception( __( '$_POST[\'data\'] not provided.', 'woocommerce-mailchimp' ) );
|
155 |
}
|
156 |
|
157 |
+
if ( ! isset( $_POST['data']['api_key'] ) || empty( $_POST['data']['api_key'] ) ) {
|
158 |
|
159 |
throw new Exception( __( 'Please enter an api key.', 'woocommerce-mailchimp' ) );
|
160 |
|
161 |
}
|
162 |
|
163 |
+
$api_key = sanitize_text_field( wp_unslash( $_POST['data']['api_key'] ) );
|
164 |
|
165 |
$account = $this->sswcmc->mailchimp()->get_account( $api_key );
|
166 |
|
168 |
|
169 |
} catch ( Exception $e ) {
|
170 |
|
171 |
+
return $this->to_json( array( 'error' => $e->getMessage() ) );
|
172 |
|
173 |
}
|
174 |
|
175 |
+
return $this->to_json( $results );
|
176 |
|
177 |
} //end function ajax_get_account
|
178 |
|
186 |
|
187 |
try {
|
188 |
|
189 |
+
check_ajax_referer( 'sswcmc_get_lists', 'nonce' );
|
190 |
|
191 |
+
if ( ! isset( $_POST['data']['api_key'] ) || empty( $_POST['data']['api_key'] ) ) {
|
192 |
+
|
193 |
+
return $this->to_json( array( '' => __( 'Enter your api key above to see your lists', 'woocommerce-mailchimp' ) ) );
|
194 |
|
195 |
}
|
196 |
|
197 |
+
$api_key = sanitize_text_field( wp_unslash( $_POST['data']['api_key'] ) );
|
198 |
|
199 |
$lists = $this->sswcmc->mailchimp( $api_key )->get_lists();
|
200 |
|
202 |
|
203 |
} catch ( Exception $e ) {
|
204 |
|
205 |
+
return $this->to_json( array( 'error' => $e->getMessage() ) );
|
206 |
|
207 |
}
|
208 |
|
209 |
+
return $this->to_json( $results );
|
210 |
|
211 |
} //end function ajax_get_lists
|
212 |
|
220 |
|
221 |
try {
|
222 |
|
223 |
+
check_ajax_referer( 'sswcmc_get_interest_groups', 'nonce' );
|
224 |
+
|
225 |
+
if ( ! isset( $_POST['data']['api_key'] ) || empty( $_POST['data']['api_key'] ) ) {
|
226 |
|
227 |
+
return $this->to_json( array( '' => __( 'Enter your api key above to see your lists', 'ss_wc_mailchimp' ) ) );
|
228 |
|
229 |
}
|
230 |
|
231 |
+
if ( ! isset( $_POST['data']['list_id'] ) || empty( $_POST['data']['list_id'] ) ) {
|
232 |
|
233 |
+
return $this->to_json( array( '' => __( 'Please select a list from above.', 'ss_wc_mailchimp' ) ) );
|
234 |
|
235 |
}
|
236 |
|
237 |
+
$api_key = sanitize_text_field( wp_unslash( $_POST['data']['api_key'] ) );
|
238 |
+
$list_id = sanitize_text_field( wp_unslash( $_POST['data']['list_id'] ) );
|
239 |
|
240 |
$interest_groups = $this->sswcmc->mailchimp( $api_key )->get_interest_categories_with_interests( $list_id );
|
241 |
|
243 |
|
244 |
} catch ( Exception $e ) {
|
245 |
|
246 |
+
return $this->to_json( array( 'error' => $e->getMessage() ) );
|
247 |
|
248 |
}
|
249 |
|
250 |
+
return $this->to_json( $results );
|
251 |
|
252 |
} //end function ajax_get_interest_groups
|
253 |
|
261 |
|
262 |
try {
|
263 |
|
264 |
+
check_ajax_referer( 'sswcmc_get_tags', 'nonce' );
|
265 |
|
266 |
+
if ( ! isset( $_POST['data']['api_key'] ) || empty( $_POST['data']['api_key'] ) ) {
|
267 |
+
|
268 |
+
return $this->to_json( array( '' => __( 'Enter your api key above to see your lists', 'ss_wc_mailchimp' ) ) );
|
269 |
|
270 |
}
|
271 |
|
272 |
+
if ( ! isset( $_POST['data']['list_id'] ) || empty( $_POST['data']['list_id'] ) ) {
|
273 |
|
274 |
+
return $this->to_json( array( '' => __( 'Please select a list from above.', 'ss_wc_mailchimp' ) ) );
|
275 |
|
276 |
}
|
277 |
|
278 |
+
$api_key = sanitize_text_field( wp_unslash( $_POST['data']['api_key'] ) );
|
279 |
+
$list_id = sanitize_text_field( wp_unslash( $_POST['data']['list_id'] ) );
|
280 |
|
281 |
$tags = $this->sswcmc->mailchimp( $api_key )->get_tags( $list_id );
|
282 |
|
284 |
|
285 |
} catch ( Exception $e ) {
|
286 |
|
287 |
+
return $this->to_json( array( 'error' => $e->getMessage() ) );
|
288 |
|
289 |
}
|
290 |
|
291 |
+
return $this->to_json( $results );
|
292 |
|
293 |
} //end function ajax_get_tags
|
294 |
|
302 |
|
303 |
try {
|
304 |
|
305 |
+
check_ajax_referer( 'sswcmc_get_merge_fields', 'nonce' );
|
306 |
+
|
307 |
+
if ( ! isset( $_POST['data']['api_key'] ) || empty( $_POST['data']['api_key'] ) ) {
|
308 |
|
309 |
+
return $this->to_json( array( '' => __( 'Please enter your api key above.', 'ss_wc_mailchimp' ) ) );
|
310 |
|
311 |
}
|
312 |
|
313 |
+
if ( ! isset( $_POST['data']['list_id'] ) || empty( $_POST['data']['list_id'] ) ) {
|
314 |
|
315 |
+
return $this->to_json( array( '' => __( 'Please select a list from above.', 'ss_wc_mailchimp' ) ) );
|
316 |
|
317 |
}
|
318 |
|
319 |
+
$api_key = sanitize_text_field( wp_unslash( $_POST['data']['api_key'] ) );
|
320 |
+
$list_id = sanitize_text_field( wp_unslash( $_POST['data']['list_id'] ) );
|
321 |
|
322 |
$merge_fields = $this->sswcmc->mailchimp( $api_key )->get_merge_fields( $list_id );
|
323 |
|
324 |
$results = $merge_fields;
|
325 |
|
326 |
+
} catch ( Exception $e ) {
|
|
|
327 |
|
328 |
+
return $this->to_json( array( 'error' => $e->getMessage() ) );
|
329 |
|
330 |
}
|
331 |
|
332 |
+
return $this->to_json( $results );
|
333 |
|
334 |
} //end function ajax_get_merge_fields
|
335 |
|
336 |
+
/**
|
337 |
+
* Send the Json back to the client.
|
338 |
+
*
|
339 |
+
* @param mixed $response The response to send.
|
340 |
+
*/
|
341 |
+
private function to_json( $response ) {
|
342 |
|
343 |
+
wp_send_json( $response, '200' );
|
|
|
|
|
|
|
344 |
|
345 |
+
} //end function to_json
|
346 |
|
347 |
/**
|
348 |
* WooCommerce 2.2 support for wc_get_order
|
350 |
* @since 1.2.1
|
351 |
*
|
352 |
* @access private
|
353 |
+
* @param int $order_id The order id.
|
354 |
+
*
|
355 |
+
* @return WC_Order The order.
|
356 |
*/
|
357 |
private function wc_get_order( $order_id ) {
|
358 |
if ( function_exists( 'wc_get_order' ) ) {
|
364 |
|
365 |
/**
|
366 |
* Get message
|
367 |
+
*
|
368 |
+
* @param string $message The message.
|
369 |
+
* @param string $type The message type.
|
370 |
* @return string Error
|
371 |
*/
|
372 |
private function get_message( $message, $type = 'error' ) {
|
373 |
ob_start();
|
374 |
|
375 |
?>
|
376 |
+
<div class="<?php echo esc_attr( $type ); ?>">
|
377 |
+
<p><?php echo esc_html( $message ); ?></p>
|
378 |
</div>
|
379 |
<?php
|
380 |
return ob_get_clean();
|
381 |
}
|
382 |
|
383 |
/**
|
384 |
+
* Subscribe function.
|
385 |
*
|
386 |
* @access public
|
387 |
+
* @param int $order_id The order id.
|
|
|
|
|
|
|
|
|
|
|
388 |
* @return void
|
389 |
*/
|
390 |
public function maybe_subscribe( $order_id ) {
|
391 |
|
392 |
+
// Get the ss_wc_mailchimp_opt_in value from the post meta ("order_custom_fields" was removed with WooCommerce 2.1).
|
393 |
$subscribe_customer = get_post_meta( $order_id, 'ss_wc_mailchimp_opt_in', true );
|
394 |
|
395 |
+
// Get the subscribe options.
|
396 |
$subscribe_options = $this->sswcmc->get_subscribe_options_for_order( $order_id );
|
397 |
|
398 |
+
$email = $subscribe_options['email'];
|
399 |
$list_id = $subscribe_options['list_id'];
|
400 |
|
401 |
+
$this->log( sprintf( __( '%1$s(): Processing queued maybe_subscribe ($subscribe_customer: %2$s) for customer (%3$s) to list %4$s for order (%5$s)', 'woocommerce-mailchimp' ), __METHOD__, $subscribe_customer, $email, $list_id, $order_id ) );
|
402 |
|
403 |
if ( ! $email ) {
|
404 |
return; // Email is required.
|
420 |
extract( $options );
|
421 |
|
422 |
// Log.
|
423 |
+
$this->log( sprintf( __( '%1$s(): Maybe subscribing customer ($subscribe_customer: %2$s) to MailChimp: %3$s', 'woocommerce-mailchimp' ), __METHOD__, $subscribe_customer, print_r( $options, true ) ) );
|
424 |
|
425 |
do_action( 'ss_wc_mailchimp_before_subscribe', $subscribe_customer, $subscribe_options, $order_id );
|
426 |
|
427 |
// If the 'ss_wc_mailchimp_opt_in' meta value isn't set
|
428 |
// (because 'display_opt_in' wasn't enabled at the time the order was placed)
|
429 |
+
// or the 'ss_wc_mailchimp_opt_in' is yes, subscriber the customer.
|
|
|
430 |
if ( ! empty( $list_id ) && ( ! $subscribe_customer || empty( $subscribe_customer ) || 'yes' === $subscribe_customer ) ) {
|
431 |
// Call API.
|
432 |
$api_response = $this->sswcmc->mailchimp()->subscribe( $list_id, $email, $email_type, $merge_tags, $interest_groups, $double_opt_in, $tags );
|
433 |
|
434 |
// Log api response.
|
435 |
+
$this->log( sprintf( __( '%1$s(): MailChimp API response: %2$s', 'woocommerce-mailchimp' ), __METHOD__, print_r( $api_response, true ) ) );
|
436 |
|
437 |
+
if ( false === $api_response ) {
|
438 |
// Format error message.
|
439 |
+
$error_response = sprintf( __( '%1$s(): WooCommerce MailChimp subscription failed: %2$s (%3$s)', 'woocommerce-mailchimp' ), __METHOD__, $this->sswcmc->mailchimp()->get_error_message(), $this->sswcmc->mailchimp()->get_error_code() );
|
440 |
|
441 |
// Log the error response.
|
442 |
$this->log( $error_response );
|
443 |
|
444 |
// New hook for failing operations.
|
445 |
+
do_action( 'ss_wc_mailchimp_subscription_failed', $email, array(
|
446 |
+
'list_id' => $list_id,
|
447 |
+
'order_id' => $order_id,
|
448 |
+
) );
|
449 |
|
450 |
// Email admin.
|
451 |
$admin_email = get_option( 'admin_email' );
|
453 |
wp_mail( $admin_email, __( 'WooCommerce Mailchimp subscription failed', 'woocommerce-mailchimp' ), $error_response );
|
454 |
} else {
|
455 |
// Hook on success.
|
456 |
+
do_action( 'ss_wc_mailchimp_subscription_success', $email, array(
|
457 |
+
'list_id' => $list_id,
|
458 |
+
'order_id' => $order_id,
|
459 |
+
) );
|
460 |
}
|
461 |
}
|
462 |
|
469 |
*
|
470 |
* @since 1.1
|
471 |
*/
|
472 |
+
public function maybe_add_checkout_fields() {
|
473 |
|
474 |
if ( $this->sswcmc->is_valid() ) {
|
475 |
if ( $this->sswcmc->display_opt_in() ) {
|
476 |
do_action( 'ss_wc_mailchimp_before_opt_in_checkbox' );
|
477 |
|
478 |
+
echo wp_kses_post( apply_filters( 'ss_wc_mailchimp_opt_in_checkbox', '<p class="form-row woocommerce-mailchimp-opt-in"><label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox" for="ss_wc_mailchimp_opt_in"><input type="checkbox" name="ss_wc_mailchimp_opt_in" id="ss_wc_mailchimp_opt_in" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" value="yes"' . ( $this->sswcmc->opt_in_checkbox_default_status() === 'checked' ? ' checked="checked"' : '' ) . '/><span class="woocommerce-mailchimp-opt-in-checkbox-text">' . $this->sswcmc->opt_in_label() . '</span></label></p>' . "\n", $this->sswcmc->opt_in_checkbox_default_status(), $this->sswcmc->opt_in_label(), $this->sswcmc->opt_in_checkbox_default_status(), $this->sswcmc->opt_in_label() ) );
|
479 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
480 |
do_action( 'ss_wc_mailchimp_after_opt_in_checkbox' );
|
481 |
}
|
482 |
}
|
485 |
/**
|
486 |
* When the checkout form is submitted, save opt-in value.
|
487 |
*
|
488 |
+
* @since 1.1
|
489 |
+
*
|
490 |
+
* @param string $order_id The order id.
|
491 |
*/
|
492 |
+
public function maybe_save_checkout_fields( $order_id ) {
|
493 |
if ( $this->sswcmc->display_opt_in() ) {
|
494 |
+
$opt_in = isset( $_POST['ss_wc_mailchimp_opt_in'] ) ? 'yes' : 'no';
|
495 |
|
496 |
update_post_meta( $order_id, 'ss_wc_mailchimp_opt_in', $opt_in );
|
497 |
}
|
501 |
* Helper log function for debugging
|
502 |
*
|
503 |
* @since 1.2.2
|
504 |
+
*
|
505 |
+
* @param string $message The message.
|
506 |
*/
|
507 |
private function log( $message ) {
|
508 |
if ( is_array( $message ) || is_object( $message ) ) {
|
includes/class-ss-wc-mailchimp-plugin.php
CHANGED
@@ -15,7 +15,7 @@ final class SS_WC_MailChimp_Plugin {
|
|
15 |
*
|
16 |
* @var string
|
17 |
*/
|
18 |
-
private static $version = '2.3.
|
19 |
|
20 |
/**
|
21 |
* Plugin singleton instance
|
@@ -103,7 +103,7 @@ final class SS_WC_MailChimp_Plugin {
|
|
103 |
|
104 |
if ( empty( $this->settings ) || true === $refresh ) {
|
105 |
|
106 |
-
$defaults = require
|
107 |
$defaults = apply_filters( 'ss_wc_mailchimp_default_settings', $defaults );
|
108 |
$settings = array();
|
109 |
|
@@ -253,17 +253,17 @@ final class SS_WC_MailChimp_Plugin {
|
|
253 |
*
|
254 |
* @since 2.3.2
|
255 |
* @access public
|
256 |
-
* @param $order_id
|
257 |
*/
|
258 |
public function get_subscribe_options_for_order( $order_id ) {
|
259 |
|
260 |
-
// Get WC order
|
261 |
$order = wc_get_order( $order_id );
|
262 |
|
263 |
-
$order_id
|
264 |
-
$email
|
265 |
$first_name = method_exists( $order, 'get_billing_first_name' ) ? $order->get_billing_first_name() : $order->billing_first_name;
|
266 |
-
$last_name
|
267 |
|
268 |
$list_id = $this->get_list();
|
269 |
|
@@ -288,20 +288,20 @@ final class SS_WC_MailChimp_Plugin {
|
|
288 |
|
289 |
$tags = array_map( function( $tag ) use ( $mc_tags ) {
|
290 |
return array(
|
291 |
-
'name'
|
292 |
'status' => 'active',
|
293 |
);
|
294 |
}, $tags );
|
295 |
|
296 |
// Set subscription options.
|
297 |
$subscribe_options = array(
|
298 |
-
'list_id'
|
299 |
-
'email'
|
300 |
-
'merge_tags'
|
301 |
-
'interest_groups'
|
302 |
-
'tags'
|
303 |
-
'email_type'
|
304 |
-
'double_opt_in'
|
305 |
);
|
306 |
|
307 |
return $subscribe_options;
|
@@ -370,7 +370,7 @@ final class SS_WC_MailChimp_Plugin {
|
|
370 |
$api_key = $api_key ? $api_key : $settings['api_key'];
|
371 |
$debug = $debug ? $debug : $settings['debug'];
|
372 |
|
373 |
-
require_once
|
374 |
$this->mailchimp = new SS_WC_MailChimp( $api_key, $debug );
|
375 |
|
376 |
delete_transient( 'sswcmc_lists' );
|
@@ -429,21 +429,21 @@ final class SS_WC_MailChimp_Plugin {
|
|
429 |
*/
|
430 |
public function includes() {
|
431 |
|
432 |
-
require_once
|
433 |
|
434 |
-
require_once
|
435 |
|
436 |
-
require_once
|
437 |
|
438 |
-
require_once
|
439 |
|
440 |
-
require_once
|
441 |
|
442 |
-
require_once
|
443 |
|
444 |
-
require_once
|
445 |
|
446 |
-
require_once
|
447 |
|
448 |
} //end function includes
|
449 |
|
@@ -497,10 +497,10 @@ final class SS_WC_MailChimp_Plugin {
|
|
497 |
|
498 |
$mofile = sprintf( '%1$s-%2$s.mo', 'woocommerce-mailchimp', $locale );
|
499 |
|
500 |
-
// Look for wp-content/languages/woocommerce-mailchimp/woocommerce-mailchimp-{lang}_{country}.mo
|
501 |
$mofile_global1 = WP_LANG_DIR . '/woocommerce-mailchimp/' . $mofile;
|
502 |
|
503 |
-
// Look in wp-content/languages/plugins/woocommerce-mailchimp
|
504 |
$mofile_global2 = WP_LANG_DIR . '/plugins/woocommerce-mailchimp/' . $mofile;
|
505 |
|
506 |
if ( file_exists( $mofile_global1 ) ) {
|
@@ -565,13 +565,13 @@ final class SS_WC_MailChimp_Plugin {
|
|
565 |
* @param array $settings MailChimp settings.
|
566 |
* @return array Settings.
|
567 |
*/
|
568 |
-
function add_mailchimp_settings( $settings ) {
|
569 |
|
570 |
if ( ! is_array( $settings ) ) {
|
571 |
$settings = array();
|
572 |
}
|
573 |
|
574 |
-
$settings[] = require_once
|
575 |
|
576 |
return $settings;
|
577 |
|
@@ -590,7 +590,7 @@ final class SS_WC_MailChimp_Plugin {
|
|
590 |
wp_register_style( 'woocommerce-mailchimp', SS_WC_MAILCHIMP_URL . 'assets/css/style.css', array(), self::version() );
|
591 |
|
592 |
// Localize javascript messages.
|
593 |
-
$
|
594 |
'connecting_to_mailchimp' => __( 'Connecting to Mailchimp', 'woocommerce-mailchimp' ),
|
595 |
'error_loading_account' => __( 'Error. Please check your api key.', 'woocommerce-mailchimp' ),
|
596 |
'error_loading_groups' => __( 'Error loading groups. Please check your Mailchimp Interest Groups for the selected list.', 'woocommerce-mailchimp' ),
|
@@ -600,7 +600,21 @@ final class SS_WC_MailChimp_Plugin {
|
|
600 |
'select_tags_placeholder' => __( 'Select one or more tags (optional)', 'woocommerce-mailchimp' ),
|
601 |
'tags_not_enabled' => __( 'This list does not have tags enabled', 'woocommerce-mailchimp' ),
|
602 |
);
|
603 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
604 |
|
605 |
// Scripts.
|
606 |
wp_enqueue_script( 'woocommerce-mailchimp-admin' );
|
@@ -637,7 +651,7 @@ final class SS_WC_MailChimp_Plugin {
|
|
637 |
*/
|
638 |
public static function update() {
|
639 |
|
640 |
-
require_once
|
641 |
|
642 |
SS_WC_MailChimp_Migrator::migrate( self::version() );
|
643 |
|
15 |
*
|
16 |
* @var string
|
17 |
*/
|
18 |
+
private static $version = '2.3.5';
|
19 |
|
20 |
/**
|
21 |
* Plugin singleton instance
|
103 |
|
104 |
if ( empty( $this->settings ) || true === $refresh ) {
|
105 |
|
106 |
+
$defaults = require SS_WC_MAILCHIMP_DIR . 'config/default-settings.php';
|
107 |
$defaults = apply_filters( 'ss_wc_mailchimp_default_settings', $defaults );
|
108 |
$settings = array();
|
109 |
|
253 |
*
|
254 |
* @since 2.3.2
|
255 |
* @access public
|
256 |
+
* @param int $order_id The order id.
|
257 |
*/
|
258 |
public function get_subscribe_options_for_order( $order_id ) {
|
259 |
|
260 |
+
// Get WC order.
|
261 |
$order = wc_get_order( $order_id );
|
262 |
|
263 |
+
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
|
264 |
+
$email = method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email;
|
265 |
$first_name = method_exists( $order, 'get_billing_first_name' ) ? $order->get_billing_first_name() : $order->billing_first_name;
|
266 |
+
$last_name = method_exists( $order, 'get_billing_last_name' ) ? $order->get_billing_last_name() : $order->billing_last_name;
|
267 |
|
268 |
$list_id = $this->get_list();
|
269 |
|
288 |
|
289 |
$tags = array_map( function( $tag ) use ( $mc_tags ) {
|
290 |
return array(
|
291 |
+
'name' => $mc_tags[ $tag ],
|
292 |
'status' => 'active',
|
293 |
);
|
294 |
}, $tags );
|
295 |
|
296 |
// Set subscription options.
|
297 |
$subscribe_options = array(
|
298 |
+
'list_id' => $list_id,
|
299 |
+
'email' => $email,
|
300 |
+
'merge_tags' => $merge_tags,
|
301 |
+
'interest_groups' => $interest_groups,
|
302 |
+
'tags' => $tags,
|
303 |
+
'email_type' => 'html',
|
304 |
+
'double_opt_in' => $this->double_opt_in(),
|
305 |
);
|
306 |
|
307 |
return $subscribe_options;
|
370 |
$api_key = $api_key ? $api_key : $settings['api_key'];
|
371 |
$debug = $debug ? $debug : $settings['debug'];
|
372 |
|
373 |
+
require_once SS_WC_MAILCHIMP_DIR . 'includes/class-ss-wc-mailchimp.php';
|
374 |
$this->mailchimp = new SS_WC_MailChimp( $api_key, $debug );
|
375 |
|
376 |
delete_transient( 'sswcmc_lists' );
|
429 |
*/
|
430 |
public function includes() {
|
431 |
|
432 |
+
require_once SS_WC_MAILCHIMP_DIR . 'includes/lib/class-ss-system-info.php';
|
433 |
|
434 |
+
require_once SS_WC_MAILCHIMP_DIR . 'includes/helper-functions.php';
|
435 |
|
436 |
+
require_once SS_WC_MAILCHIMP_DIR . 'includes/class-ss-wc-mailchimp-compatibility.php';
|
437 |
|
438 |
+
require_once SS_WC_MAILCHIMP_DIR . 'includes/class-ss-wc-mailchimp-admin-notices.php';
|
439 |
|
440 |
+
require_once SS_WC_MAILCHIMP_DIR . 'includes/class-ss-wc-mailchimp-api.php';
|
441 |
|
442 |
+
require_once SS_WC_MAILCHIMP_DIR . 'includes/class-ss-wc-mailchimp.php';
|
443 |
|
444 |
+
require_once SS_WC_MAILCHIMP_DIR . 'includes/class-ss-wc-mailchimp-handler.php';
|
445 |
|
446 |
+
require_once SS_WC_MAILCHIMP_DIR . 'includes/class-sswcmc-logger.php';
|
447 |
|
448 |
} //end function includes
|
449 |
|
497 |
|
498 |
$mofile = sprintf( '%1$s-%2$s.mo', 'woocommerce-mailchimp', $locale );
|
499 |
|
500 |
+
// Look for wp-content/languages/woocommerce-mailchimp/woocommerce-mailchimp-{lang}_{country}.mo.
|
501 |
$mofile_global1 = WP_LANG_DIR . '/woocommerce-mailchimp/' . $mofile;
|
502 |
|
503 |
+
// Look in wp-content/languages/plugins/woocommerce-mailchimp.
|
504 |
$mofile_global2 = WP_LANG_DIR . '/plugins/woocommerce-mailchimp/' . $mofile;
|
505 |
|
506 |
if ( file_exists( $mofile_global1 ) ) {
|
565 |
* @param array $settings MailChimp settings.
|
566 |
* @return array Settings.
|
567 |
*/
|
568 |
+
public function add_mailchimp_settings( $settings ) {
|
569 |
|
570 |
if ( ! is_array( $settings ) ) {
|
571 |
$settings = array();
|
572 |
}
|
573 |
|
574 |
+
$settings[] = require_once SS_WC_MAILCHIMP_DIR . 'includes/class-ss-wc-settings-mailchimp.php';
|
575 |
|
576 |
return $settings;
|
577 |
|
590 |
wp_register_style( 'woocommerce-mailchimp', SS_WC_MAILCHIMP_URL . 'assets/css/style.css', array(), self::version() );
|
591 |
|
592 |
// Localize javascript messages.
|
593 |
+
$translations = array(
|
594 |
'connecting_to_mailchimp' => __( 'Connecting to Mailchimp', 'woocommerce-mailchimp' ),
|
595 |
'error_loading_account' => __( 'Error. Please check your api key.', 'woocommerce-mailchimp' ),
|
596 |
'error_loading_groups' => __( 'Error loading groups. Please check your Mailchimp Interest Groups for the selected list.', 'woocommerce-mailchimp' ),
|
600 |
'select_tags_placeholder' => __( 'Select one or more tags (optional)', 'woocommerce-mailchimp' ),
|
601 |
'tags_not_enabled' => __( 'This list does not have tags enabled', 'woocommerce-mailchimp' ),
|
602 |
);
|
603 |
+
|
604 |
+
$nonces = array(
|
605 |
+
'get_account' => wp_create_nonce( 'sswcmc_get_account' ),
|
606 |
+
'get_lists' => wp_create_nonce( 'sswcmc_get_lists' ),
|
607 |
+
'get_interest_groups' => wp_create_nonce( 'sswcmc_get_interest_groups' ),
|
608 |
+
'get_tags' => wp_create_nonce( 'sswcmc_get_tags' ),
|
609 |
+
'get_merge_fields' => wp_create_nonce( 'sswcmc_merge_fields' ),
|
610 |
+
);
|
611 |
+
|
612 |
+
$sswcmc = array(
|
613 |
+
'messages' => $translations,
|
614 |
+
'nonces' => $nonces,
|
615 |
+
);
|
616 |
+
|
617 |
+
wp_localize_script( 'woocommerce-mailchimp-admin', 'SSWCMC', $sswcmc );
|
618 |
|
619 |
// Scripts.
|
620 |
wp_enqueue_script( 'woocommerce-mailchimp-admin' );
|
651 |
*/
|
652 |
public static function update() {
|
653 |
|
654 |
+
require_once 'class-ss-wc-mailchimp-migrator.php';
|
655 |
|
656 |
SS_WC_MailChimp_Migrator::migrate( self::version() );
|
657 |
|
readme.txt
CHANGED
@@ -6,7 +6,7 @@ Requires at least: 4.7.0
|
|
6 |
Tested up to: 5.2.2
|
7 |
WC tested up to: 3.7.0
|
8 |
Requires PHP: 5.6
|
9 |
-
Stable tag: 2.3.
|
10 |
License: GPLv3
|
11 |
|
12 |
Simple and flexible Mailchimp integration for WooCommerce.
|
@@ -78,19 +78,19 @@ If no custom translations are present, languages will be loaded in the following
|
|
78 |
|
79 |
= Requirements =
|
80 |
|
81 |
-
WooCommerce Mailchimp requires PHP 5.6+ (PHP 7.0+ recommended). You'll also need to be running WordPress 4.7.0+ and have WooCommerce 3.5.0+.
|
82 |
|
83 |
= Documentation & Support =
|
84 |
|
85 |
Online documentation and code samples are available via our [Help Center](https://support.saintsystems.com/hc/en-us/sections/201959566).
|
86 |
|
87 |
Please visit the
|
88 |
-
[WooCommerce MailChimp support forum on WordPress.org](https://wordpress.org/support/plugin/woocommerce-mailchimp) for basic support and help from other users. Since this is a free plugin, we respond to these as we have time.
|
89 |
|
90 |
-
Dedicated support will is available for [WooCommerce MailChimp Pro](https://www.saintsystems.com/products/woocommerce-mailchimp-pro/) customers.
|
91 |
|
92 |
= Contribute =
|
93 |
-
All development for WooCommerce MailChimp is [handled via GitHub](https://github.com/anderly/woocommerce-mailchimp). Opening new issues and submitting pull requests are welcome.
|
94 |
|
95 |
[Our public roadmap is available on Trello](https://trello.com/b/VWBdLVuI/woocommerce-mailchimp-development). We'd love it if you vote and comment on your favorite ideas.
|
96 |
|
@@ -119,6 +119,9 @@ Also, if you enjoy using the software [we'd love it if you could give us a revie
|
|
119 |
|
120 |
== Changelog ==
|
121 |
|
|
|
|
|
|
|
122 |
#### 2.3.4 - October 29, 2019
|
123 |
- Change plugin display name.
|
124 |
- Sanitize post data.
|
6 |
Tested up to: 5.2.2
|
7 |
WC tested up to: 3.7.0
|
8 |
Requires PHP: 5.6
|
9 |
+
Stable tag: 2.3.5
|
10 |
License: GPLv3
|
11 |
|
12 |
Simple and flexible Mailchimp integration for WooCommerce.
|
78 |
|
79 |
= Requirements =
|
80 |
|
81 |
+
WP WooCommerce Mailchimp requires PHP 5.6+ (PHP 7.0+ recommended). You'll also need to be running WordPress 4.7.0+ and have WooCommerce 3.5.0+.
|
82 |
|
83 |
= Documentation & Support =
|
84 |
|
85 |
Online documentation and code samples are available via our [Help Center](https://support.saintsystems.com/hc/en-us/sections/201959566).
|
86 |
|
87 |
Please visit the
|
88 |
+
[WP WooCommerce MailChimp support forum on WordPress.org](https://wordpress.org/support/plugin/woocommerce-mailchimp) for basic support and help from other users. Since this is a free plugin, we respond to these as we have time.
|
89 |
|
90 |
+
Dedicated support will is available for [WP WooCommerce MailChimp Pro](https://www.saintsystems.com/products/woocommerce-mailchimp-pro/) customers.
|
91 |
|
92 |
= Contribute =
|
93 |
+
All development for WP WooCommerce MailChimp is [handled via GitHub](https://github.com/anderly/woocommerce-mailchimp). Opening new issues and submitting pull requests are welcome.
|
94 |
|
95 |
[Our public roadmap is available on Trello](https://trello.com/b/VWBdLVuI/woocommerce-mailchimp-development). We'd love it if you vote and comment on your favorite ideas.
|
96 |
|
119 |
|
120 |
== Changelog ==
|
121 |
|
122 |
+
#### 2.3.5 - October 30, 2019
|
123 |
+
- WordPress coding standards updates.
|
124 |
+
|
125 |
#### 2.3.4 - October 29, 2019
|
126 |
- Change plugin display name.
|
127 |
- Sanitize post data.
|
woocommerce-mailchimp.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Description: WP WooCommerce Mailchimp provides simple and flexible Mailchimp integration for WooCommerce.
|
6 |
* Author: Saint Systems
|
7 |
* Author URI: https://www.saintsystems.com
|
8 |
-
* Version: 2.3.
|
9 |
* WC tested up to: 3.7.0
|
10 |
* Text Domain: woocommerce-mailchimp
|
11 |
* Domain Path: languages
|
5 |
* Description: WP WooCommerce Mailchimp provides simple and flexible Mailchimp integration for WooCommerce.
|
6 |
* Author: Saint Systems
|
7 |
* Author URI: https://www.saintsystems.com
|
8 |
+
* Version: 2.3.5
|
9 |
* WC tested up to: 3.7.0
|
10 |
* Text Domain: woocommerce-mailchimp
|
11 |
* Domain Path: languages
|