Version Description
Download this release
Release Info
Developer | anderly |
Plugin | WooCommerce MailChimp |
Version | 2.0.1 |
Comparing to | |
See all releases |
Code changes from version 2.0 to 2.0.1
classes/api/class-ss-wc-mailchimp-api.php
DELETED
@@ -1,274 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Minimal MailChimp API v1.3 wrapper
|
7 |
-
*
|
8 |
-
* @class SS_WC_MailChimp_API
|
9 |
-
* @extends WC_Integration
|
10 |
-
* @version 1.3.9
|
11 |
-
* @package WooCommerce MailChimp
|
12 |
-
* @author Saint Systems
|
13 |
-
*/
|
14 |
-
class SS_WC_MailChimp_API {
|
15 |
-
var $version = "1.3";
|
16 |
-
var $errorMessage;
|
17 |
-
var $errorCode;
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Cache the information on the API location on the server
|
21 |
-
*/
|
22 |
-
var $apiUrl;
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Default to a 300 second timeout on server calls
|
26 |
-
*/
|
27 |
-
var $timeout = 300;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Default to a 8K chunk size
|
31 |
-
*/
|
32 |
-
var $chunkSize = 8192;
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Cache the user api_key so we only have to log in once per client instantiation
|
36 |
-
*/
|
37 |
-
var $api_key;
|
38 |
-
|
39 |
-
/**
|
40 |
-
* Cache the user api_key so we only have to log in once per client instantiation
|
41 |
-
*/
|
42 |
-
var $secure = false;
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Connect to the MailChimp API for a given list.
|
46 |
-
*
|
47 |
-
* @param string $apikey Your MailChimp apikey
|
48 |
-
* @param string $secure Whether or not this should use a secure connection
|
49 |
-
*/
|
50 |
-
function __construct($apikey, $secure=false) {
|
51 |
-
$this->secure = $secure;
|
52 |
-
$this->apiUrl = parse_url("http://api.mailchimp.com/" . $this->version . "/?output=php");
|
53 |
-
$this->api_key = $apikey;
|
54 |
-
}
|
55 |
-
|
56 |
-
function setTimeout($seconds){
|
57 |
-
if (is_int($seconds)){
|
58 |
-
$this->timeout = $seconds;
|
59 |
-
return true;
|
60 |
-
}
|
61 |
-
}
|
62 |
-
|
63 |
-
function getTimeout(){
|
64 |
-
return $this->timeout;
|
65 |
-
}
|
66 |
-
|
67 |
-
function useSecure($val){
|
68 |
-
if ($val===true){
|
69 |
-
$this->secure = true;
|
70 |
-
} else {
|
71 |
-
$this->secure = false;
|
72 |
-
}
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* Actually connect to the server and call the requested methods, parsing the result
|
77 |
-
* You should never have to call this function manually
|
78 |
-
*/
|
79 |
-
function __call($method, $params) {
|
80 |
-
$dc = "us1";
|
81 |
-
if (strstr($this->api_key,"-")){
|
82 |
-
list($key, $dc) = explode("-",$this->api_key,2);
|
83 |
-
if (!$dc) $dc = "us1";
|
84 |
-
}
|
85 |
-
$host = $dc.".".$this->apiUrl["host"];
|
86 |
-
|
87 |
-
$this->errorMessage = "";
|
88 |
-
$this->errorCode = "";
|
89 |
-
$sep_changed = false;
|
90 |
-
//sigh, apparently some distribs change this to & by default
|
91 |
-
if (ini_get("arg_separator.output")!="&"){
|
92 |
-
$sep_changed = true;
|
93 |
-
$orig_sep = ini_get("arg_separator.output");
|
94 |
-
ini_set("arg_separator.output", "&");
|
95 |
-
}
|
96 |
-
//mutate params
|
97 |
-
$mutate = array();
|
98 |
-
$mutate["apikey"] = $this->api_key;
|
99 |
-
foreach($params as $k=>$v){
|
100 |
-
$mutate[$this->function_map[$method][$k]] = $v;
|
101 |
-
}
|
102 |
-
$post_vars = http_build_query($mutate);
|
103 |
-
if ($sep_changed){
|
104 |
-
ini_set("arg_separator.output", $orig_sep);
|
105 |
-
}
|
106 |
-
|
107 |
-
$payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
|
108 |
-
$payload .= "Host: " . $host . "\r\n";
|
109 |
-
$payload .= "User-Agent: MCAPImini/" . $this->version ."\r\n";
|
110 |
-
$payload .= "Content-type: application/x-www-form-urlencoded\r\n";
|
111 |
-
$payload .= "Content-length: " . strlen($post_vars) . "\r\n";
|
112 |
-
$payload .= "Connection: close \r\n\r\n";
|
113 |
-
$payload .= $post_vars;
|
114 |
-
|
115 |
-
ob_start();
|
116 |
-
if ($this->secure){
|
117 |
-
$sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
|
118 |
-
} else {
|
119 |
-
$sock = fsockopen($host, 80, $errno, $errstr, 30);
|
120 |
-
}
|
121 |
-
if(!$sock) {
|
122 |
-
$this->errorMessage = "Could not connect (ERR $errno: $errstr)";
|
123 |
-
$this->errorCode = "-99";
|
124 |
-
ob_end_clean();
|
125 |
-
return false;
|
126 |
-
}
|
127 |
-
|
128 |
-
$response = "";
|
129 |
-
fwrite($sock, $payload);
|
130 |
-
stream_set_timeout($sock, $this->timeout);
|
131 |
-
$info = stream_get_meta_data($sock);
|
132 |
-
while ((!feof($sock)) && (!$info["timed_out"])) {
|
133 |
-
$response .= fread($sock, $this->chunkSize);
|
134 |
-
$info = stream_get_meta_data($sock);
|
135 |
-
}
|
136 |
-
fclose($sock);
|
137 |
-
ob_end_clean();
|
138 |
-
if ($info["timed_out"]) {
|
139 |
-
$this->errorMessage = "Could not read response (timed out)";
|
140 |
-
$this->errorCode = -98;
|
141 |
-
|
142 |
-
return false;
|
143 |
-
}
|
144 |
-
|
145 |
-
list($headers, $response) = explode("\r\n\r\n", $response, 2);
|
146 |
-
$headers = explode("\r\n", $headers);
|
147 |
-
$errored = false;
|
148 |
-
foreach($headers as $h) {
|
149 |
-
if (substr($h,0,26)==="X-MailChimp-API-Error-Code"){
|
150 |
-
$errored = true;
|
151 |
-
$error_code = trim(substr($h,27));
|
152 |
-
break;
|
153 |
-
}
|
154 |
-
}
|
155 |
-
|
156 |
-
if(ini_get("magic_quotes_runtime")) $response = stripslashes($response);
|
157 |
-
|
158 |
-
$serial = unserialize($response);
|
159 |
-
if($response && $serial === false) {
|
160 |
-
$response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99");
|
161 |
-
} else {
|
162 |
-
$response = $serial;
|
163 |
-
}
|
164 |
-
if($errored && is_array($response) && isset($response["error"])) {
|
165 |
-
$this->errorMessage = $response["error"];
|
166 |
-
$this->errorCode = $response["code"];
|
167 |
-
return false;
|
168 |
-
}
|
169 |
-
elseif($errored){
|
170 |
-
$this->errorMessage = "No error message was found";
|
171 |
-
$this->errorCode = $error_code;
|
172 |
-
return false;
|
173 |
-
}
|
174 |
-
|
175 |
-
return $response;
|
176 |
-
}
|
177 |
-
|
178 |
-
protected $function_map = array(
|
179 |
-
'campaignUnschedule' => array( "cid" ),
|
180 |
-
'campaignSchedule' => array( "cid", "schedule_time", "schedule_time_b" ),
|
181 |
-
'campaignResume' => array( "cid" ),
|
182 |
-
'campaignPause' => array( "cid" ),
|
183 |
-
'campaignSendNow' => array( "cid" ),
|
184 |
-
'campaignSendTest' => array( "cid", "test_emails", "send_type" ),
|
185 |
-
'campaignSegmentTest' => array( "list_id", "options" ),
|
186 |
-
'campaignCreate' => array( "type", "options", "content", "segment_opts", "type_opts" ),
|
187 |
-
'campaignUpdate' => array( "cid", "name", "value" ),
|
188 |
-
'campaignReplicate' => array( "cid" ),
|
189 |
-
'campaignDelete' => array( "cid" ),
|
190 |
-
'campaigns' => array( "filters", "start", "limit" ),
|
191 |
-
'campaignStats' => array( "cid" ),
|
192 |
-
'campaignClickStats' => array( "cid" ),
|
193 |
-
'campaignEmailDomainPerformance'=> array( "cid" ),
|
194 |
-
'campaignMembers' => array( "cid", "status", "start", "limit" ),
|
195 |
-
'campaignHardBounces' => array( "cid", "start", "limit" ),
|
196 |
-
'campaignSoftBounces' => array( "cid", "start", "limit" ),
|
197 |
-
'campaignUnsubscribes' => array( "cid", "start", "limit" ),
|
198 |
-
'campaignAbuseReports' => array( "cid", "since", "start", "limit" ),
|
199 |
-
'campaignAdvice' => array( "cid" ),
|
200 |
-
'campaignAnalytics' => array( "cid" ),
|
201 |
-
'campaignGeoOpens' => array( "cid" ),
|
202 |
-
'campaignGeoOpensForCountry' => array( "cid", "code" ),
|
203 |
-
'campaignEepUrlStats' => array( "cid" ),
|
204 |
-
'campaignBounceMessage' => array( "cid", "email" ),
|
205 |
-
'campaignBounceMessages' => array( "cid", "start", "limit", "since" ),
|
206 |
-
'campaignEcommOrders' => array( "cid", "start", "limit", "since" ),
|
207 |
-
'campaignShareReport' => array( "cid", "opts" ),
|
208 |
-
'campaignContent' => array( "cid", "for_archive" ),
|
209 |
-
'campaignTemplateContent' => array( "cid" ),
|
210 |
-
'campaignOpenedAIM' => array( "cid", "start", "limit" ),
|
211 |
-
'campaignNotOpenedAIM' => array( "cid", "start", "limit" ),
|
212 |
-
'campaignClickDetailAIM' => array( "cid", "url", "start", "limit" ),
|
213 |
-
'campaignEmailStatsAIM' => array( "cid", "email_address" ),
|
214 |
-
'campaignEmailStatsAIMAll' => array( "cid", "start", "limit" ),
|
215 |
-
'campaignEcommOrderAdd' => array( "order" ),
|
216 |
-
'lists' => array( "filters", "start", "limit" ),
|
217 |
-
'listMergeVars' => array( "id" ),
|
218 |
-
'listMergeVarAdd' => array( "id", "tag", "name", "options" ),
|
219 |
-
'listMergeVarUpdate' => array( "id", "tag", "options" ),
|
220 |
-
'listMergeVarDel' => array( "id", "tag" ),
|
221 |
-
'listInterestGroupings' => array( "id" ),
|
222 |
-
'listInterestGroupAdd' => array( "id", "group_name", "grouping_id" ),
|
223 |
-
'listInterestGroupDel' => array( "id", "group_name", "grouping_id" ),
|
224 |
-
'listInterestGroupUpdate' => array( "id", "old_name", "new_name", "grouping_id" ),
|
225 |
-
'listInterestGroupingAdd' => array( "id", "name", "type", "groups" ),
|
226 |
-
'listInterestGroupingUpdate' => array( "grouping_id", "name", "value" ),
|
227 |
-
'listInterestGroupingDel' => array( "grouping_id" ),
|
228 |
-
'listWebhooks' => array( "id" ),
|
229 |
-
'listWebhookAdd' => array( "id", "url", "actions", "sources" ),
|
230 |
-
'listWebhookDel' => array( "id", "url" ),
|
231 |
-
'listStaticSegments' => array( "id" ),
|
232 |
-
'listStaticSegmentAdd' => array( "id", "name" ),
|
233 |
-
'listStaticSegmentReset' => array( "id", "seg_id" ),
|
234 |
-
'listStaticSegmentDel' => array( "id", "seg_id" ),
|
235 |
-
'listStaticSegmentMembersAdd' => array( "id", "seg_id", "batch" ),
|
236 |
-
'listStaticSegmentMembersDel' => array( "id", "seg_id", "batch" ),
|
237 |
-
'listSubscribe' => array( "id", "email_address", "merge_vars", "email_type", "double_optin", "update_existing", "replace_interests", "send_welcome" ),
|
238 |
-
'listUnsubscribe' => array( "id", "email_address", "delete_member", "send_goodbye", "send_notify" ),
|
239 |
-
'listUpdateMember' => array( "id", "email_address", "merge_vars", "email_type", "replace_interests" ),
|
240 |
-
'listBatchSubscribe' => array( "id", "batch", "double_optin", "update_existing", "replace_interests" ),
|
241 |
-
'listBatchUnsubscribe' => array( "id", "emails", "delete_member", "send_goodbye", "send_notify" ),
|
242 |
-
'listMembers' => array( "id", "status", "since", "start", "limit" ),
|
243 |
-
'listMemberInfo' => array( "id", "email_address" ),
|
244 |
-
'listMemberActivity' => array( "id", "email_address" ),
|
245 |
-
'listAbuseReports' => array( "id", "start", "limit", "since" ),
|
246 |
-
'listGrowthHistory' => array( "id" ),
|
247 |
-
'listActivity' => array( "id" ),
|
248 |
-
'listLocations' => array( "id" ),
|
249 |
-
'listClients' => array( "id" ),
|
250 |
-
'templates' => array( "types", "category", "inactives" ),
|
251 |
-
'templateInfo' => array( "tid", "type" ),
|
252 |
-
'templateAdd' => array( "name", "html" ),
|
253 |
-
'templateUpdate' => array( "id", "values" ),
|
254 |
-
'templateDel' => array( "id" ),
|
255 |
-
'templateUndel' => array( "id" ),
|
256 |
-
'getAccountDetails' => array(),
|
257 |
-
'generateText' => array( "type", "content" ),
|
258 |
-
'inlineCss' => array( "html", "strip_css" ),
|
259 |
-
'folders' => array( "type" ),
|
260 |
-
'folderAdd' => array( "name", "type" ),
|
261 |
-
'folderUpdate' => array( "fid", "name", "type" ),
|
262 |
-
'folderDel' => array( "fid", "type" ),
|
263 |
-
'ecommOrders' => array( "start", "limit", "since" ),
|
264 |
-
'ecommOrderAdd' => array( "order" ),
|
265 |
-
'ecommOrderDel' => array( "store_id", "order_id" ),
|
266 |
-
'listsForEmail' => array( "email_address" ),
|
267 |
-
'campaignsForEmail' => array( "email_address" ),
|
268 |
-
'chimpChatter' => array(),
|
269 |
-
'apikeys' => array( "username", "password", "expired" ),
|
270 |
-
'apikeyAdd' => array( "username", "password" ),
|
271 |
-
'apikeyExpire' => array( "username", "password" ),
|
272 |
-
'ping' => array()
|
273 |
-
);
|
274 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/class-ss-wc-integration-mailchimp.php
DELETED
@@ -1,642 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
4 |
-
|
5 |
-
/**
|
6 |
-
* MailChimp Integration
|
7 |
-
*
|
8 |
-
* Allows integration with MailChimp
|
9 |
-
*
|
10 |
-
* @class SS_WC_Integration_MailChimp
|
11 |
-
* @extends WC_Integration
|
12 |
-
* @version 1.3.7
|
13 |
-
* @package WooCommerce MailChimp
|
14 |
-
* @author Saint Systems
|
15 |
-
*/
|
16 |
-
class SS_WC_Integration_MailChimp extends WC_Integration {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Instance of the API class.
|
20 |
-
* @var Object
|
21 |
-
*/
|
22 |
-
private static $api = null;
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Init and hook in the integration.
|
26 |
-
*
|
27 |
-
* @access public
|
28 |
-
* @return void
|
29 |
-
*/
|
30 |
-
public function __construct() {
|
31 |
-
|
32 |
-
$this->id = 'mailchimp';
|
33 |
-
$this->method_title = __( 'MailChimp', 'ss_wc_mailchimp' );
|
34 |
-
$this->method_description = __( 'MailChimp is a popular email marketing service.', 'ss_wc_mailchimp' );
|
35 |
-
|
36 |
-
// Load the settings.
|
37 |
-
$this->init_settings();
|
38 |
-
|
39 |
-
$this->load_settings();
|
40 |
-
|
41 |
-
if ( is_admin() ) {
|
42 |
-
// Load the settings
|
43 |
-
$this->init_form_fields();
|
44 |
-
}
|
45 |
-
|
46 |
-
// Hooks
|
47 |
-
add_action( 'admin_notices', array( $this, 'checks' ) );
|
48 |
-
|
49 |
-
// Update the settings fields
|
50 |
-
add_action( 'woocommerce_update_options_integration', array( $this, 'process_admin_options') );
|
51 |
-
|
52 |
-
// Update the settings fields
|
53 |
-
add_action( 'woocommerce_update_options_integration', array( $this, 'refresh_settings'), 10 );
|
54 |
-
|
55 |
-
// Refresh the settings
|
56 |
-
add_action( 'woocommerce_update_options_integration_' . $this->id, array( $this, 'refresh_settings'), 10 );
|
57 |
-
|
58 |
-
// We would use the 'woocommerce_new_order' action but first name, last name and email address (order meta) is not yet available,
|
59 |
-
// so instead we use the 'woocommerce_checkout_update_order_meta' action hook which fires after the checkout process on the "thank you" page
|
60 |
-
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'order_status_changed' ), 1000, 1 );
|
61 |
-
|
62 |
-
// hook into woocommerce order status changed hook to handle the desired subscription event trigger
|
63 |
-
add_action( 'woocommerce_order_status_changed', array( $this, 'order_status_changed' ), 10, 3 );
|
64 |
-
|
65 |
-
// Maybe add an "opt-in" field to the checkout
|
66 |
-
$opt_in_checkbox_display_location = ( isset( $this->opt_in_checkbox_display_location ) && !empty( $this->opt_in_checkbox_display_location ) ) ? $this->opt_in_checkbox_display_location : 'woocommerce_review_order_before_submit';
|
67 |
-
|
68 |
-
// Old opt-in checkbox display locations
|
69 |
-
$old_opt_in_checkbox_display_locations = array(
|
70 |
-
'billing' => 'woocommerce_after_checkout_billing_form',
|
71 |
-
'order' => 'woocommerce_review_order_before_submit',
|
72 |
-
);
|
73 |
-
|
74 |
-
// Map old billing/order checkbox display locations to new format
|
75 |
-
if ( array_key_exists( $opt_in_checkbox_display_location, $old_opt_in_checkbox_display_locations ) ) {
|
76 |
-
$opt_in_checkbox_display_location = $old_opt_in_checkbox_display_locations[ $opt_in_checkbox_display_location ];
|
77 |
-
}
|
78 |
-
|
79 |
-
add_action( $opt_in_checkbox_display_location, array( $this, 'maybe_add_checkout_fields' ) );
|
80 |
-
add_filter( 'default_checkout_ss_wc_mailchimp_opt_in', array( $this, 'checkbox_default_status' ) );
|
81 |
-
|
82 |
-
// Maybe save the "opt-in" field on the checkout
|
83 |
-
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'maybe_save_checkout_fields' ) );
|
84 |
-
}
|
85 |
-
|
86 |
-
public function load_settings() {
|
87 |
-
// We need the API key to set up for the lists in the form fields
|
88 |
-
$this->api_key = $this->get_option( 'api_key' );
|
89 |
-
$this->enabled = $this->get_option( 'enabled' );
|
90 |
-
|
91 |
-
// Get setting values
|
92 |
-
$this->occurs = $this->get_option( 'occurs' );
|
93 |
-
$this->list = $this->get_option( 'list' );
|
94 |
-
$this->double_optin = $this->get_option( 'double_optin' );
|
95 |
-
$this->groups = $this->get_option( 'groups' );
|
96 |
-
$this->display_opt_in = $this->get_option( 'display_opt_in' );
|
97 |
-
$this->opt_in_label = $this->get_option( 'opt_in_label' );
|
98 |
-
$this->opt_in_checkbox_default_status = $this->get_option( 'opt_in_checkbox_default_status' );
|
99 |
-
$this->opt_in_checkbox_display_location = $this->get_option( 'opt_in_checkbox_display_location' );
|
100 |
-
$this->interest_groupings = $this->get_option( 'interest_groupings' );
|
101 |
-
}
|
102 |
-
|
103 |
-
public function refresh_settings() {
|
104 |
-
$this->init_form_fields();
|
105 |
-
}
|
106 |
-
|
107 |
-
/**
|
108 |
-
* Check if the user has enabled the plugin functionality, but hasn't provided an api key
|
109 |
-
**/
|
110 |
-
function checks() {
|
111 |
-
// Check required fields
|
112 |
-
if ( $this->is_enabled() && ! $this->has_api_key() ) {
|
113 |
-
// Show notice
|
114 |
-
echo $this->get_message( 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 ) );
|
115 |
-
}
|
116 |
-
}
|
117 |
-
|
118 |
-
/**
|
119 |
-
* order_status_changed function.
|
120 |
-
*
|
121 |
-
* @access public
|
122 |
-
* @return void
|
123 |
-
*/
|
124 |
-
public function order_status_changed( $id, $status = 'new', $new_status = 'pending' ) {
|
125 |
-
if ( $this->is_valid() && $new_status == $this->occurs ) {
|
126 |
-
// Get WC order
|
127 |
-
$order = $this->wc_get_order( $id );
|
128 |
-
|
129 |
-
// get the ss_wc_mailchimp_opt_in value from the post meta. "order_custom_fields" was removed with WooCommerce 2.1
|
130 |
-
$subscribe_customer = get_post_meta( $id, 'ss_wc_mailchimp_opt_in', true );
|
131 |
-
|
132 |
-
// log
|
133 |
-
self::log( sprintf( __( 'Order Opt-In Value: %s', 'ss_wc_mailchimp' ), var_export( $subscribe_customer, true ) ) );
|
134 |
-
|
135 |
-
// If the 'ss_wc_mailchimp_opt_in' meta value isn't set (because 'display_opt_in' wasn't enabled at the time the order
|
136 |
-
// was placed) or the 'ss_wc_mailchimp_opt_in' is yes, subscriber the customer
|
137 |
-
if ( ! $subscribe_customer || empty( $subscribe_customer ) || 'yes' == $subscribe_customer ) {
|
138 |
-
// log
|
139 |
-
self::log( sprintf( __( 'Subscribe customer (%s) to list %s', 'ss_wc_mailchimp' ), $order->billing_email, $this->list ) );
|
140 |
-
|
141 |
-
// subscribe
|
142 |
-
$this->subscribe( $order->id, $order->billing_first_name, $order->billing_last_name, $order->billing_email, $this->list );
|
143 |
-
}
|
144 |
-
}
|
145 |
-
}
|
146 |
-
|
147 |
-
/**
|
148 |
-
* has_list function.
|
149 |
-
*
|
150 |
-
* @access public
|
151 |
-
* @return void
|
152 |
-
*/
|
153 |
-
public function has_list() {
|
154 |
-
if ( $this->list )
|
155 |
-
return true;
|
156 |
-
}
|
157 |
-
|
158 |
-
/**
|
159 |
-
* has_api_key function.
|
160 |
-
*
|
161 |
-
* @access public
|
162 |
-
* @return void
|
163 |
-
*/
|
164 |
-
public function has_api_key() {
|
165 |
-
return isset( $this->api_key ) && !empty( $this->api_key );
|
166 |
-
}
|
167 |
-
|
168 |
-
/**
|
169 |
-
* is_valid function.
|
170 |
-
*
|
171 |
-
* @access public
|
172 |
-
* @return boolean
|
173 |
-
*/
|
174 |
-
public function is_valid() {
|
175 |
-
return $this->is_enabled() && $this->has_api_key() && $this->has_list();
|
176 |
-
}
|
177 |
-
|
178 |
-
/**
|
179 |
-
* is_enabled function.
|
180 |
-
*
|
181 |
-
* @access public
|
182 |
-
* @return boolean
|
183 |
-
*/
|
184 |
-
public function is_enabled() {
|
185 |
-
return 'yes' === $this->enabled;
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
* Initialize Settings Form Fields
|
190 |
-
*
|
191 |
-
* @access public
|
192 |
-
* @return void
|
193 |
-
*/
|
194 |
-
function init_form_fields() {
|
195 |
-
$this->load_settings();
|
196 |
-
|
197 |
-
$lists = array();
|
198 |
-
|
199 |
-
if ( is_admin() && ! is_ajax() ) {
|
200 |
-
|
201 |
-
if ( $this->is_enabled() && $this->has_api_key() ) {
|
202 |
-
$user_lists = $this->get_lists();
|
203 |
-
|
204 |
-
if ( is_array( $user_lists ) && ! empty( $user_lists ) ) {
|
205 |
-
$lists = $user_lists;
|
206 |
-
}
|
207 |
-
}
|
208 |
-
|
209 |
-
if( $this->has_api_key() ) {
|
210 |
-
$mailchimp_lists = array_merge( array( '' => __( 'Select a list...', 'ss_wc_mailchimp' ) ), $lists );
|
211 |
-
}
|
212 |
-
else {
|
213 |
-
$mailchimp_lists = array( '' => __( 'Enter your key and save to see your lists', 'ss_wc_mailchimp' ) );
|
214 |
-
}
|
215 |
-
|
216 |
-
$this->form_fields = array(
|
217 |
-
'enabled' => array(
|
218 |
-
'title' => __( 'Enable/Disable', 'ss_wc_mailchimp' ),
|
219 |
-
'label' => __( 'Enable MailChimp', 'ss_wc_mailchimp' ),
|
220 |
-
'type' => 'checkbox',
|
221 |
-
'description' => '',
|
222 |
-
'default' => 'no'
|
223 |
-
),
|
224 |
-
'occurs' => array(
|
225 |
-
'title' => __( 'Subscribe Event', 'ss_wc_mailchimp' ),
|
226 |
-
'type' => 'select',
|
227 |
-
'description' => __( 'When should customers be subscribed to lists?', 'ss_wc_mailchimp' ),
|
228 |
-
'default' => 'pending',
|
229 |
-
'options' => array(
|
230 |
-
'pending' => __( 'Order Created', 'ss_wc_mailchimp' ),
|
231 |
-
'processing' => __( 'Order Processing', 'ss_wc_mailchimp' ),
|
232 |
-
'completed' => __( 'Order Completed', 'ss_wc_mailchimp' ),
|
233 |
-
),
|
234 |
-
),
|
235 |
-
'api_key' => array(
|
236 |
-
'title' => __( 'API Key', 'ss_wc_mailchimp' ),
|
237 |
-
'type' => 'text',
|
238 |
-
'description' => __( '<a href="https://us2.admin.mailchimp.com/account/api/" target="_blank">Login to mailchimp</a> to look up your api key.', 'ss_wc_mailchimp' ),
|
239 |
-
'default' => ''
|
240 |
-
),
|
241 |
-
'list' => array(
|
242 |
-
'title' => __( 'Main List', 'ss_wc_mailchimp' ),
|
243 |
-
'type' => 'select',
|
244 |
-
'description' => __( 'All customers will be added to this list.', 'ss_wc_mailchimp' ),
|
245 |
-
'default' => '',
|
246 |
-
'options' => $mailchimp_lists,
|
247 |
-
),
|
248 |
-
'interest_groupings' => array(
|
249 |
-
'title' => __( 'Group Name', 'ss_wc_mailchimp' ),
|
250 |
-
'type' => 'text',
|
251 |
-
'description' => __( 'Optional: Enter the name of the group. Learn more about <a href="http://mailchimp.com/features/groups" target="_blank">Groups</a>', 'ss_wc_mailchimp' ),
|
252 |
-
'default' => '',
|
253 |
-
),
|
254 |
-
'groups' => array(
|
255 |
-
'title' => __( 'Groups', 'ss_wc_mailchimp' ),
|
256 |
-
'type' => 'text',
|
257 |
-
'description' => __( 'Optional: Comma separated list of interest groups to which subscribers should be added.', 'ss_wc_mailchimp' ),
|
258 |
-
'default' => '',
|
259 |
-
),
|
260 |
-
'double_optin' => array(
|
261 |
-
'title' => __( 'Double Opt-In', 'ss_wc_mailchimp' ),
|
262 |
-
'label' => __( 'Enable Double Opt-In', 'ss_wc_mailchimp' ),
|
263 |
-
'type' => 'checkbox',
|
264 |
-
'description' => __( 'If enabled, customers will receive an email prompting them to confirm their subscription to the list above.', 'ss_wc_mailchimp' ),
|
265 |
-
'default' => 'no'
|
266 |
-
),
|
267 |
-
'display_opt_in' => array(
|
268 |
-
'title' => __( 'Display Opt-In Field', 'ss_wc_mailchimp' ),
|
269 |
-
'label' => __( 'Display an Opt-In Field on Checkout', 'ss_wc_mailchimp' ),
|
270 |
-
'type' => 'checkbox',
|
271 |
-
'description' => __( 'If enabled, customers will be presented with a "Opt-in" checkbox during checkout and will only be added to the list above if they opt-in.', 'ss_wc_mailchimp' ),
|
272 |
-
'default' => 'no',
|
273 |
-
),
|
274 |
-
'opt_in_label' => array(
|
275 |
-
'title' => __( 'Opt-In Field Label', 'ss_wc_mailchimp' ),
|
276 |
-
'type' => 'text',
|
277 |
-
'description' => __( 'Optional: customize the label displayed next to the opt-in checkbox.', 'ss_wc_mailchimp' ),
|
278 |
-
'default' => __( 'Add me to the newsletter (we will never share your email).', 'ss_wc_mailchimp' ),
|
279 |
-
),
|
280 |
-
'opt_in_checkbox_default_status' => array(
|
281 |
-
'title' => __( 'Opt-In Checkbox Default Status', 'ss_wc_mailchimp' ),
|
282 |
-
'type' => 'select',
|
283 |
-
'description' => __( 'The default state of the opt-in checkbox.', 'ss_wc_mailchimp' ),
|
284 |
-
'default' => 'checked',
|
285 |
-
'options' => array(
|
286 |
-
'checked' => __( 'Checked', 'ss_wc_mailchimp' ),
|
287 |
-
'unchecked' => __( 'Unchecked', 'ss_wc_mailchimp' )
|
288 |
-
)
|
289 |
-
),
|
290 |
-
'opt_in_checkbox_display_location' => array(
|
291 |
-
'title' => __( 'Opt-In Checkbox Display Location', 'ss_wc_mailchimp' ),
|
292 |
-
'type' => 'select',
|
293 |
-
'description' => __( 'Where to display the opt-in checkbox on the checkout page.', 'ss_wc_mailchimp' ),
|
294 |
-
'default' => 'woocommerce_review_order_before_submit',
|
295 |
-
'options' => array(
|
296 |
-
'woocommerce_checkout_before_customer_details' => __( 'Above customer details', 'ss_wc_mailchimp' ),
|
297 |
-
'woocommerce_checkout_after_customer_details' => __( 'Below customer details', 'ss_wc_mailchimp' ),
|
298 |
-
'woocommerce_review_order_before_submit' => __( 'Order review above submit', 'ss_wc_mailchimp' ),
|
299 |
-
'woocommerce_review_order_after_submit' => __( 'Order review below submit', 'ss_wc_mailchimp' ),
|
300 |
-
'woocommerce_review_order_before_order_total' => __( 'Order review above total', 'ss_wc_mailchimp' ),
|
301 |
-
'woocommerce_checkout_billing' => __( 'Above billing details', 'ss_wc_mailchimp' ),
|
302 |
-
'woocommerce_checkout_shipping' => __( 'Above shipping details', 'ss_wc_mailchimp' ),
|
303 |
-
'woocommerce_after_checkout_billing_form' => __( 'Below Checkout billing form', 'ss_wc_mailchimp' ),
|
304 |
-
)
|
305 |
-
)
|
306 |
-
);
|
307 |
-
|
308 |
-
$this->wc_enqueue_js("
|
309 |
-
jQuery('#woocommerce_mailchimp_display_opt_in').change(function(){
|
310 |
-
jQuery('#mainform [id^=woocommerce_mailchimp_opt_in]').closest('tr').hide('fast');
|
311 |
-
|
312 |
-
if ( jQuery(this).prop('checked') == true ) {
|
313 |
-
jQuery('#mainform [id^=woocommerce_mailchimp_opt_in]').closest('tr').show('fast');
|
314 |
-
}
|
315 |
-
else {
|
316 |
-
jQuery('#mainform [id^=woocommerce_mailchimp_opt_in]').closest('tr').hide('fast');
|
317 |
-
}
|
318 |
-
|
319 |
-
}).change();
|
320 |
-
");
|
321 |
-
}
|
322 |
-
|
323 |
-
} // End init_form_fields()
|
324 |
-
|
325 |
-
/**
|
326 |
-
* WooCommerce 2.1 support for wc_enqueue_js
|
327 |
-
*
|
328 |
-
* @since 1.2.1
|
329 |
-
*
|
330 |
-
* @access private
|
331 |
-
* @param string $code
|
332 |
-
* @return void
|
333 |
-
*/
|
334 |
-
private function wc_enqueue_js( $code ) {
|
335 |
-
if ( function_exists( 'wc_enqueue_js' ) ) {
|
336 |
-
wc_enqueue_js( $code );
|
337 |
-
} else {
|
338 |
-
global $woocommerce;
|
339 |
-
$woocommerce->add_inline_js( $code );
|
340 |
-
}
|
341 |
-
}
|
342 |
-
|
343 |
-
/**
|
344 |
-
* WooCommerce 2.2 support for wc_get_order
|
345 |
-
*
|
346 |
-
* @since 1.2.1
|
347 |
-
*
|
348 |
-
* @access private
|
349 |
-
* @param int $order_id
|
350 |
-
* @return void
|
351 |
-
*/
|
352 |
-
private function wc_get_order( $order_id ) {
|
353 |
-
if ( function_exists( 'wc_get_order' ) ) {
|
354 |
-
return wc_get_order( $order_id );
|
355 |
-
} else {
|
356 |
-
return new WC_Order( $order_id );
|
357 |
-
}
|
358 |
-
}
|
359 |
-
|
360 |
-
/**
|
361 |
-
* Get message
|
362 |
-
* @return string Error
|
363 |
-
*/
|
364 |
-
private function get_message( $message, $type = 'error' ) {
|
365 |
-
ob_start();
|
366 |
-
|
367 |
-
?>
|
368 |
-
<div class="<?php echo $type ?>">
|
369 |
-
<p><?php echo $message ?></p>
|
370 |
-
</div>
|
371 |
-
<?php
|
372 |
-
return ob_get_clean();
|
373 |
-
}
|
374 |
-
|
375 |
-
/**
|
376 |
-
* Main API Instance, ensure only 1 API instance is loaded.
|
377 |
-
* @return Object
|
378 |
-
*/
|
379 |
-
public function get_api() {
|
380 |
-
if ( is_null( self::$api ) ) {
|
381 |
-
$this->api_key = $this->get_option( 'api_key' );
|
382 |
-
if ( $this->api_key == '' ) {
|
383 |
-
return false;
|
384 |
-
}
|
385 |
-
require_once( 'api/class-ss-wc-mailchimp-api.php' );
|
386 |
-
self::$api = new SS_WC_MailChimp_API( $this->api_key );
|
387 |
-
}
|
388 |
-
return self::$api;
|
389 |
-
}
|
390 |
-
|
391 |
-
/**
|
392 |
-
* get_lists function.
|
393 |
-
*
|
394 |
-
* @access public
|
395 |
-
* @return void
|
396 |
-
*/
|
397 |
-
public function get_lists() {
|
398 |
-
//$mailchimp_lists = get_transient( 'sswcmclist_' . md5( $this->api_key ) );
|
399 |
-
|
400 |
-
//if ( ! $mailchimp_lists ) {
|
401 |
-
|
402 |
-
$mailchimp_lists = array();
|
403 |
-
if ( $this->get_api() ) {
|
404 |
-
$retval = $this->get_api()->lists();
|
405 |
-
}
|
406 |
-
else {
|
407 |
-
return false;
|
408 |
-
}
|
409 |
-
|
410 |
-
// if ( $lists !== false ) {
|
411 |
-
// $retval = $this->get_api()->lists();
|
412 |
-
|
413 |
-
if ( $this->get_api()->errorCode ) {
|
414 |
-
|
415 |
-
add_action( 'admin_notices', array( $this, 'mailchimp_api_error_msg' ) );
|
416 |
-
add_action( 'network_admin_notices', array( $this, 'mailchimp_api_error_msg' ) );
|
417 |
-
|
418 |
-
return false;
|
419 |
-
}
|
420 |
-
else {
|
421 |
-
foreach ( $retval['data'] as $list )
|
422 |
-
$mailchimp_lists[ $list['id'] ] = $list['name'];
|
423 |
-
|
424 |
-
if ( sizeof( $mailchimp_lists ) > 0 )
|
425 |
-
set_transient( 'sswcmclist_' . md5( $this->api_key ), $mailchimp_lists, 60 * 60 * 1 );
|
426 |
-
}
|
427 |
-
//}
|
428 |
-
|
429 |
-
return $mailchimp_lists;
|
430 |
-
}
|
431 |
-
|
432 |
-
/**
|
433 |
-
* Display message to user if there is an issue with the MailChimp API call
|
434 |
-
*
|
435 |
-
* @since 1.0
|
436 |
-
* @param void
|
437 |
-
* @return html the message for the user
|
438 |
-
*/
|
439 |
-
public function mailchimp_api_error_msg() {
|
440 |
-
echo $this->get_message(
|
441 |
-
sprintf( __( 'Unable to load lists from MailChimp: (%s) %s. ', 'ss_wc_mailchimp' ), $this->get_api()->errorCode, $this->get_api()->errorMessage ) .
|
442 |
-
sprintf( __( 'Please check your %s <a href="%s">settings</a>.', 'ss_wc_mailchimp' ), __( 'Settings', 'ss_wc_mailchimp' ), WOOCOMMERCE_MAILCHIMP_SETTINGS_URL )
|
443 |
-
);
|
444 |
-
}
|
445 |
-
|
446 |
-
/**
|
447 |
-
* get_interest_groupings function.
|
448 |
-
*
|
449 |
-
* @access public
|
450 |
-
* @return void
|
451 |
-
*/
|
452 |
-
public function get_interest_groupings( $listid = 'false' ) {
|
453 |
-
if ( $listid == 'false' )
|
454 |
-
$listid = $this->list;
|
455 |
-
|
456 |
-
$interest_groupings = array();
|
457 |
-
$interest_groups = array();
|
458 |
-
$retval = $this->get_api()->listInterestGroupings( $listid );
|
459 |
-
|
460 |
-
if ( $this->get_api()->errorCode ) {
|
461 |
-
echo $this->get_message( sprintf( __( 'Unable to load listInterestGroupings() from MailChimp: (%s) %s', 'ss_wc_mailchimp' ), $this->get_api()->errorCode, $this->get_api()->errorMessage ) );
|
462 |
-
|
463 |
-
return false;
|
464 |
-
|
465 |
-
}
|
466 |
-
else {
|
467 |
-
if ( sizeof( $retval ) > 0 ) {
|
468 |
-
foreach ( $retval as $interest_grouping ) {
|
469 |
-
$interest_groupings[ $interest_grouping['id'] ] = $interest_grouping['name'];
|
470 |
-
|
471 |
-
foreach ( $interest_grouping['groups'] as $group ) {
|
472 |
-
$interest_groups[ $group['bit'] ] = $group['name'];
|
473 |
-
}
|
474 |
-
}
|
475 |
-
|
476 |
-
if ( sizeof( $interest_groupings ) > 0 ) {
|
477 |
-
// set transients for cache
|
478 |
-
set_transient( 'wc_mailchimp_list_' . md5( $this->api_key ) . '_' . $listid, $interest_groupings, 60 * 60 * 1 );
|
479 |
-
set_transient( 'wc_mailchimp_list_' . md5( $this->api_key ) . '_' . $listid . '_groups', $interest_groups, 60 * 60 * 1 );
|
480 |
-
|
481 |
-
$this->interest_groupings = $interest_groupings;
|
482 |
-
$this->groups[$listid] = $interest_groups;
|
483 |
-
}
|
484 |
-
}
|
485 |
-
}
|
486 |
-
|
487 |
-
return $interest_groupings;
|
488 |
-
}
|
489 |
-
|
490 |
-
/**
|
491 |
-
* subscribe function.
|
492 |
-
*
|
493 |
-
* @access public
|
494 |
-
* @param int $order_id
|
495 |
-
* @param mixed $first_name
|
496 |
-
* @param mixed $last_name
|
497 |
-
* @param mixed $email
|
498 |
-
* @param string $listid (default: 'false')
|
499 |
-
* @return void
|
500 |
-
*/
|
501 |
-
public function subscribe( $order_id, $first_name, $last_name, $email, $listid = 'false' ) {
|
502 |
-
if ( ! $email )
|
503 |
-
return; // Email is required
|
504 |
-
|
505 |
-
if ( 'false' == $listid )
|
506 |
-
$listid = $this->list;
|
507 |
-
|
508 |
-
$merge_vars = array(
|
509 |
-
'FNAME' => $first_name,
|
510 |
-
'LNAME' => $last_name
|
511 |
-
);
|
512 |
-
|
513 |
-
if ( ! empty( $this->interest_groupings ) && ! empty( $this->groups ) ) {
|
514 |
-
$merge_vars['GROUPINGS'] = array(
|
515 |
-
array(
|
516 |
-
'name' => $this->interest_groupings,
|
517 |
-
'groups' => $this->groups
|
518 |
-
)
|
519 |
-
);
|
520 |
-
}
|
521 |
-
|
522 |
-
// Allow hooking into variables
|
523 |
-
$vars = apply_filters( 'ss_wc_mailchimp_subscribe_merge_vars', $merge_vars, $order_id );
|
524 |
-
|
525 |
-
// Set subscription options
|
526 |
-
$subscribe_options = array(
|
527 |
-
'listid' => $listid,
|
528 |
-
'email' => $email,
|
529 |
-
'vars' => $vars,
|
530 |
-
'email_type' => 'html',
|
531 |
-
'double_optin' => $this->double_optin == 'no' ? false : true,
|
532 |
-
'update_existing' => true,
|
533 |
-
'replace_interests' => false,
|
534 |
-
'send_welcome' => false
|
535 |
-
);
|
536 |
-
|
537 |
-
// Allow hooking into subscription options
|
538 |
-
$options = apply_filters( 'ss_wc_mailchimp_subscribe_options', $subscribe_options, $order_id );
|
539 |
-
|
540 |
-
// Extract options into variables
|
541 |
-
extract( $options );
|
542 |
-
|
543 |
-
// Log
|
544 |
-
self::log( sprintf( __( 'Calling MailChimp API listSubscribe method with the following: %s', 'ss_wc_mailchimp' ), print_r( $options, true ) ) );
|
545 |
-
|
546 |
-
// Call API
|
547 |
-
$api_response = $this->get_api()->listSubscribe( $listid, $email, $vars, $email_type, $double_optin, $update_existing, $replace_interests, $send_welcome );
|
548 |
-
|
549 |
-
// Log api response
|
550 |
-
self::log( sprintf( __( 'MailChimp API response: %s', 'ss_wc_mailchimp' ), $api_response ) );
|
551 |
-
|
552 |
-
if ( $this->get_api()->errorCode && $this->get_api()->errorCode != 214 ) {
|
553 |
-
// Format error message
|
554 |
-
$error_response = sprintf( __( 'WooCommerce MailChimp subscription failed: %s (%s)', 'ss_wc_mailchimp' ), $this->get_api()->errorMessage, $this->get_api()->errorCode );
|
555 |
-
|
556 |
-
// Log
|
557 |
-
self::log( $error_response );
|
558 |
-
|
559 |
-
// Compability to old hook
|
560 |
-
do_action( 'ss_wc_mailchimp_subscribed', $email );
|
561 |
-
|
562 |
-
// New hook for failing operations
|
563 |
-
do_action( 'ss_wc_mailchimp_subscription_failed', $email, array( 'list_id' => $listid, 'order_id' => $order_id ) );
|
564 |
-
|
565 |
-
// Email admin
|
566 |
-
wp_mail( get_option( 'admin_email' ), __( 'WooCommerce MailChimp subscription failed', 'ss_wc_mailchimp' ), $error_response );
|
567 |
-
}
|
568 |
-
else {
|
569 |
-
// Hook on success
|
570 |
-
do_action( 'ss_wc_mailchimp_subscription_success', $email, array( 'list_id' => $listid, 'order_id' => $order_id ) );
|
571 |
-
}
|
572 |
-
}
|
573 |
-
|
574 |
-
/**
|
575 |
-
* Admin Panel Options
|
576 |
-
*/
|
577 |
-
function admin_options() {
|
578 |
-
?>
|
579 |
-
<h3><?php _e( 'MailChimp', 'ss_wc_mailchimp' ); ?></h3>
|
580 |
-
<p><?php _e( 'Enter your MailChimp settings below to control how WooCommerce integrates with your MailChimp lists.', 'ss_wc_mailchimp' ); ?></p>
|
581 |
-
<table class="form-table">
|
582 |
-
<?php $this->generate_settings_html(); ?>
|
583 |
-
</table><!--/.form-table-->
|
584 |
-
<?php
|
585 |
-
}
|
586 |
-
|
587 |
-
/**
|
588 |
-
* Add the opt-in checkbox to the checkout fields (to be displayed on checkout).
|
589 |
-
*
|
590 |
-
* @since 1.1
|
591 |
-
*/
|
592 |
-
function maybe_add_checkout_fields() {
|
593 |
-
if ( $this->is_valid() ) {
|
594 |
-
if ( 'yes' == $this->display_opt_in ) {
|
595 |
-
do_action( 'ss_wc_mailchimp_before_opt_in_checkbox' );
|
596 |
-
echo apply_filters('ss_wc_mailchimp_opt_in_checkbox', '<p class="form-row woocommerce-mailchimp-opt-in"><label for="ss_wc_mailchimp_opt_in"><input type="checkbox" name="ss_wc_mailchimp_opt_in" id="ss_wc_mailchimp_opt_in" value="yes"' . ($this->opt_in_checkbox_default_status == 'checked' ? ' checked="checked"' : '') . '/> ' . esc_html( $this->opt_in_label ) . '</label></p>' . "\n", $this->opt_in_checkbox_default_status, $this->opt_in_label);
|
597 |
-
do_action( 'ss_wc_mailchimp_after_opt_in_checkbox' );
|
598 |
-
}
|
599 |
-
}
|
600 |
-
}
|
601 |
-
|
602 |
-
/**
|
603 |
-
* Opt-in checkbox default support for WooCommerce 2.1
|
604 |
-
*
|
605 |
-
* @since 1.2.1
|
606 |
-
*/
|
607 |
-
function checkbox_default_status( $input ) {
|
608 |
-
return $this->opt_in_checkbox_default_status == 'checked' ? 1 : 0;
|
609 |
-
}
|
610 |
-
|
611 |
-
/**
|
612 |
-
* When the checkout form is submitted, save opt-in value.
|
613 |
-
*
|
614 |
-
* @version 1.1
|
615 |
-
*/
|
616 |
-
function maybe_save_checkout_fields( $order_id ) {
|
617 |
-
if ( 'yes' == $this->display_opt_in ) {
|
618 |
-
$opt_in = isset( $_POST['ss_wc_mailchimp_opt_in'] ) ? 'yes' : 'no';
|
619 |
-
|
620 |
-
update_post_meta( $order_id, 'ss_wc_mailchimp_opt_in', $opt_in );
|
621 |
-
}
|
622 |
-
}
|
623 |
-
|
624 |
-
/**
|
625 |
-
* Helper log function for debugging
|
626 |
-
*
|
627 |
-
* @since 1.2.2
|
628 |
-
*/
|
629 |
-
static function log( $message ) {
|
630 |
-
if ( WP_DEBUG === true ) {
|
631 |
-
$logger = new WC_Logger();
|
632 |
-
|
633 |
-
if ( is_array( $message ) || is_object( $message ) ) {
|
634 |
-
$logger->add( 'mailchimp', print_r( $message, true ) );
|
635 |
-
}
|
636 |
-
else {
|
637 |
-
$logger->add( 'mailchimp', $message );
|
638 |
-
}
|
639 |
-
}
|
640 |
-
}
|
641 |
-
|
642 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-ss-wc-mailchimp-plugin.php
CHANGED
@@ -7,7 +7,7 @@ final class SS_WC_MailChimp_Plugin {
|
|
7 |
|
8 |
private static $_instance;
|
9 |
|
10 |
-
private static $version = '2.0';
|
11 |
|
12 |
public static function version() {
|
13 |
return self::$version;
|
@@ -54,6 +54,8 @@ final class SS_WC_MailChimp_Plugin {
|
|
54 |
|
55 |
do_action( 'ss_wc_mailchimp_loaded' );
|
56 |
|
|
|
|
|
57 |
} //end function __construct
|
58 |
|
59 |
/**
|
@@ -234,6 +236,10 @@ final class SS_WC_MailChimp_Plugin {
|
|
234 |
|
235 |
} //end function enqueue_scripts
|
236 |
|
|
|
|
|
|
|
|
|
237 |
/**
|
238 |
* Plugin activate function.
|
239 |
*
|
@@ -246,7 +252,7 @@ final class SS_WC_MailChimp_Plugin {
|
|
246 |
|
247 |
require_once( 'class-ss-wc-mailchimp-migrator.php' );
|
248 |
|
249 |
-
|
250 |
|
251 |
} //end function activate
|
252 |
|
7 |
|
8 |
private static $_instance;
|
9 |
|
10 |
+
private static $version = '2.0.1';
|
11 |
|
12 |
public static function version() {
|
13 |
return self::$version;
|
54 |
|
55 |
do_action( 'ss_wc_mailchimp_loaded' );
|
56 |
|
57 |
+
self::update();
|
58 |
+
|
59 |
} //end function __construct
|
60 |
|
61 |
/**
|
236 |
|
237 |
} //end function enqueue_scripts
|
238 |
|
239 |
+
public static function update() {
|
240 |
+
SS_WC_MailChimp_Migrator::migrate( self::version() );
|
241 |
+
}
|
242 |
+
|
243 |
/**
|
244 |
* Plugin activate function.
|
245 |
*
|
252 |
|
253 |
require_once( 'class-ss-wc-mailchimp-migrator.php' );
|
254 |
|
255 |
+
self::update();
|
256 |
|
257 |
} //end function activate
|
258 |
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: saintsystems, anderly
|
|
3 |
Tags: woocommerce, mailchimp
|
4 |
Requires at least: 3.5.1
|
5 |
Tested up to: 4.6.1
|
6 |
-
Stable tag: 2.0
|
7 |
License: GPLv3
|
8 |
|
9 |
Simple and flexible MailChimp integration for WooCommerce.
|
@@ -93,7 +93,7 @@ Also, if you enjoy using the software [we'd love it if you could give us a revie
|
|
93 |
|
94 |
== Changelog ==
|
95 |
|
96 |
-
#### 2.0 - September 16, 2016
|
97 |
|
98 |
**WARNING:** This release contains breaking changes to the plugins action hooks and filters. If you have custom code that hooks into the plugins action hooks and filters, please review the breaking changes below to know how to update your code appropriately.
|
99 |
|
3 |
Tags: woocommerce, mailchimp
|
4 |
Requires at least: 3.5.1
|
5 |
Tested up to: 4.6.1
|
6 |
+
Stable tag: 2.0.1
|
7 |
License: GPLv3
|
8 |
|
9 |
Simple and flexible MailChimp integration for WooCommerce.
|
93 |
|
94 |
== Changelog ==
|
95 |
|
96 |
+
#### 2.0 && 2.0.1 - September 16, 2016
|
97 |
|
98 |
**WARNING:** This release contains breaking changes to the plugins action hooks and filters. If you have custom code that hooks into the plugins action hooks and filters, please review the breaking changes below to know how to update your code appropriately.
|
99 |
|
woocommerce-mailchimp.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Description: WooCommerce MailChimp provides simple MailChimp integration for WooCommerce.
|
6 |
* Author: Saint Systems
|
7 |
* Author URI: https://www.saintsystems.com
|
8 |
-
* Version: 2.0
|
9 |
* Text Domain: ss_wc_mailchimp
|
10 |
* Domain Path: languages
|
11 |
*
|
5 |
* Description: WooCommerce MailChimp provides simple MailChimp integration for WooCommerce.
|
6 |
* Author: Saint Systems
|
7 |
* Author URI: https://www.saintsystems.com
|
8 |
+
* Version: 2.0.1
|
9 |
* Text Domain: ss_wc_mailchimp
|
10 |
* Domain Path: languages
|
11 |
*
|