Version Description
- March 13, 2014 =
- Fixed: Honeypot textarea showing in some themes
- Improved: Plugin will automatically strip duplicate
<form>
tags from form mark-up - Improved: Better code documentation
- Improved: Code is now more adhering to WP code standards
- Improved: Add custom error type to error message filter to allow developers to show custom error messages
- Improved: Plugin will now show detailed errors for failed API requests (up to HTTP level)
- Improved: Better way of loading plugin files
Download this release
Release Info
Developer | DvanKooten |
Plugin | MailChimp for WordPress |
Version | 1.5.6 |
Comparing to | |
See all releases |
Code changes from version 1.5.5 to 1.5.6
- assets/css/checkbox.css +9 -9
- assets/css/css.php +11 -11
- assets/css/form-reset.css +52 -24
- assets/css/form.css +0 -23
- includes/class-admin.php +129 -52
- includes/class-api.php +152 -39
- includes/class-checkbox.php +160 -90
- includes/class-form.php +17 -13
- includes/functions.php +15 -4
- mailchimp-for-wp.php +13 -11
- readme.txt +10 -2
- uninstall.php +0 -15
assets/css/checkbox.css
CHANGED
@@ -1,24 +1,24 @@
|
|
1 |
/* MailChimp for WP - Default Checkbox Styles */
|
2 |
#mc4wp-checkbox{
|
3 |
-
clear:both;
|
4 |
-
display:block;
|
5 |
}
|
6 |
|
7 |
#mc4wp-checkbox input{
|
8 |
-
position:relative;
|
9 |
-
margin:0 6px 0 0;
|
10 |
-
padding:0;
|
11 |
vertical-align: middle;
|
12 |
-
display:inline-block !important;
|
13 |
max-width: 20px;
|
14 |
}
|
15 |
|
16 |
#mc4wp-checkbox label{
|
17 |
-
display:block;
|
18 |
-
cursor:pointer;
|
19 |
width: auto;
|
20 |
}
|
21 |
|
22 |
#registerform #mc4wp-checkbox{
|
23 |
-
margin-bottom:10px;
|
24 |
}
|
1 |
/* MailChimp for WP - Default Checkbox Styles */
|
2 |
#mc4wp-checkbox{
|
3 |
+
clear: both;
|
4 |
+
display: block;
|
5 |
}
|
6 |
|
7 |
#mc4wp-checkbox input{
|
8 |
+
position: relative;
|
9 |
+
margin: 0 6px 0 0;
|
10 |
+
padding: 0;
|
11 |
vertical-align: middle;
|
12 |
+
display: inline-block !important;
|
13 |
max-width: 20px;
|
14 |
}
|
15 |
|
16 |
#mc4wp-checkbox label{
|
17 |
+
display: block;
|
18 |
+
cursor: pointer;
|
19 |
width: auto;
|
20 |
}
|
21 |
|
22 |
#registerform #mc4wp-checkbox{
|
23 |
+
margin-bottom: 10px;
|
24 |
}
|
assets/css/css.php
CHANGED
@@ -1,30 +1,30 @@
|
|
1 |
<?php
|
2 |
// Set headers to serve CSS and encourage browser caching
|
3 |
$expires = 31536000; // cache time: 1 year
|
4 |
-
header('Content-Type: text/css');
|
5 |
-
header("Cache-Control: max-age=" . $expires);
|
6 |
-
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
|
7 |
|
8 |
-
if(isset($_GET['checkbox'])) {
|
9 |
-
readfile(dirname(__FILE__) . '/checkbox.css');
|
10 |
}
|
11 |
|
12 |
// load form reset
|
13 |
-
if(isset($_GET['form'])) {
|
14 |
-
readfile(dirname(__FILE__) . '/form-reset.css');
|
15 |
}
|
16 |
|
17 |
// should we load a form theme?
|
18 |
-
if(isset($_GET['form-theme'])) {
|
19 |
$form_theme = strtolower( trim( $_GET['form-theme'] ) );
|
20 |
|
21 |
// only load themes we actually have
|
22 |
-
if(in_array($form_theme, array('blue', 'green', 'dark', 'light', 'red'))) {
|
23 |
// load theme base file
|
24 |
-
readfile(dirname(__FILE__) . '/form-theme-base.css');
|
25 |
|
26 |
// load theme file
|
27 |
-
readfile(dirname(__FILE__) . '/form-theme-'. $form_theme .'.css');
|
28 |
}
|
29 |
|
30 |
}
|
1 |
<?php
|
2 |
// Set headers to serve CSS and encourage browser caching
|
3 |
$expires = 31536000; // cache time: 1 year
|
4 |
+
header( 'Content-Type: text/css' );
|
5 |
+
header( "Cache-Control: max-age=" . $expires );
|
6 |
+
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires ) . ' GMT' );
|
7 |
|
8 |
+
if( isset( $_GET['checkbox'] ) ) {
|
9 |
+
readfile( dirname( __FILE__ ) . '/checkbox.css' );
|
10 |
}
|
11 |
|
12 |
// load form reset
|
13 |
+
if( isset( $_GET['form'] ) ) {
|
14 |
+
readfile( dirname( __FILE__ ) . '/form-reset.css' );
|
15 |
}
|
16 |
|
17 |
// should we load a form theme?
|
18 |
+
if( isset( $_GET['form-theme'] ) ) {
|
19 |
$form_theme = strtolower( trim( $_GET['form-theme'] ) );
|
20 |
|
21 |
// only load themes we actually have
|
22 |
+
if( in_array( $form_theme, array( 'blue', 'green', 'dark', 'light', 'red' ) ) ) {
|
23 |
// load theme base file
|
24 |
+
readfile( dirname( __FILE__ ) . '/form-theme-base.css' );
|
25 |
|
26 |
// load theme file
|
27 |
+
readfile( dirname( __FILE__ ) . '/form-theme-'. $form_theme .'.css' );
|
28 |
}
|
29 |
|
30 |
}
|
assets/css/form-reset.css
CHANGED
@@ -1,20 +1,20 @@
|
|
1 |
|
2 |
/* MailChimp for WP - Default Form Styles */
|
3 |
.mc4wp-form{
|
4 |
-
margin:1em 0;
|
5 |
}
|
6 |
|
7 |
.mc4wp-form label{
|
8 |
-
display:block;
|
9 |
-
font-weight:bold;
|
10 |
-
margin-bottom:5px;
|
11 |
}
|
12 |
|
13 |
.mc4wp-form ul,
|
14 |
.mc4wp-form li {
|
15 |
-
list-style:none;
|
16 |
-
margin:0;
|
17 |
-
padding:0;
|
18 |
}
|
19 |
|
20 |
.mc4wp-form label > span,
|
@@ -26,7 +26,9 @@
|
|
26 |
margin-top: 10px;
|
27 |
}
|
28 |
|
29 |
-
.mc4wp-form input.placeholdersjs {
|
|
|
|
|
30 |
|
31 |
.mc4wp-form input[type="text"],
|
32 |
.mc4wp-form input[type="email"],
|
@@ -36,23 +38,23 @@
|
|
36 |
.mc4wp-form textarea,
|
37 |
.mc4wp-form select {
|
38 |
cursor: auto;
|
39 |
-
display:block;
|
40 |
-
width:100%;
|
41 |
-
height:auto;
|
42 |
-
box-sizing:border-box;
|
43 |
-webkit-box-sizing: border-box;
|
44 |
-moz-box-sizing: border-box;
|
45 |
}
|
46 |
|
47 |
.mc4wp-form input[type="checkbox"],
|
48 |
.mc4wp-form input[type="radio"] {
|
49 |
-
position:relative;
|
50 |
-
margin:0 6px 0 0;
|
51 |
-
padding:0;
|
52 |
-
height:13px;
|
53 |
-
width:13px;
|
54 |
-
display:inline-block;
|
55 |
-
border:0;
|
56 |
}
|
57 |
|
58 |
.mc4wp-form input[type="checkbox"] {
|
@@ -67,10 +69,36 @@
|
|
67 |
.mc4wp-form button,
|
68 |
.mc4wp-form input[type="button"] {
|
69 |
cursor: pointer;
|
70 |
-
display:inline-block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
}
|
72 |
|
73 |
-
.mc4wp-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
1 |
|
2 |
/* MailChimp for WP - Default Form Styles */
|
3 |
.mc4wp-form{
|
4 |
+
margin: 1em 0;
|
5 |
}
|
6 |
|
7 |
.mc4wp-form label{
|
8 |
+
display: block;
|
9 |
+
font-weight: bold;
|
10 |
+
margin-bottom: 5px;
|
11 |
}
|
12 |
|
13 |
.mc4wp-form ul,
|
14 |
.mc4wp-form li {
|
15 |
+
list-style: none;
|
16 |
+
margin: 0;
|
17 |
+
padding: 0;
|
18 |
}
|
19 |
|
20 |
.mc4wp-form label > span,
|
26 |
margin-top: 10px;
|
27 |
}
|
28 |
|
29 |
+
.mc4wp-form input.placeholdersjs {
|
30 |
+
color: #aaa !important;
|
31 |
+
}
|
32 |
|
33 |
.mc4wp-form input[type="text"],
|
34 |
.mc4wp-form input[type="email"],
|
38 |
.mc4wp-form textarea,
|
39 |
.mc4wp-form select {
|
40 |
cursor: auto;
|
41 |
+
display: block;
|
42 |
+
width: 100%;
|
43 |
+
height: auto;
|
44 |
+
box-sizing: border-box;
|
45 |
-webkit-box-sizing: border-box;
|
46 |
-moz-box-sizing: border-box;
|
47 |
}
|
48 |
|
49 |
.mc4wp-form input[type="checkbox"],
|
50 |
.mc4wp-form input[type="radio"] {
|
51 |
+
position: relative;
|
52 |
+
margin: 0 6px 0 0;
|
53 |
+
padding: 0;
|
54 |
+
height: 13px;
|
55 |
+
width: 13px;
|
56 |
+
display: inline-block;
|
57 |
+
border: 0;
|
58 |
}
|
59 |
|
60 |
.mc4wp-form input[type="checkbox"] {
|
69 |
.mc4wp-form button,
|
70 |
.mc4wp-form input[type="button"] {
|
71 |
cursor: pointer;
|
72 |
+
display: inline-block;
|
73 |
+
}
|
74 |
+
|
75 |
+
.mc4wp-alert{
|
76 |
+
margin: 1em 0;
|
77 |
+
padding: 10px 15px;
|
78 |
+
color: #c09853;
|
79 |
+
background-color: #fcf8e3;
|
80 |
+
border: 1px solid #fbeed5;
|
81 |
+
border-radius: 2px;
|
82 |
+
-moz-border-radius: 2px;
|
83 |
+
-webkit-border-radius: 2px;
|
84 |
+
display: block;
|
85 |
+
position: relative;
|
86 |
+
}
|
87 |
+
|
88 |
+
.mc4wp-success {
|
89 |
+
color: #468847;
|
90 |
+
background-color: #dff0d8;
|
91 |
+
border-color: #d6e9c6;
|
92 |
+
}
|
93 |
+
|
94 |
+
.mc4wp-notice {
|
95 |
+
color: #3a87ad;
|
96 |
+
background-color: #d9edf7;
|
97 |
+
border-color: #bce8f1;
|
98 |
}
|
99 |
|
100 |
+
.mc4wp-error {
|
101 |
+
color: #b94a48;
|
102 |
+
background-color: #f2dede;
|
103 |
+
border-color: #eed3d7;
|
104 |
+
}
|
assets/css/form.css
DELETED
@@ -1,23 +0,0 @@
|
|
1 |
-
|
2 |
-
/* MailChimp for WP - Default Form Styles */
|
3 |
-
.mc4wp-form{ margin:1em 0; }
|
4 |
-
.mc4wp-form p{ text-align:left; }
|
5 |
-
.mc4wp-form label{ display:block; font-weight:bold; margin-bottom:3px; text-align:left; }
|
6 |
-
.mc4wp-form label > span, .mc4wp-form li > label{ font-weight: normal; }
|
7 |
-
|
8 |
-
.mc4wp-form input[type="text"],
|
9 |
-
.mc4wp-form input[type="email"],
|
10 |
-
.mc4wp-form input[type="tel"],
|
11 |
-
.mc4wp-form input[type="url"] { display:inline-block; width:100%; height:auto; box-sizing:border-box; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; }
|
12 |
-
|
13 |
-
.mc4wp-form input[type="checkbox"] { margin:0 10px 0 0; padding:0; height:13px; width:13px;
|
14 |
-
display:inline-block; -webkit-appearance: checkbox; border:0; }
|
15 |
-
.mc4wp-form input[type="radio"] { margin:0 10px 0 0; padding:0; height:13px; width:13px;
|
16 |
-
display:inline-block; -webkit-appearance: radio; border:0; }
|
17 |
-
.mc4wp-form select, .mc4wp-form input[type="date"] { min-width:35%; }
|
18 |
-
.mc4wp-form input[type="submit"], .mc4wp-form button{ display:inline-block; }
|
19 |
-
|
20 |
-
.mc4wp-alert{ margin:1em 0; padding: 10px 15px; color: #c09853; background-color: #fcf8e3; border: 1px solid #fbeed5; border-radius: 2px; -moz-border-radius:2px; -webkit-border-radius:2px; display:block; position:relative;}
|
21 |
-
.mc4wp-success { color: #468847; background-color: #dff0d8; border-color: #d6e9c6; }
|
22 |
-
.mc4wp-notice { color: #3a87ad; background-color: #d9edf7; border-color: #bce8f1; }
|
23 |
-
.mc4wp-error { color: #b94a48; background-color: #f2dede; border-color: #eed3d7;; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-admin.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
if( ! defined("MC4WP_LITE_VERSION") ) {
|
4 |
header( 'Status: 403 Forbidden' );
|
5 |
header( 'HTTP/1.1 403 Forbidden' );
|
6 |
exit;
|
@@ -11,10 +11,10 @@ class MC4WP_Lite_Admin
|
|
11 |
private static $instance = null;
|
12 |
|
13 |
public static function init() {
|
14 |
-
if(!self::$instance) {
|
15 |
self::$instance = new self();
|
16 |
} else {
|
17 |
-
throw new Exception("Already initalized.");
|
18 |
}
|
19 |
}
|
20 |
|
@@ -24,55 +24,77 @@ class MC4WP_Lite_Admin
|
|
24 |
add_action('admin_menu', array($this, 'build_menu'));
|
25 |
add_action( 'admin_enqueue_scripts', array($this, 'load_css_and_js') );
|
26 |
|
27 |
-
register_activation_hook( 'mailchimp-for-wp/mailchimp-for-wp.php', array($this, 'delete_transients') );
|
28 |
-
register_deactivation_hook( 'mailchimp-for-wp/mailchimp-for-wp.php', array($this, 'delete_transients') );
|
29 |
|
30 |
-
add_filter("plugin_action_links_mailchimp-for-wp/mailchimp-for-wp.php", array($this, 'add_settings_link'));
|
31 |
|
32 |
// did the user click on upgrade to pro link?
|
33 |
-
if(isset($_GET['page'])) {
|
34 |
|
35 |
-
if($_GET['page'] == 'mc4wp-lite-upgrade' && !headers_sent()) {
|
36 |
header("Location: http://dannyvankooten.com/mailchimp-for-wordpress/?utm_source=lite-plugin&utm_medium=link&utm_campaign=menu-upgrade-link");
|
37 |
exit;
|
38 |
}
|
39 |
|
40 |
-
if($_GET['page'] == 'mc4wp-lite-form-settings') {
|
41 |
-
add_filter('quicktags_settings', array($this, 'set_quicktags_buttons'), 10, 2 );
|
42 |
}
|
43 |
}
|
44 |
}
|
45 |
|
|
|
|
|
|
|
46 |
public function delete_transients()
|
47 |
{
|
48 |
-
delete_transient('mc4wp_mailchimp_lists');
|
49 |
-
delete_transient('mc4wp_mailchimp_lists_fallback');
|
50 |
}
|
51 |
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
{
|
54 |
-
if($editor_id
|
|
|
|
|
55 |
|
56 |
-
// strong,em,link,block,del,ins,img,ul,ol,li,code,more,close
|
57 |
$settings['buttons'] = 'strong,em,link,block,img,ul,ol,li,close';
|
|
|
58 |
return $settings;
|
59 |
}
|
60 |
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
62 |
{
|
63 |
$settings_link = '<a href="admin.php?page=mc4wp-lite">'. __('Settings') . '</a>';
|
64 |
$upgrade_link = '<a href="http://dannyvankooten.com/mailchimp-for-wordpress/">Upgrade to Pro</a>';
|
65 |
-
array_unshift($links, $upgrade_link, $settings_link);
|
66 |
return $links;
|
67 |
}
|
68 |
|
|
|
|
|
|
|
69 |
public function register_settings()
|
70 |
{
|
71 |
-
register_setting('mc4wp_lite_settings', 'mc4wp_lite', array($this, 'validate_settings') );
|
72 |
-
register_setting('mc4wp_lite_checkbox_settings', 'mc4wp_lite_checkbox');
|
73 |
-
register_setting('mc4wp_lite_form_settings', 'mc4wp_lite_form');
|
74 |
}
|
75 |
|
|
|
|
|
|
|
76 |
public function build_menu()
|
77 |
{
|
78 |
$required_cap = apply_filters( 'mc4wp_settings_cap', 'manage_options' );
|
@@ -83,6 +105,13 @@ class MC4WP_Lite_Admin
|
|
83 |
add_submenu_page( 'mc4wp-lite', 'Upgrade to Pro - MailChimp for WP Lite', 'Upgrade to Pro', $required_cap, 'mc4wp-lite-upgrade', array( $this, 'redirect_to_pro' ) );
|
84 |
}
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
public function validate_settings( $settings ) {
|
87 |
|
88 |
if( isset( $settings['api_key'] ) ) {
|
@@ -92,8 +121,30 @@ class MC4WP_Lite_Admin
|
|
92 |
return $settings;
|
93 |
}
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
public function load_css_and_js( $hook )
|
96 |
{
|
|
|
97 |
if( ! isset( $_GET['page'] ) || stristr( $_GET['page'], 'mc4wp-lite' ) == false ) {
|
98 |
return;
|
99 |
}
|
@@ -107,6 +158,10 @@ class MC4WP_Lite_Admin
|
|
107 |
wp_enqueue_script( array( 'jquery', 'mc4wp-beautifyhtml', 'mc4wp-admin-js' ) );
|
108 |
}
|
109 |
|
|
|
|
|
|
|
|
|
110 |
public function get_checkbox_compatible_plugins()
|
111 |
{
|
112 |
$checkbox_plugins = array(
|
@@ -124,38 +179,50 @@ class MC4WP_Lite_Admin
|
|
124 |
return $checkbox_plugins;
|
125 |
}
|
126 |
|
|
|
|
|
|
|
127 |
public function redirect_to_pro()
|
128 |
{
|
129 |
?><script>window.location.replace('http://dannyvankooten.com/mailchimp-for-wordpress/'); </script><?php
|
130 |
}
|
131 |
|
|
|
|
|
|
|
132 |
public function show_api_settings()
|
133 |
{
|
134 |
-
$opts = mc4wp_get_options('general');
|
135 |
$tab = 'api-settings';
|
136 |
|
137 |
-
if(empty($opts['api_key'])) {
|
138 |
$connected = false;
|
139 |
} else {
|
140 |
-
$connected = (mc4wp_get_api()->is_connected());
|
141 |
}
|
142 |
|
143 |
$lists = $this->get_mailchimp_lists();
|
144 |
include_once MC4WP_LITE_PLUGIN_DIR . 'includes/views/api-settings.php';
|
145 |
}
|
146 |
|
|
|
|
|
|
|
147 |
public function show_checkbox_settings()
|
148 |
{
|
149 |
-
$opts = mc4wp_get_options('checkbox');
|
150 |
$lists = $this->get_mailchimp_lists();
|
151 |
|
152 |
$tab = 'checkbox-settings';
|
153 |
include_once MC4WP_LITE_PLUGIN_DIR . 'includes/views/checkbox-settings.php';
|
154 |
}
|
155 |
|
|
|
|
|
|
|
156 |
public function show_form_settings()
|
157 |
{
|
158 |
-
$opts = mc4wp_get_options('form');
|
159 |
$lists = $this->get_mailchimp_lists();
|
160 |
$tab = 'form-settings';
|
161 |
include_once MC4WP_LITE_PLUGIN_DIR . 'includes/views/form-settings.php';
|
@@ -164,32 +231,34 @@ class MC4WP_Lite_Admin
|
|
164 |
/**
|
165 |
* Get MailChimp lists
|
166 |
* Try cache first, then try API, then try fallback cache.
|
|
|
|
|
167 |
*/
|
168 |
private function get_mailchimp_lists()
|
169 |
{
|
170 |
$cached_lists = get_transient( 'mc4wp_mailchimp_lists' );
|
171 |
-
$refresh_cache = (isset($_REQUEST['renew-cached-data']));
|
172 |
|
173 |
// force cache refresh if merge_vars are not set (deprecated)
|
174 |
-
if(
|
175 |
-
if(!is_array($cached_lists)) {
|
176 |
$refresh_cache = true;
|
177 |
} else {
|
178 |
-
$first_list = reset($cached_lists);
|
179 |
-
$refresh_cache = !isset($first_list->merge_vars);
|
180 |
}
|
181 |
}
|
182 |
|
183 |
-
if($refresh_cache || !$cached_lists) {
|
184 |
// make api request for lists
|
185 |
$api = mc4wp_get_api();
|
186 |
$lists = array();
|
187 |
$lists_data = $api->get_lists();
|
188 |
|
189 |
-
if($lists_data) {
|
190 |
|
191 |
$list_ids = array();
|
192 |
-
foreach($lists_data as $list) {
|
193 |
$list_ids[] = $list->id;
|
194 |
|
195 |
$lists["{$list->id}"] = (object) array(
|
@@ -201,38 +270,41 @@ class MC4WP_Lite_Admin
|
|
201 |
);
|
202 |
|
203 |
// get interest groupings
|
204 |
-
$groupings_data = $api->get_list_groupings($list->id);
|
205 |
-
if($groupings_data) {
|
206 |
-
$lists["{$list->id}"]->interest_groupings = array_map(array($this, 'strip_unnecessary_grouping_properties'), $groupings_data);
|
207 |
}
|
208 |
}
|
209 |
|
210 |
// get merge vars for all lists at once
|
211 |
-
$merge_vars_data = $api->get_lists_with_merge_vars($list_ids);
|
212 |
-
if($merge_vars_data) {
|
213 |
-
foreach($merge_vars_data as $list) {
|
214 |
// add merge vars to list
|
215 |
-
$lists["{$list->id}"]->merge_vars = array_map(array($this, 'strip_unnecessary_merge_vars_properties'), $list->merge_vars);
|
216 |
}
|
217 |
}
|
218 |
|
219 |
// cache renewal triggered manually?
|
220 |
-
if(isset($_POST['renew-cached-data'])) {
|
221 |
-
if($lists) {
|
222 |
-
add_settings_error("mc4wp", "cache-renewed", 'Renewed MailChimp cache.', 'updated' );
|
223 |
} else {
|
224 |
-
add_settings_error("mc4wp", "cache-renew-failed", 'Failed to renew MailChimp cache - please try again later.' );
|
225 |
}
|
226 |
}
|
227 |
|
228 |
// store lists in transients
|
229 |
-
set_transient('mc4wp_mailchimp_lists', $lists, (24 * 3600)); // 1 day
|
230 |
-
set_transient('mc4wp_mailchimp_lists_fallback', $lists, 1209600); // 2 weeks
|
231 |
return $lists;
|
232 |
} else {
|
233 |
// api request failed, get fallback data (with longer lifetime)
|
234 |
$cached_lists = get_transient('mc4wp_mailchimp_lists_fallback');
|
235 |
-
|
|
|
|
|
|
|
236 |
}
|
237 |
|
238 |
}
|
@@ -242,8 +314,10 @@ class MC4WP_Lite_Admin
|
|
242 |
|
243 |
/**
|
244 |
* Build the group array object which will be stored in cache
|
|
|
|
|
245 |
*/
|
246 |
-
public function strip_unnecessary_group_properties($group) {
|
247 |
return (object) array(
|
248 |
'name' => $group->name
|
249 |
);
|
@@ -251,21 +325,25 @@ class MC4WP_Lite_Admin
|
|
251 |
|
252 |
/**
|
253 |
* Build the groupings array object which will be stored in cache
|
|
|
|
|
254 |
*/
|
255 |
-
public function strip_unnecessary_grouping_properties($grouping)
|
256 |
{
|
257 |
return (object) array(
|
258 |
'id' => $grouping->id,
|
259 |
'name' => $grouping->name,
|
260 |
-
'groups' => array_map(array($this, 'strip_unnecessary_group_properties'), $grouping->groups),
|
261 |
'form_field' => $grouping->form_field
|
262 |
);
|
263 |
}
|
264 |
|
265 |
/**
|
266 |
* Build the merge_var array object which will be stored in cache
|
|
|
|
|
267 |
*/
|
268 |
-
public function strip_unnecessary_merge_vars_properties($merge_var)
|
269 |
{
|
270 |
$array = array(
|
271 |
'name' => $merge_var->name,
|
@@ -279,7 +357,6 @@ class MC4WP_Lite_Admin
|
|
279 |
}
|
280 |
|
281 |
return (object) $array;
|
282 |
-
|
283 |
}
|
284 |
|
285 |
}
|
1 |
<?php
|
2 |
|
3 |
+
if( ! defined( "MC4WP_LITE_VERSION" ) ) {
|
4 |
header( 'Status: 403 Forbidden' );
|
5 |
header( 'HTTP/1.1 403 Forbidden' );
|
6 |
exit;
|
11 |
private static $instance = null;
|
12 |
|
13 |
public static function init() {
|
14 |
+
if( ! self::$instance ) {
|
15 |
self::$instance = new self();
|
16 |
} else {
|
17 |
+
throw new Exception( "Already initalized." );
|
18 |
}
|
19 |
}
|
20 |
|
24 |
add_action('admin_menu', array($this, 'build_menu'));
|
25 |
add_action( 'admin_enqueue_scripts', array($this, 'load_css_and_js') );
|
26 |
|
27 |
+
register_activation_hook( 'mailchimp-for-wp/mailchimp-for-wp.php', array( $this, 'delete_transients' ) );
|
28 |
+
register_deactivation_hook( 'mailchimp-for-wp/mailchimp-for-wp.php', array( $this, 'delete_transients' ) );
|
29 |
|
30 |
+
add_filter( "plugin_action_links_mailchimp-for-wp/mailchimp-for-wp.php", array( $this, 'add_settings_link' ) );
|
31 |
|
32 |
// did the user click on upgrade to pro link?
|
33 |
+
if( isset( $_GET['page'] ) ) {
|
34 |
|
35 |
+
if( $_GET['page'] == 'mc4wp-lite-upgrade' && ! headers_sent() ) {
|
36 |
header("Location: http://dannyvankooten.com/mailchimp-for-wordpress/?utm_source=lite-plugin&utm_medium=link&utm_campaign=menu-upgrade-link");
|
37 |
exit;
|
38 |
}
|
39 |
|
40 |
+
if( $_GET['page'] == 'mc4wp-lite-form-settings' ) {
|
41 |
+
add_filter( 'quicktags_settings', array( $this, 'set_quicktags_buttons' ), 10, 2 );
|
42 |
}
|
43 |
}
|
44 |
}
|
45 |
|
46 |
+
/**
|
47 |
+
* Delete the list transients on plugin (de)activation
|
48 |
+
*/
|
49 |
public function delete_transients()
|
50 |
{
|
51 |
+
delete_transient( 'mc4wp_mailchimp_lists' );
|
52 |
+
delete_transient( 'mc4wp_mailchimp_lists_fallback' );
|
53 |
}
|
54 |
|
55 |
+
/**
|
56 |
+
* Set which Quicktag buttons should appear in the form mark-up editor
|
57 |
+
* @param array $settings
|
58 |
+
* @param string $editor_id
|
59 |
+
* @return array
|
60 |
+
*/
|
61 |
+
public function set_quicktags_buttons( $settings, $editor_id = '')
|
62 |
{
|
63 |
+
if( $editor_id !== 'mc4wpformmarkup' ) {
|
64 |
+
return $settings;
|
65 |
+
}
|
66 |
|
|
|
67 |
$settings['buttons'] = 'strong,em,link,block,img,ul,ol,li,close';
|
68 |
+
|
69 |
return $settings;
|
70 |
}
|
71 |
|
72 |
+
/**
|
73 |
+
* Add the settings link to the Plugins overview
|
74 |
+
* @param array $links
|
75 |
+
* @return array
|
76 |
+
*/
|
77 |
+
public function add_settings_link( $links )
|
78 |
{
|
79 |
$settings_link = '<a href="admin.php?page=mc4wp-lite">'. __('Settings') . '</a>';
|
80 |
$upgrade_link = '<a href="http://dannyvankooten.com/mailchimp-for-wordpress/">Upgrade to Pro</a>';
|
81 |
+
array_unshift( $links, $upgrade_link, $settings_link );
|
82 |
return $links;
|
83 |
}
|
84 |
|
85 |
+
/**
|
86 |
+
* Register the various MailChimp for WordPress settings
|
87 |
+
*/
|
88 |
public function register_settings()
|
89 |
{
|
90 |
+
register_setting( 'mc4wp_lite_settings', 'mc4wp_lite', array( $this, 'validate_settings' ) );
|
91 |
+
register_setting( 'mc4wp_lite_checkbox_settings', 'mc4wp_lite_checkbox');
|
92 |
+
register_setting( 'mc4wp_lite_form_settings', 'mc4wp_lite_form', array( $this, 'validate_form_settings' ) );
|
93 |
}
|
94 |
|
95 |
+
/**
|
96 |
+
* Register the setting pages and their menu items
|
97 |
+
*/
|
98 |
public function build_menu()
|
99 |
{
|
100 |
$required_cap = apply_filters( 'mc4wp_settings_cap', 'manage_options' );
|
105 |
add_submenu_page( 'mc4wp-lite', 'Upgrade to Pro - MailChimp for WP Lite', 'Upgrade to Pro', $required_cap, 'mc4wp-lite-upgrade', array( $this, 'redirect_to_pro' ) );
|
106 |
}
|
107 |
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Validates the General settings
|
111 |
+
*
|
112 |
+
* @param array $settings
|
113 |
+
* @return array
|
114 |
+
*/
|
115 |
public function validate_settings( $settings ) {
|
116 |
|
117 |
if( isset( $settings['api_key'] ) ) {
|
121 |
return $settings;
|
122 |
}
|
123 |
|
124 |
+
/**
|
125 |
+
* Validates the Form settings
|
126 |
+
*
|
127 |
+
* @param array $settings
|
128 |
+
* @return array
|
129 |
+
*/
|
130 |
+
public function validate_form_settings( $settings ) {
|
131 |
+
|
132 |
+
if( isset( $settings['markup'] ) ) {
|
133 |
+
|
134 |
+
// strip form tags (to prevent people from adding them)
|
135 |
+
$settings['markup'] = preg_replace( '/<\/?form(.|\s)*?>/i', '', $settings['markup'] );
|
136 |
+
|
137 |
+
}
|
138 |
+
|
139 |
+
return $settings;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* @param string $hook
|
144 |
+
*/
|
145 |
public function load_css_and_js( $hook )
|
146 |
{
|
147 |
+
// only load files on the MailChimp for WordPress page
|
148 |
if( ! isset( $_GET['page'] ) || stristr( $_GET['page'], 'mc4wp-lite' ) == false ) {
|
149 |
return;
|
150 |
}
|
158 |
wp_enqueue_script( array( 'jquery', 'mc4wp-beautifyhtml', 'mc4wp-admin-js' ) );
|
159 |
}
|
160 |
|
161 |
+
/**
|
162 |
+
* Returns available checkbox integrations
|
163 |
+
* @return array
|
164 |
+
*/
|
165 |
public function get_checkbox_compatible_plugins()
|
166 |
{
|
167 |
$checkbox_plugins = array(
|
179 |
return $checkbox_plugins;
|
180 |
}
|
181 |
|
182 |
+
/**
|
183 |
+
* Redirects to the premium version of MailChimp for WordPress (uses JS)
|
184 |
+
*/
|
185 |
public function redirect_to_pro()
|
186 |
{
|
187 |
?><script>window.location.replace('http://dannyvankooten.com/mailchimp-for-wordpress/'); </script><?php
|
188 |
}
|
189 |
|
190 |
+
/**
|
191 |
+
* Show the API settings page
|
192 |
+
*/
|
193 |
public function show_api_settings()
|
194 |
{
|
195 |
+
$opts = mc4wp_get_options( 'general' );
|
196 |
$tab = 'api-settings';
|
197 |
|
198 |
+
if( empty( $opts['api_key'] ) ) {
|
199 |
$connected = false;
|
200 |
} else {
|
201 |
+
$connected = ( mc4wp_get_api()->is_connected() );
|
202 |
}
|
203 |
|
204 |
$lists = $this->get_mailchimp_lists();
|
205 |
include_once MC4WP_LITE_PLUGIN_DIR . 'includes/views/api-settings.php';
|
206 |
}
|
207 |
|
208 |
+
/**
|
209 |
+
* Show the Checkbox settings page
|
210 |
+
*/
|
211 |
public function show_checkbox_settings()
|
212 |
{
|
213 |
+
$opts = mc4wp_get_options( 'checkbox' );
|
214 |
$lists = $this->get_mailchimp_lists();
|
215 |
|
216 |
$tab = 'checkbox-settings';
|
217 |
include_once MC4WP_LITE_PLUGIN_DIR . 'includes/views/checkbox-settings.php';
|
218 |
}
|
219 |
|
220 |
+
/**
|
221 |
+
* Show the forms settings page
|
222 |
+
*/
|
223 |
public function show_form_settings()
|
224 |
{
|
225 |
+
$opts = mc4wp_get_options( 'form' );
|
226 |
$lists = $this->get_mailchimp_lists();
|
227 |
$tab = 'form-settings';
|
228 |
include_once MC4WP_LITE_PLUGIN_DIR . 'includes/views/form-settings.php';
|
231 |
/**
|
232 |
* Get MailChimp lists
|
233 |
* Try cache first, then try API, then try fallback cache.
|
234 |
+
*
|
235 |
+
* @return array
|
236 |
*/
|
237 |
private function get_mailchimp_lists()
|
238 |
{
|
239 |
$cached_lists = get_transient( 'mc4wp_mailchimp_lists' );
|
240 |
+
$refresh_cache = ( isset( $_REQUEST['renew-cached-data'] ) );
|
241 |
|
242 |
// force cache refresh if merge_vars are not set (deprecated)
|
243 |
+
if( ! $refresh_cache && $cached_lists ) {
|
244 |
+
if( ! is_array( $cached_lists ) ) {
|
245 |
$refresh_cache = true;
|
246 |
} else {
|
247 |
+
$first_list = reset( $cached_lists );
|
248 |
+
$refresh_cache = ! isset( $first_list->merge_vars );
|
249 |
}
|
250 |
}
|
251 |
|
252 |
+
if( $refresh_cache || !$cached_lists ) {
|
253 |
// make api request for lists
|
254 |
$api = mc4wp_get_api();
|
255 |
$lists = array();
|
256 |
$lists_data = $api->get_lists();
|
257 |
|
258 |
+
if( $lists_data ) {
|
259 |
|
260 |
$list_ids = array();
|
261 |
+
foreach( $lists_data as $list ) {
|
262 |
$list_ids[] = $list->id;
|
263 |
|
264 |
$lists["{$list->id}"] = (object) array(
|
270 |
);
|
271 |
|
272 |
// get interest groupings
|
273 |
+
$groupings_data = $api->get_list_groupings( $list->id );
|
274 |
+
if( $groupings_data ) {
|
275 |
+
$lists["{$list->id}"]->interest_groupings = array_map( array( $this, 'strip_unnecessary_grouping_properties' ), $groupings_data );
|
276 |
}
|
277 |
}
|
278 |
|
279 |
// get merge vars for all lists at once
|
280 |
+
$merge_vars_data = $api->get_lists_with_merge_vars( $list_ids );
|
281 |
+
if( $merge_vars_data ) {
|
282 |
+
foreach( $merge_vars_data as $list ) {
|
283 |
// add merge vars to list
|
284 |
+
$lists["{$list->id}"]->merge_vars = array_map( array( $this, 'strip_unnecessary_merge_vars_properties' ), $list->merge_vars );
|
285 |
}
|
286 |
}
|
287 |
|
288 |
// cache renewal triggered manually?
|
289 |
+
if( isset( $_POST['renew-cached-data'] ) ) {
|
290 |
+
if( $lists ) {
|
291 |
+
add_settings_error( "mc4wp", "cache-renewed", 'Renewed MailChimp cache.', 'updated' );
|
292 |
} else {
|
293 |
+
add_settings_error( "mc4wp", "cache-renew-failed", 'Failed to renew MailChimp cache - please try again later.' );
|
294 |
}
|
295 |
}
|
296 |
|
297 |
// store lists in transients
|
298 |
+
set_transient( 'mc4wp_mailchimp_lists', $lists, ( 24 * 3600 ) ); // 1 day
|
299 |
+
set_transient( 'mc4wp_mailchimp_lists_fallback', $lists, 1209600 ); // 2 weeks
|
300 |
return $lists;
|
301 |
} else {
|
302 |
// api request failed, get fallback data (with longer lifetime)
|
303 |
$cached_lists = get_transient('mc4wp_mailchimp_lists_fallback');
|
304 |
+
|
305 |
+
if( ! $cached_lists ) {
|
306 |
+
return array();
|
307 |
+
}
|
308 |
}
|
309 |
|
310 |
}
|
314 |
|
315 |
/**
|
316 |
* Build the group array object which will be stored in cache
|
317 |
+
* @param object $group
|
318 |
+
* @return object
|
319 |
*/
|
320 |
+
public function strip_unnecessary_group_properties( $group ) {
|
321 |
return (object) array(
|
322 |
'name' => $group->name
|
323 |
);
|
325 |
|
326 |
/**
|
327 |
* Build the groupings array object which will be stored in cache
|
328 |
+
* @param object $grouping
|
329 |
+
* @return object
|
330 |
*/
|
331 |
+
public function strip_unnecessary_grouping_properties( $grouping )
|
332 |
{
|
333 |
return (object) array(
|
334 |
'id' => $grouping->id,
|
335 |
'name' => $grouping->name,
|
336 |
+
'groups' => array_map( array( $this, 'strip_unnecessary_group_properties' ), $grouping->groups ),
|
337 |
'form_field' => $grouping->form_field
|
338 |
);
|
339 |
}
|
340 |
|
341 |
/**
|
342 |
* Build the merge_var array object which will be stored in cache
|
343 |
+
* @param object $merge_var
|
344 |
+
* @return object
|
345 |
*/
|
346 |
+
public function strip_unnecessary_merge_vars_properties( $merge_var )
|
347 |
{
|
348 |
$array = array(
|
349 |
'name' => $merge_var->name,
|
357 |
}
|
358 |
|
359 |
return (object) $array;
|
|
|
360 |
}
|
361 |
|
362 |
}
|
includes/class-api.php
CHANGED
@@ -6,6 +6,10 @@ if( ! defined("MC4WP_LITE_VERSION") ) {
|
|
6 |
exit;
|
7 |
}
|
8 |
|
|
|
|
|
|
|
|
|
9 |
class MC4WP_Lite_API {
|
10 |
|
11 |
private $api_url = 'https://api.mailchimp.com/2.0/';
|
@@ -13,26 +17,72 @@ class MC4WP_Lite_API {
|
|
13 |
private $error_message = '';
|
14 |
private $connected = null;
|
15 |
|
16 |
-
|
|
|
|
|
|
|
17 |
{
|
18 |
$this->api_key = $api_key;
|
19 |
|
20 |
-
if(strpos($api_key, '-') !== false) {
|
21 |
-
$this->api_url = 'https://' . substr($api_key, -3) . '.api.mailchimp.com/2.0/';
|
22 |
}
|
23 |
}
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
public function is_connected()
|
26 |
{
|
27 |
-
if($this->connected
|
28 |
-
|
29 |
-
$this->connected =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
31 |
|
32 |
return $this->connected;
|
33 |
}
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
{
|
37 |
$data = array(
|
38 |
'id' => $list_id,
|
@@ -45,15 +95,17 @@ class MC4WP_Lite_API {
|
|
45 |
'send_welcome' => $send_welcome
|
46 |
);
|
47 |
|
48 |
-
$result = $this->call('lists/subscribe', $data);
|
49 |
|
50 |
-
if($result) {
|
51 |
|
52 |
-
if(!isset($result->error)) {
|
53 |
return true;
|
54 |
} else {
|
55 |
// check error
|
56 |
-
if($result->code == 214) {
|
|
|
|
|
57 |
|
58 |
// store error message
|
59 |
$this->error_message = $result->error;
|
@@ -65,67 +117,112 @@ class MC4WP_Lite_API {
|
|
65 |
}
|
66 |
}
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
69 |
{
|
70 |
-
$result = $this->call('lists/interest-groupings', array('id' => $list_id) );
|
71 |
-
if($result && is_array($result)) {
|
72 |
return $result;
|
73 |
} else {
|
74 |
return false;
|
75 |
}
|
76 |
}
|
77 |
|
|
|
|
|
|
|
|
|
78 |
public function get_lists()
|
79 |
{
|
80 |
-
$result = $this->call(
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
-
if($result && isset($result->data)) {
|
83 |
return $result->data;
|
84 |
} else {
|
85 |
return false;
|
86 |
}
|
87 |
}
|
88 |
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
90 |
{
|
91 |
-
$result = $this->call('lists/merge-vars', array('id' => $list_ids));
|
92 |
|
93 |
-
if($result && isset($result->data)) {
|
94 |
return $result->data;
|
95 |
} else {
|
96 |
return false;
|
97 |
}
|
98 |
}
|
99 |
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
-
if($result && isset($result->data)) {
|
104 |
return $result->data;
|
105 |
} else {
|
106 |
return false;
|
107 |
}
|
108 |
}
|
109 |
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
-
if( $member_info && is_array($member_info) ) {
|
114 |
-
return ($member_info[0]->status == "subscribed");
|
115 |
}
|
116 |
|
117 |
return false;
|
118 |
}
|
119 |
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
{
|
122 |
// do not make request when no api key was provided.
|
123 |
-
if(empty($this->api_key)) {
|
|
|
|
|
124 |
|
125 |
$data['apikey'] = $this->api_key;
|
126 |
$url = $this->api_url . $method . '.json';
|
127 |
|
128 |
-
$response = wp_remote_post($url, array(
|
129 |
'body' => $data,
|
130 |
'timeout' => 20,
|
131 |
'headers' => array('Accept-Encoding' => ''),
|
@@ -133,24 +230,40 @@ class MC4WP_Lite_API {
|
|
133 |
)
|
134 |
);
|
135 |
|
136 |
-
if(is_wp_error($response)) {
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
if($method == 'helper/ping' && isset($response['headers']['content-length']) && (int) $response['headers']['content-length'] == '44') {
|
141 |
-
return (object) array( 'msg' => "Everything's Chimpy!");
|
142 |
-
}
|
143 |
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
146 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
}
|
148 |
|
|
|
|
|
|
|
|
|
149 |
public function has_error()
|
150 |
{
|
151 |
-
return (!empty($this->error_message));
|
152 |
}
|
153 |
|
|
|
|
|
|
|
|
|
154 |
public function get_error_message()
|
155 |
{
|
156 |
return $this->error_message;
|
6 |
exit;
|
7 |
}
|
8 |
|
9 |
+
/**
|
10 |
+
* Takes care of requests to the MailChimp API
|
11 |
+
* @uses WP_HTTP
|
12 |
+
*/
|
13 |
class MC4WP_Lite_API {
|
14 |
|
15 |
private $api_url = 'https://api.mailchimp.com/2.0/';
|
17 |
private $error_message = '';
|
18 |
private $connected = null;
|
19 |
|
20 |
+
/**
|
21 |
+
* @param string $api_key MailChimp API key
|
22 |
+
*/
|
23 |
+
public function __construct( $api_key )
|
24 |
{
|
25 |
$this->api_key = $api_key;
|
26 |
|
27 |
+
if( strpos( $api_key, '-' ) !== false ) {
|
28 |
+
$this->api_url = 'https://' . substr( $api_key, -3 ) . '.api.mailchimp.com/2.0/';
|
29 |
}
|
30 |
}
|
31 |
|
32 |
+
/**
|
33 |
+
* Show an error message to administrators
|
34 |
+
*
|
35 |
+
* @param string $message
|
36 |
+
*/
|
37 |
+
private function show_error( $message ) {
|
38 |
+
if( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
|
39 |
+
return false;
|
40 |
+
}
|
41 |
+
|
42 |
+
add_settings_error( 'mc4wp-api', 'mc4wp-api-error', $message, 'error' );
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Pings the MailChimp API
|
47 |
+
* Will store its result to ensure a maximum of 1 ping per page load
|
48 |
+
*
|
49 |
+
* @return boolean
|
50 |
+
*/
|
51 |
public function is_connected()
|
52 |
{
|
53 |
+
if( $this->connected == null ) {
|
54 |
+
|
55 |
+
$this->connected = false;
|
56 |
+
$result = $this->call( 'helper/ping' );
|
57 |
+
|
58 |
+
if( $result !== false ) {
|
59 |
+
if( isset( $result->msg ) && $result->msg === "Everything's Chimpy!" ) {
|
60 |
+
$this->connected = true;
|
61 |
+
} else {
|
62 |
+
$this->show_error( "MailChimp Error: " . $result->error );
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
}
|
67 |
|
68 |
return $this->connected;
|
69 |
}
|
70 |
|
71 |
+
/**
|
72 |
+
* Sends a subscription request to the MailChimp API
|
73 |
+
*
|
74 |
+
* @param string $list_id
|
75 |
+
* @param string $email
|
76 |
+
* @param array $merge_vars
|
77 |
+
* @param string $email_type
|
78 |
+
* @param boolean $double_optin
|
79 |
+
* @param boolean $update_existing
|
80 |
+
* @param boolean $replace_interests
|
81 |
+
* @param boolean $send_welcome
|
82 |
+
*
|
83 |
+
* @return boolean|string True if success, 'error' if error
|
84 |
+
*/
|
85 |
+
public function subscribe( $list_id, $email, array $merge_vars = array(), $email_type = 'html', $double_optin = true, $update_existing = false, $replace_interests = true, $send_welcome = false )
|
86 |
{
|
87 |
$data = array(
|
88 |
'id' => $list_id,
|
95 |
'send_welcome' => $send_welcome
|
96 |
);
|
97 |
|
98 |
+
$result = $this->call( 'lists/subscribe', $data );
|
99 |
|
100 |
+
if( $result ) {
|
101 |
|
102 |
+
if( ! isset( $result->error ) ) {
|
103 |
return true;
|
104 |
} else {
|
105 |
// check error
|
106 |
+
if( $result->code == 214 ) {
|
107 |
+
return 'already_subscribed';
|
108 |
+
}
|
109 |
|
110 |
// store error message
|
111 |
$this->error_message = $result->error;
|
117 |
}
|
118 |
}
|
119 |
|
120 |
+
/**
|
121 |
+
* Gets the Groupings for a given List
|
122 |
+
* @param string $list_id
|
123 |
+
* @return array|boolean
|
124 |
+
*/
|
125 |
+
public function get_list_groupings( $list_id )
|
126 |
{
|
127 |
+
$result = $this->call( 'lists/interest-groupings', array( 'id' => $list_id ) );
|
128 |
+
if( $result && is_array( $result ) ) {
|
129 |
return $result;
|
130 |
} else {
|
131 |
return false;
|
132 |
}
|
133 |
}
|
134 |
|
135 |
+
/**
|
136 |
+
* Gets the lists for the current API Key
|
137 |
+
* @return array|boolean
|
138 |
+
*/
|
139 |
public function get_lists()
|
140 |
{
|
141 |
+
$result = $this->call(
|
142 |
+
'lists/list',
|
143 |
+
array(
|
144 |
+
'limit' => 100
|
145 |
+
)
|
146 |
+
);
|
147 |
|
148 |
+
if( $result && isset( $result->data ) ) {
|
149 |
return $result->data;
|
150 |
} else {
|
151 |
return false;
|
152 |
}
|
153 |
}
|
154 |
|
155 |
+
/**
|
156 |
+
* Get lists with their merge_vars for a given array of list id's
|
157 |
+
* @param array $list_ids
|
158 |
+
* @return array|boolean
|
159 |
+
*/
|
160 |
+
public function get_lists_with_merge_vars( $list_ids )
|
161 |
{
|
162 |
+
$result = $this->call( 'lists/merge-vars', array('id' => $list_ids ) );
|
163 |
|
164 |
+
if( $result && isset( $result->data ) ) {
|
165 |
return $result->data;
|
166 |
} else {
|
167 |
return false;
|
168 |
}
|
169 |
}
|
170 |
|
171 |
+
/**
|
172 |
+
* Gets the member info for one or multiple emails on a list
|
173 |
+
*
|
174 |
+
* @param string $list_id
|
175 |
+
* @param array $emails
|
176 |
+
* @return array
|
177 |
+
*/
|
178 |
+
public function get_member_info( $list_id, $emails ) {
|
179 |
+
$result = $this->call( 'lists/member-info', array( 'id' => $list_id, 'emails' => $emails ) );
|
180 |
|
181 |
+
if( $result && isset( $result->data ) ) {
|
182 |
return $result->data;
|
183 |
} else {
|
184 |
return false;
|
185 |
}
|
186 |
}
|
187 |
|
188 |
+
/**
|
189 |
+
* Checks if an email address is on a given list
|
190 |
+
*
|
191 |
+
* @param string $list_id
|
192 |
+
* @param string $email
|
193 |
+
* @return boolean
|
194 |
+
*/
|
195 |
+
public function list_has_subscriber( $list_id, $email ) {
|
196 |
+
$member_info = $this->get_member_info( $list_id, array( array( 'email' => $email ) ) );
|
197 |
|
198 |
+
if( $member_info && is_array( $member_info ) ) {
|
199 |
+
return ( $member_info[0]->status == "subscribed" );
|
200 |
}
|
201 |
|
202 |
return false;
|
203 |
}
|
204 |
|
205 |
+
/**
|
206 |
+
* Calls the MailChimp API
|
207 |
+
*
|
208 |
+
* @uses WP_HTTP
|
209 |
+
*
|
210 |
+
* @param string $method
|
211 |
+
* @param array $data
|
212 |
+
*
|
213 |
+
* @return object
|
214 |
+
*/
|
215 |
+
public function call( $method, array $data = array() )
|
216 |
{
|
217 |
// do not make request when no api key was provided.
|
218 |
+
if( empty( $this->api_key ) ) {
|
219 |
+
return false;
|
220 |
+
}
|
221 |
|
222 |
$data['apikey'] = $this->api_key;
|
223 |
$url = $this->api_url . $method . '.json';
|
224 |
|
225 |
+
$response = wp_remote_post( $url, array(
|
226 |
'body' => $data,
|
227 |
'timeout' => 20,
|
228 |
'headers' => array('Accept-Encoding' => ''),
|
230 |
)
|
231 |
);
|
232 |
|
233 |
+
if( is_wp_error( $response ) ) {
|
234 |
+
|
235 |
+
// show error message to admins
|
236 |
+
$this->show_error( "HTTP Error: " . $response->get_error_message() );
|
|
|
|
|
|
|
237 |
|
238 |
+
return false;
|
239 |
+
}
|
240 |
+
|
241 |
+
// dirty fix for older WP version
|
242 |
+
if($method == 'helper/ping' && isset( $response['headers']['content-length'] ) && (int) $response['headers']['content-length'] == '44' ) {
|
243 |
+
return (object) array( 'msg' => "Everything's Chimpy!");
|
244 |
}
|
245 |
+
|
246 |
+
$body = wp_remote_retrieve_body( $response );
|
247 |
+
return json_decode( $body );
|
248 |
+
}
|
249 |
+
|
250 |
+
public function show_http_error() {
|
251 |
+
|
252 |
}
|
253 |
|
254 |
+
/**
|
255 |
+
* Checks if an error occured in the most recent request
|
256 |
+
* @return boolean
|
257 |
+
*/
|
258 |
public function has_error()
|
259 |
{
|
260 |
+
return ( ! empty( $this->error_message ) );
|
261 |
}
|
262 |
|
263 |
+
/**
|
264 |
+
* Gets the most recent error message
|
265 |
+
* @return string
|
266 |
+
*/
|
267 |
public function get_error_message()
|
268 |
{
|
269 |
return $this->error_message;
|
includes/class-checkbox.php
CHANGED
@@ -79,23 +79,23 @@ class MC4WP_Lite_Checkbox
|
|
79 |
|
80 |
public function initialize()
|
81 |
{
|
82 |
-
if(function_exists("wpcf7_add_shortcode")) {
|
83 |
wpcf7_add_shortcode( 'mc4wp_checkbox', array( $this, 'get_checkbox') );
|
84 |
add_action( 'wpcf7_posted_data', array( $this, 'alter_cf7_data') );
|
85 |
add_action( 'wpcf7_mail_sent', array( $this, 'subscribe_from_cf7' ) );
|
86 |
}
|
87 |
|
88 |
// catch-all (for manual integrations with third-party forms)
|
89 |
-
if(isset($_POST['mc4wp-try-subscribe']) && $_POST['mc4wp-try-subscribe']) {
|
90 |
$this->subscribe_from_whatever();
|
91 |
}
|
92 |
}
|
93 |
|
94 |
-
public function get_checkbox($args = array())
|
95 |
{
|
96 |
$opts = mc4wp_get_options('checkbox');
|
97 |
|
98 |
-
$label = isset($args['labels'][0]) ? $args['labels'][0] : $opts['label'];
|
99 |
$checked = $opts['precheck'] ? "checked" : '';
|
100 |
|
101 |
// CF7 checkbox?
|
@@ -124,72 +124,94 @@ class MC4WP_Lite_Checkbox
|
|
124 |
return $content;
|
125 |
}
|
126 |
|
|
|
|
|
|
|
127 |
public function output_checkbox()
|
128 |
{
|
129 |
-
if($this->showed_checkbox)
|
|
|
|
|
|
|
|
|
130 |
echo $this->get_checkbox();
|
|
|
131 |
$this->showed_checkbox = true;
|
132 |
}
|
133 |
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
135 |
$stylesheets['checkbox'] = 1;
|
136 |
return $stylesheets;
|
137 |
}
|
138 |
|
139 |
|
140 |
/* Start comment form functions */
|
141 |
-
public function subscribe_from_comment($cid, $comment_approved = '')
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
|
146 |
-
$
|
|
|
|
|
|
|
|
|
147 |
|
148 |
$email = $comment->comment_author_email;
|
149 |
$merge_vars = array(
|
150 |
'OPTINIP' => $comment->comment_author_IP,
|
151 |
'NAME' => $comment->comment_author
|
152 |
-
|
153 |
|
154 |
-
return $this->subscribe($email, $merge_vars);
|
155 |
}
|
156 |
|
157 |
-
public function add_comment_meta($comment_id)
|
158 |
-
{
|
159 |
add_comment_meta($comment_id, 'mc4wp_subscribe', $_POST['mc4wp-do-subscribe'], true );
|
160 |
}
|
161 |
/* End comment form functions */
|
162 |
|
163 |
/* Start registration form functions */
|
164 |
-
public function subscribe_from_registration($user_id)
|
165 |
-
|
166 |
-
if(!isset($_POST['mc4wp-do-subscribe']) || $_POST['mc4wp-do-subscribe'] != 1) {
|
|
|
|
|
167 |
|
168 |
// gather emailadress from user who WordPress registered
|
169 |
-
$user = get_userdata($user_id);
|
170 |
-
if(
|
|
|
|
|
171 |
|
172 |
$email = $user->user_email;
|
173 |
$merge_vars = array(
|
174 |
'NAME' => $user->user_login
|
175 |
);
|
176 |
|
177 |
-
if(isset($user->user_firstname) && !empty($user->user_firstname)) {
|
178 |
$merge_vars['FNAME'] = $user->user_firstname;
|
179 |
}
|
180 |
|
181 |
-
if(isset($user->user_lastname) && !empty($user->user_lastname)) {
|
182 |
$merge_vars['LNAME'] = $user->user_lastname;
|
183 |
}
|
184 |
|
185 |
-
$result = $this->subscribe($email, $merge_vars);
|
186 |
}
|
187 |
/* End registration form functions */
|
188 |
|
189 |
/* Start BuddyPress functions */
|
190 |
public function subscribe_from_buddypress()
|
191 |
{
|
192 |
-
if(!isset($_POST['mc4wp-do-subscribe']) || $_POST['mc4wp-do-subscribe'] != 1)
|
|
|
|
|
193 |
|
194 |
// gather emailadress and name from user who BuddyPress registered
|
195 |
$email = $_POST['signup_email'];
|
@@ -197,66 +219,91 @@ class MC4WP_Lite_Checkbox
|
|
197 |
'NAME' => $_POST['signup_username']
|
198 |
);
|
199 |
|
200 |
-
|
201 |
}
|
202 |
/* End BuddyPress functions */
|
203 |
|
204 |
/* Start Multisite functions */
|
205 |
public function add_multisite_hidden_checkbox()
|
206 |
{
|
207 |
-
?><input type="hidden" name="mc4wp-do-subscribe" value="<?php echo (isset($_POST['mc4wp-do-subscribe'])) ? 1 : 0; ?>" /><?php
|
208 |
}
|
209 |
|
210 |
-
public function on_multisite_blog_signup($blog_id, $user_id, $a, $b ,$meta = null)
|
211 |
{
|
212 |
-
if(!isset($meta['mc4wp-do-subscribe']) || $meta['mc4wp-do-subscribe'] != 1)
|
213 |
-
|
|
|
|
|
214 |
return $this->subscribe_from_multisite($user_id);
|
215 |
}
|
216 |
|
217 |
public function on_multisite_user_signup($user_id, $password = NULL, $meta = NULL)
|
218 |
{
|
219 |
-
if(!isset($meta['mc4wp-do-subscribe']) || $meta['mc4wp-do-subscribe'] != 1)
|
220 |
-
|
|
|
|
|
221 |
return $this->subscribe_from_multisite($user_id);
|
222 |
}
|
223 |
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
{
|
226 |
-
$meta['mc4wp-do-subscribe'] = (isset($_POST['mc4wp-do-subscribe'])) ? 1 : 0;
|
227 |
return $meta;
|
228 |
}
|
229 |
|
230 |
-
|
|
|
|
|
|
|
|
|
231 |
{
|
232 |
-
$user = get_userdata($user_id);
|
233 |
|
234 |
-
if(!is_object($user))
|
|
|
|
|
235 |
|
236 |
$email = $user->user_email;
|
237 |
$merge_vars = array(
|
238 |
'NAME' => $user->first_name . ' ' . $user->last_name
|
239 |
);
|
240 |
-
$result = $this->subscribe($email, $merge_vars);
|
241 |
}
|
242 |
/* End Multisite functions */
|
243 |
|
244 |
/* Start Contact Form 7 functions */
|
245 |
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
247 |
$data['mc4wp_checkbox'] = ( isset( $_POST['mc4wp-do-subscribe'] ) && $_POST['mc4wp-do-subscribe'] == 1 ) ? __("Yes") : __("No");
|
248 |
return $data;
|
249 |
}
|
250 |
|
251 |
-
|
|
|
|
|
|
|
|
|
252 |
{
|
253 |
// check if CF7 "mc4wp" checkbox was checked
|
254 |
-
if(!isset($_POST['mc4wp-do-subscribe']) ||
|
255 |
return false;
|
256 |
}
|
257 |
|
258 |
$_POST['mc4wp-try-subscribe'] = 1;
|
259 |
-
unset($_POST['mc4wp-do-subscribe']);
|
260 |
|
261 |
return $this->subscribe_from_whatever();
|
262 |
}
|
@@ -265,7 +312,9 @@ class MC4WP_Lite_Checkbox
|
|
265 |
/* Start whatever functions */
|
266 |
public function subscribe_from_whatever()
|
267 |
{
|
268 |
-
if(!isset($_POST['mc4wp-try-subscribe']) ||
|
|
|
|
|
269 |
|
270 |
// start running..
|
271 |
$email = null;
|
@@ -273,34 +322,34 @@ class MC4WP_Lite_Checkbox
|
|
273 |
'GROUPINGS' => array()
|
274 |
);
|
275 |
|
276 |
-
foreach($_POST as $key => $value) {
|
277 |
|
278 |
-
if($key == 'mc4wp-try-subscribe') {
|
279 |
continue;
|
280 |
-
} elseif(strtolower(substr($key, 0, 6)) == 'mc4wp-') {
|
281 |
// find extra fields which should be sent to MailChimp
|
282 |
-
$key = strtoupper(substr($key, 6));
|
283 |
|
284 |
-
if($key == 'EMAIL') {
|
285 |
$email = $value;
|
286 |
-
} elseif($key == 'GROUPINGS' && is_array($value)) {
|
287 |
|
288 |
$groupings = $value;
|
289 |
|
290 |
-
foreach($groupings as $grouping_id_or_name => $groups) {
|
291 |
|
292 |
$grouping = array();
|
293 |
|
294 |
// group ID or group name given?
|
295 |
-
if(is_numeric($grouping_id_or_name)) {
|
296 |
$grouping['id'] = $grouping_id_or_name;
|
297 |
} else {
|
298 |
$grouping['name'] = $grouping_id_or_name;
|
299 |
}
|
300 |
|
301 |
// comma separated list should become an array
|
302 |
-
if(!is_array($groups)) {
|
303 |
-
$grouping['groups'] = explode(',', $groups);
|
304 |
} else {
|
305 |
$grouping['groups'] = $groups;
|
306 |
}
|
@@ -310,27 +359,33 @@ class MC4WP_Lite_Checkbox
|
|
310 |
|
311 |
} // end foreach
|
312 |
|
313 |
-
} elseif(!isset($merge_vars[$key])) {
|
|
|
314 |
// if value is array, convert to comma-delimited string
|
315 |
-
if(is_array($value)) {
|
|
|
|
|
316 |
|
317 |
$merge_vars[$key] = $value;
|
318 |
}
|
319 |
|
320 |
-
} elseif(
|
321 |
// find first email field
|
322 |
$email = $value;
|
323 |
-
|
324 |
} else {
|
325 |
-
$simple_key = str_replace(array('-', '_'), '', strtolower($key));
|
326 |
|
327 |
-
if(!isset($merge_vars['NAME']) && in_array($simple_key, array('name', 'yourname', 'username', 'fullname'))) {
|
328 |
// find name field
|
329 |
$merge_vars['NAME'] = $value;
|
330 |
-
}
|
|
|
|
|
331 |
// find first name field
|
332 |
$merge_vars['FNAME'] = $value;
|
333 |
-
}
|
|
|
|
|
334 |
// find last name field
|
335 |
$merge_vars['LNAME'] = $value;
|
336 |
}
|
@@ -339,33 +394,41 @@ class MC4WP_Lite_Checkbox
|
|
339 |
|
340 |
|
341 |
// unset groupings if not used
|
342 |
-
if(empty($merge_vars['GROUPINGS'])) {
|
|
|
|
|
343 |
|
344 |
// if email has not been found by the smart field guessing, return false.. sorry
|
345 |
-
if(
|
346 |
return false;
|
347 |
}
|
348 |
|
349 |
// subscribe
|
350 |
-
$result = $this->subscribe($email, $merge_vars);
|
351 |
return true;
|
352 |
}
|
353 |
/* End whatever functions */
|
354 |
|
355 |
-
|
356 |
-
|
357 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
|
359 |
-
if($anonymous_data) {
|
360 |
|
361 |
$email = $anonymous_data['bbp_anonymous_email'];
|
362 |
$merge_vars = array(
|
363 |
'NAME' => $anonymous_data['bbp_anonymous_name']
|
364 |
);
|
365 |
|
366 |
-
} elseif($user_id) {
|
367 |
|
368 |
-
$user_info = get_userdata($user_id);
|
369 |
$email = $user_info->user_email;
|
370 |
$merge_vars = array(
|
371 |
'NAME' => $user_info->first_name . ' ' . $user_info->last_name,
|
@@ -377,33 +440,40 @@ class MC4WP_Lite_Checkbox
|
|
377 |
return false;
|
378 |
}
|
379 |
|
380 |
-
return $this->subscribe($email, $merge_vars);
|
381 |
}
|
382 |
|
383 |
-
public function subscribe_from_bbpress_new_topic($topic_id, $forum_id, $anonymous_data, $topic_author)
|
384 |
-
|
385 |
-
return $this->subscribe_from_bbpress($anonymous_data, $topic_author);
|
386 |
}
|
387 |
|
388 |
-
public function subscribe_from_bbpress_new_reply($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author)
|
389 |
{
|
390 |
-
return $this->subscribe_from_bbpress($anonymous_data, $reply_author);
|
391 |
}
|
392 |
|
393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
394 |
{
|
395 |
$api = mc4wp_get_api();
|
396 |
$opts = mc4wp_get_options('checkbox');
|
397 |
|
398 |
$lists = $opts['lists'];
|
399 |
|
400 |
-
if(
|
401 |
-
|
|
|
402 |
wp_die('
|
403 |
<h3>MailChimp for WP - Error</h3>
|
404 |
<p>Please select a list to subscribe to in the <a href="'. admin_url('admin.php?page=mc4wp-lite-checkbox-settings') .'">checkbox settings</a>.</p>
|
405 |
<p style="font-style:italic; font-size:12px;">This message is only visible to administrators for debugging purposes.</p>
|
406 |
-
', "Error - MailChimp for WP", array('back_link' => true));
|
407 |
}
|
408 |
|
409 |
return 'no_lists_selected';
|
@@ -411,7 +481,7 @@ class MC4WP_Lite_Checkbox
|
|
411 |
|
412 |
|
413 |
// guess FNAME and LNAME
|
414 |
-
if ( isset( $merge_vars['NAME'] ) && !isset( $merge_vars['FNAME'] ) && !isset( $merge_vars['LNAME'] ) ) {
|
415 |
|
416 |
$strpos = strpos( $merge_vars['NAME'], ' ' );
|
417 |
|
@@ -423,21 +493,21 @@ class MC4WP_Lite_Checkbox
|
|
423 |
}
|
424 |
}
|
425 |
|
426 |
-
$merge_vars = apply_filters('mc4wp_merge_vars', $merge_vars, '');
|
427 |
-
$email_type = apply_filters('mc4wp_email_type', 'html');
|
428 |
-
$lists = apply_filters('mc4wp_lists', $lists, $merge_vars);
|
429 |
|
430 |
-
foreach($lists as $list) {
|
431 |
-
$result = $api->subscribe($list, $email, $merge_vars, $email_type, $opts['double_optin']);
|
432 |
|
433 |
-
if($result === true) {
|
434 |
-
$from_url = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : '';
|
435 |
do_action( 'mc4wp_subscribe_checkbox', $email, $list, $merge_vars );
|
436 |
}
|
437 |
}
|
438 |
|
439 |
// check if result succeeded, show debug message to administrators
|
440 |
-
if($result !== true && $api->has_error() && current_user_can('manage_options') && !defined("DOING_AJAX"))
|
441 |
{
|
442 |
wp_die("
|
443 |
<h3>MailChimp for WP - Error</h3>
|
@@ -447,9 +517,9 @@ class MC4WP_Lite_Checkbox
|
|
447 |
<strong>Email</strong>
|
448 |
<pre>{$email}</pre>
|
449 |
<strong>Merge variables</strong>
|
450 |
-
<pre>" . print_r($merge_vars, true) . "</pre>
|
451 |
<p style=\"font-style:italic; font-size:12px; \">This message is only visible to administrators for debugging purposes.</p>
|
452 |
-
", "Error - MailChimp for WP", array('back_link' => true));
|
453 |
}
|
454 |
|
455 |
return $result;
|
79 |
|
80 |
public function initialize()
|
81 |
{
|
82 |
+
if( function_exists( "wpcf7_add_shortcode" ) ) {
|
83 |
wpcf7_add_shortcode( 'mc4wp_checkbox', array( $this, 'get_checkbox') );
|
84 |
add_action( 'wpcf7_posted_data', array( $this, 'alter_cf7_data') );
|
85 |
add_action( 'wpcf7_mail_sent', array( $this, 'subscribe_from_cf7' ) );
|
86 |
}
|
87 |
|
88 |
// catch-all (for manual integrations with third-party forms)
|
89 |
+
if( isset( $_POST['mc4wp-try-subscribe'] ) && $_POST['mc4wp-try-subscribe'] ) {
|
90 |
$this->subscribe_from_whatever();
|
91 |
}
|
92 |
}
|
93 |
|
94 |
+
public function get_checkbox( $args = array() )
|
95 |
{
|
96 |
$opts = mc4wp_get_options('checkbox');
|
97 |
|
98 |
+
$label = isset( $args['labels'][0] ) ? $args['labels'][0] : $opts['label'];
|
99 |
$checked = $opts['precheck'] ? "checked" : '';
|
100 |
|
101 |
// CF7 checkbox?
|
124 |
return $content;
|
125 |
}
|
126 |
|
127 |
+
/**
|
128 |
+
* Outputs a sign-up checkbox
|
129 |
+
*/
|
130 |
public function output_checkbox()
|
131 |
{
|
132 |
+
if( $this->showed_checkbox ) {
|
133 |
+
return;
|
134 |
+
}
|
135 |
+
|
136 |
+
// echo the sign-up checkbox
|
137 |
echo $this->get_checkbox();
|
138 |
+
|
139 |
$this->showed_checkbox = true;
|
140 |
}
|
141 |
|
142 |
+
/**
|
143 |
+
* Adds the checkbox stylesheet to the array
|
144 |
+
* @param array $stylesheets
|
145 |
+
* @return array
|
146 |
+
*/
|
147 |
+
public function add_stylesheet( $stylesheets ) {
|
148 |
$stylesheets['checkbox'] = 1;
|
149 |
return $stylesheets;
|
150 |
}
|
151 |
|
152 |
|
153 |
/* Start comment form functions */
|
154 |
+
public function subscribe_from_comment( $cid, $comment_approved = '' ) {
|
155 |
+
if( ! isset( $_POST['mc4wp-do-subscribe'] ) || $_POST['mc4wp-do-subscribe'] != 1 ) {
|
156 |
+
return false;
|
157 |
+
}
|
158 |
|
159 |
+
if( $comment_approved === 'spam' ) {
|
160 |
+
return false;
|
161 |
+
}
|
162 |
+
|
163 |
+
$comment = get_comment( $cid );
|
164 |
|
165 |
$email = $comment->comment_author_email;
|
166 |
$merge_vars = array(
|
167 |
'OPTINIP' => $comment->comment_author_IP,
|
168 |
'NAME' => $comment->comment_author
|
169 |
+
);
|
170 |
|
171 |
+
return $this->subscribe( $email, $merge_vars );
|
172 |
}
|
173 |
|
174 |
+
public function add_comment_meta( $comment_id ) {
|
|
|
175 |
add_comment_meta($comment_id, 'mc4wp_subscribe', $_POST['mc4wp-do-subscribe'], true );
|
176 |
}
|
177 |
/* End comment form functions */
|
178 |
|
179 |
/* Start registration form functions */
|
180 |
+
public function subscribe_from_registration( $user_id ) {
|
181 |
+
|
182 |
+
if( ! isset( $_POST['mc4wp-do-subscribe'] ) || $_POST['mc4wp-do-subscribe'] != 1 ) {
|
183 |
+
return false;
|
184 |
+
}
|
185 |
|
186 |
// gather emailadress from user who WordPress registered
|
187 |
+
$user = get_userdata( $user_id );
|
188 |
+
if( $user == false ) {
|
189 |
+
return false;
|
190 |
+
}
|
191 |
|
192 |
$email = $user->user_email;
|
193 |
$merge_vars = array(
|
194 |
'NAME' => $user->user_login
|
195 |
);
|
196 |
|
197 |
+
if( isset( $user->user_firstname ) && ! empty( $user->user_firstname ) ) {
|
198 |
$merge_vars['FNAME'] = $user->user_firstname;
|
199 |
}
|
200 |
|
201 |
+
if( isset( $user->user_lastname ) && ! empty( $user->user_lastname ) ) {
|
202 |
$merge_vars['LNAME'] = $user->user_lastname;
|
203 |
}
|
204 |
|
205 |
+
$result = $this->subscribe( $email, $merge_vars );
|
206 |
}
|
207 |
/* End registration form functions */
|
208 |
|
209 |
/* Start BuddyPress functions */
|
210 |
public function subscribe_from_buddypress()
|
211 |
{
|
212 |
+
if( ! isset( $_POST['mc4wp-do-subscribe'] ) || $_POST['mc4wp-do-subscribe'] != 1 ) {
|
213 |
+
return false;
|
214 |
+
}
|
215 |
|
216 |
// gather emailadress and name from user who BuddyPress registered
|
217 |
$email = $_POST['signup_email'];
|
219 |
'NAME' => $_POST['signup_username']
|
220 |
);
|
221 |
|
222 |
+
return $this->subscribe( $email, $merge_vars );
|
223 |
}
|
224 |
/* End BuddyPress functions */
|
225 |
|
226 |
/* Start Multisite functions */
|
227 |
public function add_multisite_hidden_checkbox()
|
228 |
{
|
229 |
+
?><input type="hidden" name="mc4wp-do-subscribe" value="<?php echo ( isset( $_POST['mc4wp-do-subscribe'] ) ) ? 1 : 0; ?>" /><?php
|
230 |
}
|
231 |
|
232 |
+
public function on_multisite_blog_signup( $blog_id, $user_id, $a, $b ,$meta = null )
|
233 |
{
|
234 |
+
if( ! isset($meta['mc4wp-do-subscribe'] ) || $meta['mc4wp-do-subscribe'] != 1) {
|
235 |
+
return false;
|
236 |
+
}
|
237 |
+
|
238 |
return $this->subscribe_from_multisite($user_id);
|
239 |
}
|
240 |
|
241 |
public function on_multisite_user_signup($user_id, $password = NULL, $meta = NULL)
|
242 |
{
|
243 |
+
if( ! isset( $meta['mc4wp-do-subscribe'] ) || $meta['mc4wp-do-subscribe'] != 1 ) {
|
244 |
+
return false;
|
245 |
+
}
|
246 |
+
|
247 |
return $this->subscribe_from_multisite($user_id);
|
248 |
}
|
249 |
|
250 |
+
/**
|
251 |
+
* Adds the checked state of the sign-up checkbox to the $meta array of Multisite sign-ups
|
252 |
+
*
|
253 |
+
* @param array $meta
|
254 |
+
* @return array
|
255 |
+
*/
|
256 |
+
public function add_multisite_usermeta( $meta = array() )
|
257 |
{
|
258 |
+
$meta['mc4wp-do-subscribe'] = ( isset( $_POST['mc4wp-do-subscribe'] ) ) ? 1 : 0;
|
259 |
return $meta;
|
260 |
}
|
261 |
|
262 |
+
/**
|
263 |
+
* Subscribes from Multisite sign-ups
|
264 |
+
* @param int $user_id
|
265 |
+
*/
|
266 |
+
public function subscribe_from_multisite( $user_id )
|
267 |
{
|
268 |
+
$user = get_userdata( $user_id );
|
269 |
|
270 |
+
if( ! is_object( $user ) ) {
|
271 |
+
return false;
|
272 |
+
}
|
273 |
|
274 |
$email = $user->user_email;
|
275 |
$merge_vars = array(
|
276 |
'NAME' => $user->first_name . ' ' . $user->last_name
|
277 |
);
|
278 |
+
$result = $this->subscribe( $email, $merge_vars );
|
279 |
}
|
280 |
/* End Multisite functions */
|
281 |
|
282 |
/* Start Contact Form 7 functions */
|
283 |
|
284 |
+
/**
|
285 |
+
* Adds the checkbox state to CF7 email data
|
286 |
+
* @param array $data
|
287 |
+
* @return array
|
288 |
+
*/
|
289 |
+
public function alter_cf7_data( $data = array() ) {
|
290 |
$data['mc4wp_checkbox'] = ( isset( $_POST['mc4wp-do-subscribe'] ) && $_POST['mc4wp-do-subscribe'] == 1 ) ? __("Yes") : __("No");
|
291 |
return $data;
|
292 |
}
|
293 |
|
294 |
+
/**
|
295 |
+
* Subscribe from Contact Form 7 submissions
|
296 |
+
* @param array $args (optional)
|
297 |
+
*/
|
298 |
+
public function subscribe_from_cf7( $args = null )
|
299 |
{
|
300 |
// check if CF7 "mc4wp" checkbox was checked
|
301 |
+
if( ! isset( $_POST['mc4wp-do-subscribe'] ) || ! $_POST['mc4wp-do-subscribe'] ) {
|
302 |
return false;
|
303 |
}
|
304 |
|
305 |
$_POST['mc4wp-try-subscribe'] = 1;
|
306 |
+
unset( $_POST['mc4wp-do-subscribe'] );
|
307 |
|
308 |
return $this->subscribe_from_whatever();
|
309 |
}
|
312 |
/* Start whatever functions */
|
313 |
public function subscribe_from_whatever()
|
314 |
{
|
315 |
+
if(! isset( $_POST['mc4wp-try-subscribe'] ) || ! $_POST['mc4wp-try-subscribe'] ) {
|
316 |
+
return false;
|
317 |
+
}
|
318 |
|
319 |
// start running..
|
320 |
$email = null;
|
322 |
'GROUPINGS' => array()
|
323 |
);
|
324 |
|
325 |
+
foreach( $_POST as $key => $value ) {
|
326 |
|
327 |
+
if( $key == 'mc4wp-try-subscribe' ) {
|
328 |
continue;
|
329 |
+
} elseif( strtolower( substr( $key, 0, 6 ) ) == 'mc4wp-' ) {
|
330 |
// find extra fields which should be sent to MailChimp
|
331 |
+
$key = strtoupper( substr( $key, 6 ) );
|
332 |
|
333 |
+
if( $key == 'EMAIL' ) {
|
334 |
$email = $value;
|
335 |
+
} elseif( $key == 'GROUPINGS' && is_array( $value ) ) {
|
336 |
|
337 |
$groupings = $value;
|
338 |
|
339 |
+
foreach( $groupings as $grouping_id_or_name => $groups ) {
|
340 |
|
341 |
$grouping = array();
|
342 |
|
343 |
// group ID or group name given?
|
344 |
+
if( is_numeric( $grouping_id_or_name ) ) {
|
345 |
$grouping['id'] = $grouping_id_or_name;
|
346 |
} else {
|
347 |
$grouping['name'] = $grouping_id_or_name;
|
348 |
}
|
349 |
|
350 |
// comma separated list should become an array
|
351 |
+
if( ! is_array( $groups ) ) {
|
352 |
+
$grouping['groups'] = explode( ',', $groups );
|
353 |
} else {
|
354 |
$grouping['groups'] = $groups;
|
355 |
}
|
359 |
|
360 |
} // end foreach
|
361 |
|
362 |
+
} elseif( ! isset( $merge_vars[$key] ) ) {
|
363 |
+
|
364 |
// if value is array, convert to comma-delimited string
|
365 |
+
if( is_array( $value ) ) {
|
366 |
+
$value = implode( ',', $value );
|
367 |
+
}
|
368 |
|
369 |
$merge_vars[$key] = $value;
|
370 |
}
|
371 |
|
372 |
+
} elseif( ! $email && is_email( $value ) ) {
|
373 |
// find first email field
|
374 |
$email = $value;
|
|
|
375 |
} else {
|
376 |
+
$simple_key = str_replace( array( '-', '_' ), '', strtolower( $key ) );
|
377 |
|
378 |
+
if( ! isset( $merge_vars['NAME'] ) && in_array( $simple_key, array( 'name', 'yourname', 'username', 'fullname' ) ) ) {
|
379 |
// find name field
|
380 |
$merge_vars['NAME'] = $value;
|
381 |
+
}
|
382 |
+
|
383 |
+
if( ! isset( $merge_vars['FNAME'] ) && in_array( $simple_key, array( 'firstname', 'fname', "givenname", "forename" ) ) ) {
|
384 |
// find first name field
|
385 |
$merge_vars['FNAME'] = $value;
|
386 |
+
}
|
387 |
+
|
388 |
+
if( ! isset($merge_vars['LNAME']) && in_array( $simple_key, array( 'lastname', 'lname', 'surname', 'familyname' ) ) ) {
|
389 |
// find last name field
|
390 |
$merge_vars['LNAME'] = $value;
|
391 |
}
|
394 |
|
395 |
|
396 |
// unset groupings if not used
|
397 |
+
if( empty( $merge_vars['GROUPINGS'] ) ) {
|
398 |
+
unset( $merge_vars['GROUPINGS'] );
|
399 |
+
}
|
400 |
|
401 |
// if email has not been found by the smart field guessing, return false.. sorry
|
402 |
+
if( ! $email ) {
|
403 |
return false;
|
404 |
}
|
405 |
|
406 |
// subscribe
|
407 |
+
$result = $this->subscribe( $email, $merge_vars );
|
408 |
return true;
|
409 |
}
|
410 |
/* End whatever functions */
|
411 |
|
412 |
+
/**
|
413 |
+
* @param array $anonymous_data
|
414 |
+
* @param int $user_id
|
415 |
+
* @return boolean
|
416 |
+
*/
|
417 |
+
public function subscribe_from_bbpress( $anonymous_data, $user_id ) {
|
418 |
+
if( ! isset($_POST['mc4wp-do-subscribe'] ) || $_POST['mc4wp-do-subscribe'] != 1 ) {
|
419 |
+
return;
|
420 |
+
}
|
421 |
|
422 |
+
if( $anonymous_data ) {
|
423 |
|
424 |
$email = $anonymous_data['bbp_anonymous_email'];
|
425 |
$merge_vars = array(
|
426 |
'NAME' => $anonymous_data['bbp_anonymous_name']
|
427 |
);
|
428 |
|
429 |
+
} elseif( $user_id ) {
|
430 |
|
431 |
+
$user_info = get_userdata( $user_id );
|
432 |
$email = $user_info->user_email;
|
433 |
$merge_vars = array(
|
434 |
'NAME' => $user_info->first_name . ' ' . $user_info->last_name,
|
440 |
return false;
|
441 |
}
|
442 |
|
443 |
+
return $this->subscribe( $email, $merge_vars );
|
444 |
}
|
445 |
|
446 |
+
public function subscribe_from_bbpress_new_topic( $topic_id, $forum_id, $anonymous_data, $topic_author ) {
|
447 |
+
return $this->subscribe_from_bbpress( $anonymous_data, $topic_author );
|
|
|
448 |
}
|
449 |
|
450 |
+
public function subscribe_from_bbpress_new_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author )
|
451 |
{
|
452 |
+
return $this->subscribe_from_bbpress( $anonymous_data, $reply_author );
|
453 |
}
|
454 |
|
455 |
+
/**
|
456 |
+
* Sets up the required data and calls the API Subscribe method
|
457 |
+
*
|
458 |
+
* @param string $email
|
459 |
+
* @param array $merge_vars
|
460 |
+
* @return boolean
|
461 |
+
*/
|
462 |
+
public function subscribe( $email, array $merge_vars = array() )
|
463 |
{
|
464 |
$api = mc4wp_get_api();
|
465 |
$opts = mc4wp_get_options('checkbox');
|
466 |
|
467 |
$lists = $opts['lists'];
|
468 |
|
469 |
+
if( ! $lists || empty( $lists ) ) {
|
470 |
+
|
471 |
+
if( ( ! defined("DOING_AJAX") || ! DOING_AJAX ) && current_user_can( 'manage_options' ) ) {
|
472 |
wp_die('
|
473 |
<h3>MailChimp for WP - Error</h3>
|
474 |
<p>Please select a list to subscribe to in the <a href="'. admin_url('admin.php?page=mc4wp-lite-checkbox-settings') .'">checkbox settings</a>.</p>
|
475 |
<p style="font-style:italic; font-size:12px;">This message is only visible to administrators for debugging purposes.</p>
|
476 |
+
', "Error - MailChimp for WP", array( 'back_link' => true ) );
|
477 |
}
|
478 |
|
479 |
return 'no_lists_selected';
|
481 |
|
482 |
|
483 |
// guess FNAME and LNAME
|
484 |
+
if ( isset( $merge_vars['NAME'] ) && ! isset( $merge_vars['FNAME'] ) && ! isset( $merge_vars['LNAME'] ) ) {
|
485 |
|
486 |
$strpos = strpos( $merge_vars['NAME'], ' ' );
|
487 |
|
493 |
}
|
494 |
}
|
495 |
|
496 |
+
$merge_vars = apply_filters( 'mc4wp_merge_vars', $merge_vars, '' );
|
497 |
+
$email_type = apply_filters( 'mc4wp_email_type', 'html' );
|
498 |
+
$lists = apply_filters( 'mc4wp_lists', $lists, $merge_vars );
|
499 |
|
500 |
+
foreach( $lists as $list ) {
|
501 |
+
$result = $api->subscribe( $list, $email, $merge_vars, $email_type, $opts['double_optin'] );
|
502 |
|
503 |
+
if( $result === true ) {
|
504 |
+
$from_url = ( isset( $_SERVER['HTTP_REFERER'] ) ) ? $_SERVER['HTTP_REFERER'] : '';
|
505 |
do_action( 'mc4wp_subscribe_checkbox', $email, $list, $merge_vars );
|
506 |
}
|
507 |
}
|
508 |
|
509 |
// check if result succeeded, show debug message to administrators
|
510 |
+
if( $result !== true && $api->has_error() && current_user_can( 'manage_options' ) && ! defined( "DOING_AJAX" ) )
|
511 |
{
|
512 |
wp_die("
|
513 |
<h3>MailChimp for WP - Error</h3>
|
517 |
<strong>Email</strong>
|
518 |
<pre>{$email}</pre>
|
519 |
<strong>Merge variables</strong>
|
520 |
+
<pre>" . print_r( $merge_vars, true ) . "</pre>
|
521 |
<p style=\"font-style:italic; font-size:12px; \">This message is only visible to administrators for debugging purposes.</p>
|
522 |
+
", "Error - MailChimp for WP", array( 'back_link' => true ) );
|
523 |
}
|
524 |
|
525 |
return $result;
|
includes/class-form.php
CHANGED
@@ -77,19 +77,23 @@ class MC4WP_Lite_Form {
|
|
77 |
public function output_form( $atts, $content = null ) {
|
78 |
$opts = mc4wp_get_options('form');
|
79 |
|
80 |
-
if ( !function_exists( 'mc4wp_replace_variables' ) ) {
|
81 |
include_once MC4WP_LITE_PLUGIN_DIR . 'includes/template-functions.php';
|
82 |
}
|
83 |
|
84 |
// add some useful css classes
|
85 |
$css_classes = 'form mc4wp-form ';
|
86 |
-
if ( $this->error ) $css_classes .= 'mc4wp-form-error ';
|
87 |
-
if ( $this->success ) $css_classes .= 'mc4wp-form-success ';
|
88 |
|
89 |
-
|
90 |
-
|
|
|
91 |
|
|
|
|
|
|
|
92 |
|
|
|
|
|
93 |
|
94 |
$form_action = apply_filters( 'mc4wp_form_action', mc4wp_get_current_url() );
|
95 |
|
@@ -105,16 +109,16 @@ class MC4WP_Lite_Form {
|
|
105 |
$form_markup = mc4wp_replace_variables( $form_markup, array_values( $opts['lists'] ) );
|
106 |
|
107 |
// allow plugins to add form fields
|
108 |
-
do_action('mc4wp_before_form_fields', 0);
|
109 |
|
110 |
// allow plugins to alter form content
|
111 |
-
$content .= apply_filters('mc4wp_form_content', $form_markup);
|
112 |
|
113 |
// allow plugins to add form fields
|
114 |
-
do_action('mc4wp_after_form_fields', 0);
|
115 |
|
116 |
// hidden fields
|
117 |
-
$content .= '<textarea name="_mc4wp_required_but_not_really" style="display: none;"></textarea>';
|
118 |
$content .= '<input type="hidden" name="_mc4wp_form_submit" value="1" />';
|
119 |
$content .= '<input type="hidden" name="_mc4wp_form_instance" value="'. $this->form_instance_number .'" />';
|
120 |
$content .= '<input type="hidden" name="_mc4wp_form_nonce" value="'. wp_create_nonce( '_mc4wp_form_nonce' ) .'" />';
|
@@ -129,11 +133,11 @@ class MC4WP_Lite_Form {
|
|
129 |
$api = mc4wp_get_api();
|
130 |
$e = $this->error;
|
131 |
|
132 |
-
$error_type = ($e == 'already_subscribed') ? 'notice' : 'error';
|
133 |
$error_message = isset($opts['text_' . $e]) ? $opts['text_' . $e] : $opts['text_error'];
|
134 |
|
135 |
// allow developers to customize error message
|
136 |
-
$error_message = apply_filters('mc4wp_form_error_message', $error_message);
|
137 |
|
138 |
$content .= '<div class="mc4wp-alert mc4wp-'. $error_type .'">'. __($error_message, 'mailchimp-for-wp') . '</div>';
|
139 |
|
@@ -158,8 +162,8 @@ class MC4WP_Lite_Form {
|
|
158 |
|
159 |
// make sure scripts are enqueued later
|
160 |
global $is_IE;
|
161 |
-
if(isset($is_IE) && $is_IE) {
|
162 |
-
wp_enqueue_script('mc4wp-placeholders');
|
163 |
}
|
164 |
|
165 |
return $content;
|
77 |
public function output_form( $atts, $content = null ) {
|
78 |
$opts = mc4wp_get_options('form');
|
79 |
|
80 |
+
if ( ! function_exists( 'mc4wp_replace_variables' ) ) {
|
81 |
include_once MC4WP_LITE_PLUGIN_DIR . 'includes/template-functions.php';
|
82 |
}
|
83 |
|
84 |
// add some useful css classes
|
85 |
$css_classes = 'form mc4wp-form ';
|
|
|
|
|
86 |
|
87 |
+
if ( $this->error ) {
|
88 |
+
$css_classes .= 'mc4wp-form-error ';
|
89 |
+
}
|
90 |
|
91 |
+
if ( $this->success ) {
|
92 |
+
$css_classes .= 'mc4wp-form-success ';
|
93 |
+
}
|
94 |
|
95 |
+
// allow developers to add css classes
|
96 |
+
$css_classes = apply_filters( 'mc4wp_form_css_classes', $css_classes );
|
97 |
|
98 |
$form_action = apply_filters( 'mc4wp_form_action', mc4wp_get_current_url() );
|
99 |
|
109 |
$form_markup = mc4wp_replace_variables( $form_markup, array_values( $opts['lists'] ) );
|
110 |
|
111 |
// allow plugins to add form fields
|
112 |
+
do_action( 'mc4wp_before_form_fields', 0 );
|
113 |
|
114 |
// allow plugins to alter form content
|
115 |
+
$content .= apply_filters( 'mc4wp_form_content', $form_markup );
|
116 |
|
117 |
// allow plugins to add form fields
|
118 |
+
do_action( 'mc4wp_after_form_fields', 0 );
|
119 |
|
120 |
// hidden fields
|
121 |
+
$content .= '<textarea name="_mc4wp_required_but_not_really" style="display: none !important;"></textarea>';
|
122 |
$content .= '<input type="hidden" name="_mc4wp_form_submit" value="1" />';
|
123 |
$content .= '<input type="hidden" name="_mc4wp_form_instance" value="'. $this->form_instance_number .'" />';
|
124 |
$content .= '<input type="hidden" name="_mc4wp_form_nonce" value="'. wp_create_nonce( '_mc4wp_form_nonce' ) .'" />';
|
133 |
$api = mc4wp_get_api();
|
134 |
$e = $this->error;
|
135 |
|
136 |
+
$error_type = ( $e == 'already_subscribed' ) ? 'notice' : 'error';
|
137 |
$error_message = isset($opts['text_' . $e]) ? $opts['text_' . $e] : $opts['text_error'];
|
138 |
|
139 |
// allow developers to customize error message
|
140 |
+
$error_message = apply_filters('mc4wp_form_error_message', $error_message, $e );
|
141 |
|
142 |
$content .= '<div class="mc4wp-alert mc4wp-'. $error_type .'">'. __($error_message, 'mailchimp-for-wp') . '</div>';
|
143 |
|
162 |
|
163 |
// make sure scripts are enqueued later
|
164 |
global $is_IE;
|
165 |
+
if( isset( $is_IE ) && $is_IE ) {
|
166 |
+
wp_enqueue_script( 'mc4wp-placeholders' );
|
167 |
}
|
168 |
|
169 |
return $content;
|
includes/functions.php
CHANGED
@@ -6,10 +6,17 @@ if( ! defined("MC4WP_LITE_VERSION") ) {
|
|
6 |
exit;
|
7 |
}
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
static $options;
|
11 |
|
12 |
-
if(
|
13 |
$defaults = array(
|
14 |
'general' => array(
|
15 |
'api_key' => ''
|
@@ -57,17 +64,21 @@ function mc4wp_get_options($key = null) {
|
|
57 |
}
|
58 |
}
|
59 |
|
60 |
-
if($key) {
|
61 |
return $options[$key];
|
62 |
}
|
63 |
|
64 |
return $options;
|
65 |
}
|
66 |
|
|
|
|
|
|
|
|
|
67 |
function mc4wp_get_api() {
|
68 |
static $api;
|
69 |
|
70 |
-
if(
|
71 |
require_once MC4WP_LITE_PLUGIN_DIR . 'includes/class-api.php';
|
72 |
$opts = mc4wp_get_options();
|
73 |
$api = new MC4WP_Lite_API( $opts['general']['api_key'] );
|
6 |
exit;
|
7 |
}
|
8 |
|
9 |
+
/**
|
10 |
+
* Gets the MailChimp for WP options from the database
|
11 |
+
* Uses default values to prevent undefined index notices.
|
12 |
+
*
|
13 |
+
* @param string $key
|
14 |
+
* @return array
|
15 |
+
*/
|
16 |
+
function mc4wp_get_options( $key = null ) {
|
17 |
static $options;
|
18 |
|
19 |
+
if( ! $options ) {
|
20 |
$defaults = array(
|
21 |
'general' => array(
|
22 |
'api_key' => ''
|
64 |
}
|
65 |
}
|
66 |
|
67 |
+
if( $key ) {
|
68 |
return $options[$key];
|
69 |
}
|
70 |
|
71 |
return $options;
|
72 |
}
|
73 |
|
74 |
+
/**
|
75 |
+
* Gets the MailChimp for WP API class and injects it with the given API key
|
76 |
+
* @return MC4WP_API
|
77 |
+
*/
|
78 |
function mc4wp_get_api() {
|
79 |
static $api;
|
80 |
|
81 |
+
if( ! $api ) {
|
82 |
require_once MC4WP_LITE_PLUGIN_DIR . 'includes/class-api.php';
|
83 |
$opts = mc4wp_get_options();
|
84 |
$api = new MC4WP_Lite_API( $opts['general']['api_key'] );
|
mailchimp-for-wp.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: MailChimp for WordPress Lite
|
4 |
Plugin URI: http://dannyvankooten.com/mailchimp-for-wordpress/
|
5 |
Description: Lite version of MailChimp for WordPress. Adds various sign-up methods to your website.
|
6 |
-
Version: 1.5.
|
7 |
Author: Danny van Kooten
|
8 |
Author URI: http://dannyvanKooten.com
|
9 |
License: GPL v3
|
@@ -25,21 +25,22 @@ You should have received a copy of the GNU General Public License
|
|
25 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
26 |
*/
|
27 |
|
28 |
-
if( !defined( 'ABSPATH' ) ) {
|
29 |
header( 'Status: 403 Forbidden' );
|
30 |
header( 'HTTP/1.1 403 Forbidden' );
|
31 |
exit;
|
32 |
}
|
33 |
|
34 |
-
if(!function_exists('is_plugin_active')) {
|
35 |
-
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
36 |
-
}
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
-
|
|
|
43 |
define("MC4WP_LITE_PLUGIN_DIR", plugin_dir_path(__FILE__));
|
44 |
define("MC4WP_LITE_PLUGIN_URL", plugins_url( '/' , __FILE__ ) );
|
45 |
|
@@ -54,5 +55,6 @@ if(!is_plugin_active('mailchimp-for-wp-pro/mailchimp-for-wp-pro.php')
|
|
54 |
MC4WP_Lite_Admin::init();
|
55 |
|
56 |
}
|
57 |
-
|
58 |
-
|
|
3 |
Plugin Name: MailChimp for WordPress Lite
|
4 |
Plugin URI: http://dannyvankooten.com/mailchimp-for-wordpress/
|
5 |
Description: Lite version of MailChimp for WordPress. Adds various sign-up methods to your website.
|
6 |
+
Version: 1.5.6
|
7 |
Author: Danny van Kooten
|
8 |
Author URI: http://dannyvanKooten.com
|
9 |
License: GPL v3
|
25 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
26 |
*/
|
27 |
|
28 |
+
if( ! defined( 'ABSPATH' ) ) {
|
29 |
header( 'Status: 403 Forbidden' );
|
30 |
header( 'HTTP/1.1 403 Forbidden' );
|
31 |
exit;
|
32 |
}
|
33 |
|
|
|
|
|
|
|
34 |
|
35 |
+
function mc4wp_load_plugin() {
|
36 |
+
|
37 |
+
// don't load plugin if user has the premium version installed and activated
|
38 |
+
if( defined( "MC4WP_VERSION" ) || ( is_admin() && isset( $_GET['action'] ) && $_GET['action'] === 'activate' && isset( $_GET['plugin'] ) && stristr( $_GET['plugin'], 'mailchimp-for-wp-pro' ) !== false ) ) {
|
39 |
+
return;
|
40 |
+
}
|
41 |
|
42 |
+
// bootstrap the lite plugin
|
43 |
+
define("MC4WP_LITE_VERSION", "1.5.6");
|
44 |
define("MC4WP_LITE_PLUGIN_DIR", plugin_dir_path(__FILE__));
|
45 |
define("MC4WP_LITE_PLUGIN_URL", plugins_url( '/' , __FILE__ ) );
|
46 |
|
55 |
MC4WP_Lite_Admin::init();
|
56 |
|
57 |
}
|
58 |
+
}
|
59 |
+
|
60 |
+
add_action( 'plugins_loaded', 'mc4wp_load_plugin', 20 );
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://dannyvankooten.com/donate/
|
|
4 |
Tags: mailchimp,form,shortcode,widget,checkbox,comment,newsletter,buddypress,multisite,bbpress,woocommerce,easy digital downloads,contact form,contact form 7
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 3.8.1
|
7 |
-
Stable tag: 1.5.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -198,6 +198,15 @@ Your theme folder can be found by browsing to `/wp-content/themes/your-theme-nam
|
|
198 |
|
199 |
== Changelog ==
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
= 1.5.5 - February 25, 2014 =
|
202 |
* Fixed: Field generator only generating text fields
|
203 |
* Fixed: Now using correct deactivation hook
|
@@ -205,7 +214,6 @@ Your theme folder can be found by browsing to `/wp-content/themes/your-theme-nam
|
|
205 |
|
206 |
= 1.5.4 - February 17, 2014 =
|
207 |
* Fixed: "Add to form" button not working
|
208 |
-
* Improved: Plugin now compatible with custom plugin folder names
|
209 |
|
210 |
= 1.5.3 - February 16, 2014 =
|
211 |
* Fixed: Undefined constant notice on admin pages
|
4 |
Tags: mailchimp,form,shortcode,widget,checkbox,comment,newsletter,buddypress,multisite,bbpress,woocommerce,easy digital downloads,contact form,contact form 7
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 3.8.1
|
7 |
+
Stable tag: 1.5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
198 |
|
199 |
== Changelog ==
|
200 |
|
201 |
+
= 1.5.6 - March 13, 2014 =
|
202 |
+
* Fixed: Honeypot textarea showing in some themes
|
203 |
+
* Improved: Plugin will automatically strip duplicate `<form>` tags from form mark-up
|
204 |
+
* Improved: Better code documentation
|
205 |
+
* Improved: Code is now more adhering to WP code standards
|
206 |
+
* Improved: Add custom error type to error message filter to allow developers to show custom error messages
|
207 |
+
* Improved: Plugin will now show detailed errors for failed API requests (up to HTTP level)
|
208 |
+
* Improved: Better way of loading plugin files
|
209 |
+
|
210 |
= 1.5.5 - February 25, 2014 =
|
211 |
* Fixed: Field generator only generating text fields
|
212 |
* Fixed: Now using correct deactivation hook
|
214 |
|
215 |
= 1.5.4 - February 17, 2014 =
|
216 |
* Fixed: "Add to form" button not working
|
|
|
217 |
|
218 |
= 1.5.3 - February 16, 2014 =
|
219 |
* Fixed: Undefined constant notice on admin pages
|
uninstall.php
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
//if uninstall not called from WordPress exit
|
4 |
-
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
5 |
-
header( 'Status: 403 Forbidden' );
|
6 |
-
header( 'HTTP/1.1 403 Forbidden' );
|
7 |
-
exit;
|
8 |
-
}
|
9 |
-
|
10 |
-
delete_option('mc4wp_lite');
|
11 |
-
delete_option('mc4wp_lite_checkbox');
|
12 |
-
delete_option('mc4wp_lite_form');
|
13 |
-
|
14 |
-
delete_transient('mc4wp_mailchimp_lists');
|
15 |
-
delete_transient('mc4wp_mailchimp_lists_fallback');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|