MailChimp for WordPress - Version 1.1.5

Version Description

  • Fixed: Form using checkbox settings for list and double opt-in instead of form settings.
Download this release

Release Info

Developer DvanKooten
Plugin Icon 128x128 MailChimp for WordPress
Version 1.1.5
Comparing to
See all releases

Version 1.1.5

css/admin.css ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #mc4wp_admin hr{ margin:20px 0; background-color:lightGray; border:0; height:1px; }
2
+ #mc4wp_admin h2{ padding-bottom: 0; }
3
+ #mc4wp_admin span.status{ padding:3px; color:white; font-size:12px; }
4
+ #mc4wp_admin span.status.connected{ background-color:green; }
5
+ #mc4wp_admin span.status.not_connected{ background-color:lightGrey; }
6
+ #mc4wp_admin td.desc{ font-style:italic; font-size:10px; }
7
+
8
+ #mc4wp_admin .alert{ border:1px solid black; padding:5px; width:auto; }
9
+ #mc4wp_admin .alert.warning{ background:#FCF8E3; color:#C09853; border:1px solid #FBEED5; }
10
+
11
+ #mc4wp-main-column{ float:left; width:65%; margin-right:0; }
12
+ #mc4wp-secondary-column{ float:right; width:32%; margin-left:2.5%; }
13
+ #mc4wp-secondary-column .mc4wp-box{ margin-bottom:20px; }
14
+
15
+ /* tabs */
16
+ #mc4wp-nav { clear:both; padding:0; margin:20px 0; border-bottom: 1px solid lightGray; }
17
+ #mc4wp-nav li { list-style: none; margin: 0; padding:0; display: inline-block; }
18
+ #mc4wp-nav li a { font-weight:bold; display:block; padding: 6px 12px; margin:0 10px -1px 0; border:1px solid lightGray; text-decoration: none; font-size:14px; }
19
+ #mc4wp-nav li a.active { background: white; border-bottom: 1px solid white; color:black; }
20
+ #mc4wp-tabs .mc4wp-tab{ display:none !important; }
21
+ #mc4wp-tabs .mc4wp-tab.active{ display:block !important; }
22
+ /* end tabs */
23
+
24
+ #mc4wp-upgrade-box { border:1px solid black; background:#efefef; padding:20px; -moz-box-shadow: 0 0 5px 5px #888; -webkit-box-shadow: 0 0 5px 5px#888; box-shadow: 0 0 5px 5px #888; }
25
+ #mc4wp-upgrade-box h3{ margin:0; }
26
+ #mc4wp-upgrade-box ul{ list-style:square; margin-left:25px; }
27
+ #mc4wp-upgrade-box li{ margin:0; }
28
+
29
+ #mc4wp-fw h4{ margin-top:0; }
30
+ #mc4wp-fw .mc4wp-fields { display:none; }
31
+ #mc4wp-fw-preview { font-size:11px; }
32
+
33
+ #mc4wp_admin table th{ text-align:left; }
34
+ #mc4wp_admin table.form-table tr td:first-child, #mc4wp_admin table.form-table tr th:first-child{ padding-left:0; }
35
+ #mc4wp_admin p.copyright-notice{ font-style:italic; }
36
+
37
+ #mc4wp_admin .mc4wp-wrapper{ clear:both; width:100%; display:block; }
38
+ #mc4wp_admin .mc4wp-col { float:left; margin:0 1%; padding:0; }
39
+ #mc4wp_admin .mc4wp-col-2-3{ width:64%; }
40
+ #mc4wp_admin .mc4wp-col-1-3{ width:34%; }
41
+ #mc4wp_admin .mc4wp-first{ margin-left:0; }
42
+ #mc4wp_admin .mc4wp-last{ margin-right:0; }
43
+ #mc4wp_admin .mc4wp-well{ background:#efefef; padding:10px; border:1px solid #666; }
44
+
45
+ #mc4wp_admin .upgrade-button{
46
+ border:1px solid #ffad41;-webkit-box-shadow: #999999 1px 1px 1px ;-moz-box-shadow: #999999 1px 1px 1px ; box-shadow: #999999 1px 1px 1px ; -webkit-border-radius: 3px; -moz-border-radius: 3px;border-radius: 3px;padding: 12px 16px; text-decoration:none; display:inline-block;text-shadow: 1px 1px 0 rgba(51,51,51,0.3);font-weight:bold; color: #000000;
47
+ background-color: #ffc579; background-image: -webkit-gradient(linear, left top, left bottom, from(#ffc579), to(#fb9d23));
48
+ background-image: -webkit-linear-gradient(top, #ffc579, #fb9d23);
49
+ background-image: -moz-linear-gradient(top, #ffc579, #fb9d23);
50
+ background-image: -ms-linear-gradient(top, #ffc579, #fb9d23);
51
+ background-image: -o-linear-gradient(top, #ffc579, #fb9d23);
52
+ background-image: linear-gradient(to bottom, #ffc579, #fb9d23);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#ffc579, endColorstr=#fb9d23);
53
+ }
54
+
55
+ #mc4wp_admin .upgrade-button:hover{
56
+ border:1px solid #ff9913;
57
+ background-color: #ffaf46; background-image: -webkit-gradient(linear, left top, left bottom, from(#ffaf46), to(#e78404));
58
+ background-image: -webkit-linear-gradient(top, #ffaf46, #e78404);
59
+ background-image: -moz-linear-gradient(top, #ffaf46, #e78404);
60
+ background-image: -ms-linear-gradient(top, #ffaf46, #e78404);
61
+ background-image: -o-linear-gradient(top, #ffaf46, #e78404);
62
+ background-image: linear-gradient(to bottom, #ffaf46, #e78404);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#ffaf46, endColorstr=#e78404);
63
+ }
64
+
65
+ table.mc4wp-help, table.mc4wp-help th, table.mc4wp-help td { border: 1px solid #ddd; border-collapse: collapse; font-size: 12px; }
66
+ table.mc4wp-help th, table.mc4wp-help td { vertical-align: text-top; text-align: left; padding: 5px 10px; }
67
+ table.mc4wp-help tr:hover { background-color: #ddd; }
css/checkbox.css ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ p#mc4wp-checkbox{ clear:both; display:block; }
2
+ p#mc4wp-checkbox input{ margin:0 5px 0 0; display:inline-block !important; width:13px; height:13px; }
3
+ p#mc4wp-checkbox label{ display:inline-block !important; }
4
+
5
+ #registerform p#mc4wp-checkbox{ margin-bottom:10px; }
css/form.css ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ form.mc4wp-form{ clear:both; margin:15px 0; }
2
+ form.mc4wp-form p{ clear:both; }
3
+ form.mc4wp-form label{ display:block; font-weight:bold; margin-bottom: 3px; }
4
+
5
+ form.mc4wp-form ul li label{ font-weight:normal; }
6
+
7
+ form.mc4wp-form input[type="text"],
8
+ form.mc4wp-form input[type="email"],
9
+ form.mc4wp-form input[type="tel"],
10
+ form.mc4wp-form input[type="url"] { display:block; width:100%;
11
+ box-sizing:border-box; box-sizing: border-box; -moz-box-sizing: border-box; }
12
+
13
+ form.mc4wp-form form input[type="checkbox"] { margin:0 10px 0 0; padding:0; height:13px; width:13px;
14
+ display:inline-block; -webkit-appearance: checkbox; }
15
+ form.mc4wp-form form input[type="radio"] { margin:0 10px 0 0; padding:0; height:13px; width:13px;
16
+ display:inline-block; -webkit-appearance: radio; }
17
+ form.mc4wp-form select, div.mc4wp-form input[type="date"] { min-width:35%; }
18
+ form.mc4wp-form input[type="submit"], div.mc4wp-form button[type="submit"]{ display:inline-block; }
19
+
20
+ form.mc4wp-form .mc4wp-alert{ margin-top:1em; margin-bottom:1em; padding: 10px 35px 10px 15px; color: #c09853; background-color: #fcf8e3; border: 1px solid #fbeed5; border-radius: 4px; display:block; position:relative;}
21
+ form.mc4wp-form .mc4wp-success { color: #468847; background-color: #dff0d8; border-color: #d6e9c6; }
22
+ form.mc4wp-form .mc4wp-notice { color: #3a87ad; background-color: #d9edf7; border-color: #bce8f1; }
23
+ form.mc4wp-form .mc4wp-error { color: #b94a48; background-color: #f2dede; border-color: #eed3d7;; }
img/menu-icon.png ADDED
Binary file
includes/MC4WP_Lite.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MC4WP_Lite
4
+ {
5
+ private $options = array();
6
+ private $mailchimp_api = null;
7
+ private static $instance, $checkbox = null, $form = null;
8
+
9
+ public static function instance()
10
+ {
11
+ return self::$instance;
12
+ }
13
+
14
+ public static function checkbox()
15
+ {
16
+ if(!self::$checkbox) {
17
+ require 'MC4WP_Lite_Checkbox.php';
18
+ self::$checkbox = new MC4WP_Lite_Checkbox();
19
+ }
20
+ return self::$checkbox;
21
+ }
22
+
23
+ public static function form()
24
+ {
25
+ if(!self::$form) {
26
+ require 'MC4WP_Lite_Form.php';
27
+ self::$form = new MC4WP_Lite_Form();
28
+ }
29
+ return self::$form;
30
+ }
31
+
32
+ public function __construct()
33
+ {
34
+ self::$instance = $this;
35
+
36
+ $opts = $this->get_options();
37
+
38
+ self::checkbox();
39
+ self::form();
40
+
41
+ if(defined('DOING_AJAX') && DOING_AJAX) {
42
+ // ajax only
43
+
44
+ } else {
45
+ // non-ajax only
46
+
47
+ if(is_admin()) {
48
+ // backend non-ajax only
49
+ require_once 'MC4WP_Lite_Admin.php';
50
+ new MC4WP_Lite_Admin();
51
+ } else {
52
+ // frontend non-ajax only
53
+ require 'functions.php';
54
+ }
55
+ }
56
+ }
57
+
58
+ public function get_options()
59
+ {
60
+ if(empty($this->options)) {
61
+ $defaults = array(
62
+ 'mailchimp_api_key' => '',
63
+ 'checkbox_label' => 'Sign me up for the newsletter!', 'checkbox_precheck' => 1, 'checkbox_css' => 0,
64
+ 'checkbox_show_at_comment_form' => 0, 'checkbox_show_at_registration_form' => 0, 'checkbox_show_at_ms_form' => 0, 'checkbox_show_at_bp_form' => 0, 'checkbox_show_at_other_forms' => 0,
65
+ 'checkbox_lists' => array(), 'checkbox_double_optin' => 1, 'checkbox_show_at_bbpress_forms' => 0,
66
+ 'form_css' => 1, 'form_markup' => "<p>\n\t<label for=\"mc4wp_email\">Email address: </label>\n\t<input type=\"email\" id=\"mc4wp_email\" name=\"EMAIL\" required placeholder=\"Your email address\" />\n</p>\n\n<p>\n\t<input type=\"submit\" value=\"Sign up\" />\n</p>",
67
+ 'form_text_success' => 'Thank you, your sign-up request was successful! Please check your e-mail inbox.', 'form_text_error' => 'Oops. Something went wrong. Please try again later.',
68
+ 'form_text_invalid_email' => 'Please provide a valid email address.', 'form_text_already_subscribed' => "Given email address is already subscribed, thank you!",
69
+ 'form_redirect' => '', 'form_lists' => array(), 'form_double_optin' => 1, 'form_hide_after_success' => 0
70
+ );
71
+
72
+ $options = get_option('mc4wp_lite');
73
+ if(!$options) {
74
+ // using old option key?
75
+ if(($options = get_option('mc4wp')) != false) {
76
+ add_option('mc4wp_lite', $options);
77
+ }
78
+ }
79
+
80
+ $this->options = $opts = array_merge($defaults, (array) $options);
81
+ }
82
+
83
+ return $this->options;
84
+ }
85
+
86
+ public function get_mailchimp_api()
87
+ {
88
+ if(!$this->mailchimp_api) {
89
+
90
+ // Only load MailChimp API if it has not been loaded yet
91
+ // other plugins may have already at this point.
92
+ if(!class_exists("MCAPI")) {
93
+ require_once 'MCAPI.php';
94
+ }
95
+
96
+ $this->mailchimp_api = new MCAPI($this->options['mailchimp_api_key']);
97
+ }
98
+
99
+ return $this->mailchimp_api;
100
+ }
101
+
102
+ }
includes/MC4WP_Lite_Admin.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MC4WP_Lite_Admin
4
+ {
5
+ private $options = array();
6
+
7
+ public function __construct()
8
+ {
9
+ $this->options = MC4WP_Lite::instance()->get_options();
10
+
11
+ add_action('admin_init', array($this, 'register_settings'));
12
+ add_action('admin_menu', array($this, 'build_menu'));
13
+ add_action( 'admin_enqueue_scripts', array($this, 'load_css_and_js') );
14
+
15
+ register_activation_hook( 'mailchimp-for-wp-pro/mailchimp-for-wp-pro.php', array($this, 'on_activation') );
16
+
17
+ add_filter("plugin_action_links_mailchimp-for-wp/mailchimp-for-wp.php", array($this, 'add_settings_link'));
18
+ }
19
+
20
+ public function on_activation()
21
+ {
22
+ delete_transient('mc4wp_mailchimp_lists');
23
+ delete_transient('mc4wp_mailchimp_lists_fallback');
24
+ }
25
+
26
+ public function add_settings_link($links)
27
+ {
28
+ $settings_link = '<a href="admin.php?page=mailchimp-for-wp">Settings</a>';
29
+ $upgrade_link = '<a href="http://dannyvankooten.com/wordpress-plugins/mailchimp-for-wordpress/">Upgrade to Pro</a>';
30
+ array_unshift($links, $upgrade_link, $settings_link);
31
+ return $links;
32
+ }
33
+
34
+ public function register_settings()
35
+ {
36
+ register_setting('mc4wp_options_group', 'mc4wp_lite', array($this, 'validate_options'));
37
+ }
38
+
39
+ public function validate_options($opts)
40
+ {
41
+ return $opts;
42
+ }
43
+
44
+ public function build_menu()
45
+ {
46
+ $page = add_menu_page('MailChimp for WP Lite', 'MailChimp for WP Lite', 'manage_options', 'mailchimp-for-wp', array($this, 'page_dashboard'), plugins_url('mailchimp-for-wp/img/menu-icon.png'));
47
+ }
48
+
49
+ public function load_css_and_js($hook)
50
+ {
51
+ if($hook != 'toplevel_page_mailchimp-for-wp') { return false; }
52
+
53
+ wp_register_script('mc4wp-admin-js', plugins_url('mailchimp-for-wp/js/admin.js'), array('jquery'), false, true);
54
+
55
+ // css
56
+ wp_enqueue_style( 'mc4wp-admin-css', plugins_url('mailchimp-for-wp/css/admin.css') );
57
+
58
+ // js
59
+ wp_enqueue_script( array('jquery', 'mc4wp-admin-js') );
60
+ $translation_array = array( 'admin_page' => get_admin_url(null, 'admin.php?page=mailchimp-for-wp') );
61
+ wp_localize_script( 'mc4wp-admin-js', 'mc4wp_urls', $translation_array );
62
+ }
63
+
64
+ public function get_checkbox_compatible_plugins()
65
+ {
66
+ $checkbox_plugins = array(
67
+ 'comment_form' => "Comment form",
68
+ "registration_form" => "Registration form"
69
+ );
70
+
71
+ if(is_multisite()) $checkbox_plugins['ms_form'] = "MultiSite forms";
72
+ if(class_exists("BuddyPress")) $checkbox_plugins['bp_form'] = "BuddyPress registration";
73
+ if(class_exists('bbPress')) $checkbox_plugins['bbpress_forms'] = "bbPress";
74
+
75
+ return $checkbox_plugins;
76
+ }
77
+
78
+ public function page_dashboard()
79
+ {
80
+ $opts = $this->options;
81
+ $api = $this->get_mailchimp_api();
82
+
83
+ if(empty($opts['mailchimp_api_key'])) {
84
+ $connected = false;
85
+ } else {
86
+ $connected = ($api->ping() === "Everything's Chimpy!");
87
+ }
88
+
89
+ if($connected) {
90
+ $lists = $this->get_mailchimp_lists();
91
+ }
92
+
93
+ // tab shit
94
+ $tabs = array('api-settings', 'checkbox-settings', 'form-settings');
95
+ $tab = (isset($_GET['tab'])) ? $_GET['tab'] : 'api-settings';
96
+
97
+ require 'views/dashboard.php';
98
+ }
99
+
100
+ private function get_mailchimp_api()
101
+ {
102
+ return MC4WP_Lite::instance()->get_mailchimp_api();
103
+ }
104
+
105
+ public function get_mailchimp_lists($refresh_cache = false)
106
+ {
107
+ $lists = get_transient( 'mc4wp_mailchimp_lists' );
108
+
109
+ $refresh_cache = (isset($_REQUEST['renew-cached-data'])) ? true : $refresh_cache;
110
+
111
+ if($refresh_cache || !$lists) {
112
+
113
+ // make api request for lists
114
+ $api = $this->get_mailchimp_api();
115
+ $lists_data = $api->lists();
116
+ $lists = array();
117
+
118
+ if($lists_data && isset($lists_data['data'])) {
119
+
120
+ foreach($lists_data['data'] as $l) {
121
+ $lists[$l['id']] = array(
122
+ 'id' => $l['id'],
123
+ 'name' => $l['name']
124
+ );
125
+ }
126
+
127
+ if(isset($_REQUEST['renew-cached-data'])) {
128
+ // add notice
129
+ add_settings_error("mc4wp", "cache-renewed", 'MailChimp cache renewed.', 'updated' );
130
+ }
131
+
132
+ // store lists in transients
133
+ set_transient('mc4wp_mailchimp_lists', $lists, 3600); // 1 hour
134
+ set_transient('mc4wp_mailchimp_lists_fallback', $lists, 1209600); // 2 weeks
135
+ } else {
136
+ // api request failed, get fallback data (with longer lifetime)
137
+ $lists = get_transient('mc4wp_mailchimp_lists_fallback');
138
+ if(!$lists) { return array(); }
139
+ }
140
+
141
+ }
142
+
143
+ return $lists;
144
+ }
145
+
146
+ }
includes/MC4WP_Lite_Checkbox.php ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MC4WP_Lite_Checkbox
4
+ {
5
+ private $options = array();
6
+ private $showed_checkbox = false;
7
+
8
+ public function __construct()
9
+ {
10
+ $this->options = $opts = MC4WP_Lite::instance()->get_options();
11
+
12
+ add_action('init', array($this, 'on_init'));
13
+
14
+ // load checkbox css if necessary
15
+ if($this->options['checkbox_css'] == 1) {
16
+ add_action( 'wp_enqueue_scripts', array($this, 'load_stylesheet') );
17
+ add_action( 'login_enqueue_scripts', array($this, 'load_stylesheet') );
18
+ }
19
+
20
+ /* Comment Form Actions */
21
+ if($opts['checkbox_show_at_comment_form']) {
22
+ // hooks for checking if we should subscribe the commenter
23
+ add_action('comment_post', array($this, 'subscribe_from_comment'), 20, 2);
24
+
25
+ // hooks for outputting the checkbox
26
+ add_action('thesis_hook_after_comment_box', array($this,'output_checkbox'), 20);
27
+ add_action('comment_form', array($this,'output_checkbox'), 20);
28
+ }
29
+
30
+ /* Registration Form Actions */
31
+ if($opts['checkbox_show_at_registration_form']) {
32
+ add_action('register_form',array($this, 'output_checkbox'),20);
33
+ add_action('user_register',array($this, 'subscribe_from_registration'), 80, 1);
34
+ }
35
+
36
+ /* BuddyPress Form Actions */
37
+ if($opts['checkbox_show_at_bp_form']) {
38
+ add_action('bp_before_registration_submit_buttons', array($this, 'output_checkbox'), 20);
39
+ add_action('bp_complete_signup', array($this, 'subscribe_from_buddypress'), 20);
40
+ }
41
+
42
+ /* Multisite Form Actions */
43
+ if($opts['checkbox_show_at_ms_form']) {
44
+ add_action('signup_extra_fields', array($this, 'output_checkbox'), 20);
45
+ add_action('signup_blogform', array($this, 'add_multisite_hidden_checkbox'), 20);
46
+ add_action('wpmu_activate_blog', array($this, 'on_multisite_blog_signup'), 20, 5);
47
+ add_action('wpmu_activate_user', array($this, 'on_multisite_user_signup'), 20, 3);
48
+
49
+ add_filter('add_signup_meta', array($this, 'add_multisite_usermeta'));
50
+ }
51
+
52
+ /* bbPress actions */
53
+ if($opts['checkbox_show_at_bbpress_forms']) {
54
+ add_action('bbp_theme_after_topic_form_subscriptions', array($this, 'output_checkbox'), 10);
55
+ add_action('bbp_theme_after_reply_form_subscription', array($this, 'output_checkbox'), 10);
56
+ add_action('bbp_theme_anonymous_form_extras_bottom', array($this, 'output_checkbox'), 10);
57
+ add_action('bbp_new_topic', array($this, 'subscribe_from_bbpress_new_topic'), 10, 4);
58
+ add_action('bbp_new_reply', array($this, 'subscribe_from_bbpress_new_reply'), 10, 5);
59
+ }
60
+
61
+ /* Other actions... catch-all */
62
+ if($opts['checkbox_show_at_other_forms']) {
63
+ add_action('init', array($this, 'subscribe_from_whatever'));
64
+ }
65
+
66
+ }
67
+
68
+ public function on_init()
69
+ {
70
+ if(function_exists("wpcf7_add_shortcode")) {
71
+ wpcf7_add_shortcode('mc4wp_checkbox', array($this, 'get_checkbox'));
72
+ add_action('wpcf7_mail_sent', array($this, 'subscribe_from_cf7'));
73
+ }
74
+ }
75
+
76
+ public function get_checkbox($args = array())
77
+ {
78
+ $opts = $this->options;
79
+ $label = isset($args['labels'][0]) ? $args['labels'][0] : $opts['checkbox_label'];
80
+ $checked = $opts['checkbox_precheck'] ? "checked" : '';
81
+ $content = "\n<!-- Checkbox by MailChimp for WP plugin v". MC4WP_LITE_VERSION ." - http://dannyvankooten.com/wordpress-plugins/mailchimp-for-wordpress/ -->\n";
82
+ $content .= '<p id="mc4wp-checkbox">';
83
+ $content .= '<input type="checkbox" name="mc4wp-do-subscribe" id="mc4wp-checkbox-input" value="1" '. $checked . ' />';
84
+ $content .= '<label for="mc4wp-checkbox-input">'. __($label) . '</label>';
85
+ $content .= '</p>';
86
+ $content .= "\n<!-- / MailChimp for WP Plugin -->\n";
87
+ return $content;
88
+ }
89
+
90
+ public function output_checkbox()
91
+ {
92
+ if($this->showed_checkbox) return;
93
+ echo $this->get_checkbox();
94
+ $this->showed_checkbox = true;
95
+ }
96
+
97
+ public function load_stylesheet()
98
+ {
99
+ wp_enqueue_style( 'mc4wp-checkbox-reset', plugins_url('mailchimp-for-wp/css/checkbox.css') );
100
+ }
101
+
102
+
103
+ /* Start comment form functions */
104
+ public function subscribe_from_comment($cid, $comment_approved = '')
105
+ {
106
+ if(!isset($_POST['mc4wp-do-subscribe']) || $_POST['mc4wp-do-subscribe'] != 1) { return false; }
107
+ if($comment_approved === 'spam') { return false; }
108
+
109
+ $comment = get_comment($cid);
110
+
111
+ $email = $comment->comment_author_email;
112
+ $merge_vars = array(
113
+ 'OPTINIP' => $comment->comment_author_IP,
114
+ 'NAME' => $comment->comment_author
115
+ );
116
+
117
+ return $this->subscribe($email, $merge_vars);
118
+ }
119
+
120
+ public function add_comment_meta($comment_id)
121
+ {
122
+ add_comment_meta($comment_id, 'mc4wp_subscribe', $_POST['mc4wp-do-subscribe'], true );
123
+ }
124
+ /* End comment form functions */
125
+
126
+ /* Start registration form functions */
127
+ public function subscribe_from_registration($user_id)
128
+ {
129
+ if(!isset($_POST['mc4wp-do-subscribe']) || $_POST['mc4wp-do-subscribe'] != 1) { return false; }
130
+
131
+ // gather emailadress from user who WordPress registered
132
+ $user = get_userdata($user_id);
133
+ if(!$user) { return false; }
134
+
135
+ $email = $user->user_email;
136
+ $merge_vars = array(
137
+ 'NAME' => $user->user_login
138
+ );
139
+
140
+ if(isset($user->user_firstname) && !empty($user->user_firstname)) {
141
+ $merge_vars['FNAME'] = $user->user_firstname;
142
+ }
143
+
144
+ if(isset($user->user_lastname) && !empty($user->user_lastname)) {
145
+ $merge_vars['LNAME'] = $user->user_lastname;
146
+ }
147
+
148
+ $result = $this->subscribe($email, $merge_vars);
149
+ }
150
+ /* End registration form functions */
151
+
152
+ /* Start BuddyPress functions */
153
+ public function subscribe_from_buddypress()
154
+ {
155
+ if(!isset($_POST['mc4wp-do-subscribe']) || $_POST['mc4wp-do-subscribe'] != 1) return;
156
+
157
+ // gather emailadress and name from user who BuddyPress registered
158
+ $email = $_POST['signup_email'];
159
+ $merge_vars = array(
160
+ 'NAME' => $_POST['signup_username']
161
+ );
162
+
163
+ $result = $this->subscribe($email, $merge_vars);
164
+ }
165
+ /* End BuddyPress functions */
166
+
167
+ /* Start Multisite functions */
168
+ public function add_multisite_hidden_checkbox()
169
+ {
170
+ ?><input type="hidden" name="mc4wp-do-subscribe" value="<?php echo (isset($_POST['mc4wp-do-subscribe'])) ? 1 : 0; ?>" /><?php
171
+ }
172
+
173
+ public function on_multisite_blog_signup($blog_id, $user_id, $a, $b ,$meta = null)
174
+ {
175
+ if(!isset($meta['mc4wp-do-subscribe']) || $meta['mc4wp-do-subscribe'] != 1) return false;
176
+
177
+ return $this->subscribe_from_multisite($user_id);
178
+ }
179
+
180
+ public function on_multisite_user_signup($user_id, $password = NULL, $meta = NULL)
181
+ {
182
+ if(!isset($meta['mc4wp-do-subscribe']) || $meta['mc4wp-do-subscribe'] != 1) return false;
183
+
184
+ return $this->subscribe_from_multisite($user_id);
185
+ }
186
+
187
+ public function add_multisite_usermeta($meta)
188
+ {
189
+ $meta['mc4wp-do-subscribe'] = (isset($_POST['mc4wp-do-subscribe'])) ? 1 : 0;
190
+ return $meta;
191
+ }
192
+
193
+ public function subscribe_from_multisite($user_id)
194
+ {
195
+ $user = get_userdata($user_id);
196
+
197
+ if(!is_object($user)) return false;
198
+
199
+ $email = $user->user_email;
200
+ $merge_vars = array(
201
+ 'NAME' => $user->first_name . ' ' . $user->last_name
202
+ );
203
+ $result = $this->subscribe($email, $merge_vars);
204
+ }
205
+ /* End Multisite functions */
206
+
207
+ /* Start Contact Form 7 functions */
208
+ public function subscribe_from_cf7($arg = null)
209
+ {
210
+ if(!isset($_POST['mc4wp-do-subscribe']) || !$_POST['mc4wp-do-subscribe']) { return false; }
211
+
212
+ $_POST['mc4wp-try-subscribe'] = 1;
213
+ return $this->subscribe_from_whatever();
214
+ }
215
+ /* End Contact Form 7 functions */
216
+
217
+ /* Start whatever functions */
218
+ public function subscribe_from_whatever()
219
+ {
220
+ if(!isset($_POST['mc4wp-try-subscribe']) || !$_POST['mc4wp-try-subscribe']) { return false; }
221
+
222
+ // start running..
223
+ $email = null;
224
+ $merge_vars = array();
225
+
226
+ // Add all fields with name attribute "mc4wp-*" to merge vars
227
+ foreach($_POST as $key => $value) {
228
+
229
+ if($key == 'mc4wp-try-subscribe') {
230
+ continue;
231
+ } elseif(!$email && is_email($value)) {
232
+ // find e-mail field
233
+ $email = $value;
234
+ } elseif(in_array($key, array('name', 'your-name', 'NAME', 'username', 'fullname'))) {
235
+ // find name field
236
+ $merge_vars['NAME'] = $value;
237
+ } elseif(substr($key, 0, 5) == 'mc4wp-') {
238
+ // find extra fields which should be sent to MailChimp
239
+ $key = strtoupper(substr($key, 5));
240
+
241
+ if(!isset($merge_vars[$key])) {
242
+ $merge_vars[$key] = $value;
243
+ }
244
+ }
245
+ }
246
+
247
+ // if email has not been found by the smart field guessing, return false.. sorry
248
+ if(!$email) {
249
+ return false;
250
+ }
251
+
252
+ // subscribe
253
+ $result = $this->subscribe($email, $merge_vars);
254
+ return true;
255
+ }
256
+ /* End whatever functions */
257
+
258
+ public function subscribe_from_bbpress($anonymous_data, $user_id)
259
+ {
260
+ if(!isset($_POST['mc4wp-do-subscribe']) || $_POST['mc4wp-do-subscribe'] != 1) { return; }
261
+
262
+ if($anonymous_data) {
263
+
264
+ $email = $anonymous_data['bbp_anonymous_email'];
265
+ $merge_vars = array(
266
+ 'NAME' => $anonymous_data['bbp_anonymous_name']
267
+ );
268
+
269
+ } elseif($user_id) {
270
+
271
+ $user_info = get_userdata($user_id);
272
+ $email = $user_info->user_email;
273
+ $merge_vars = array(
274
+ 'NAME' => $user_info->first_name . ' ' . $user_info->last_name,
275
+ 'FNAME' => $user_info->first_name,
276
+ 'LNAME' => $user_info->last_name
277
+ );
278
+
279
+ } else {
280
+ return false;
281
+ }
282
+
283
+ return $this->subscribe($email, $merge_vars);
284
+ }
285
+
286
+ public function subscribe_from_bbpress_new_topic($topic_id, $forum_id, $anonymous_data, $topic_author)
287
+ {
288
+ return $this->subscribe_from_bbpress($anonymous_data, $topic_author);
289
+ }
290
+
291
+ public function subscribe_from_bbpress_new_reply($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author)
292
+ {
293
+ return $this->subscribe_from_bbpress($anonymous_data, $reply_author);
294
+ }
295
+
296
+ public function subscribe($email, array $merge_vars = array())
297
+ {
298
+ $api = MC4WP_Lite::instance()->get_mailchimp_api();
299
+ $opts = $this->options;
300
+
301
+ $lists = $opts['checkbox_lists'];
302
+
303
+ if(empty($lists)) {
304
+ return 'no_lists_selected';
305
+ }
306
+
307
+ // guess FNAME and LNAME
308
+ if(isset($merge_vars['NAME']) && !isset($merge_vars['FNAME']) && !isset($merge_vars['LNAME'])) {
309
+
310
+ $strpos = strpos($merge_vars['NAME'], ' ');
311
+
312
+ if($strpos) {
313
+ $merge_vars['FNAME'] = substr($merge_vars['NAME'], 0, $strpos);
314
+ $merge_vars['LNAME'] = substr($merge_vars['NAME'], $strpos);
315
+ } else {
316
+ $merge_vars['FNAME'] = $merge_vars['NAME'];
317
+ }
318
+ }
319
+
320
+ foreach($lists as $list) {
321
+ $result = $api->listSubscribe($list, $email, $merge_vars, 'html', $opts['checkbox_double_optin']);
322
+ }
323
+
324
+ if($api->errorCode) {
325
+
326
+ if($api->errorCode == 214) {
327
+ return 'already_subscribed';
328
+ }
329
+
330
+ return 'error';
331
+ }
332
+
333
+ // flawed
334
+ // this will only return the result of the last list a subscribe attempt has been sent to
335
+ return $result;
336
+ }
337
+
338
+
339
+
340
+ }
includes/MC4WP_Lite_Form.php ADDED
@@ -0,0 +1,338 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MC4WP_Lite_Form
4
+ {
5
+ private $options;
6
+ private $form_instance_number = 1;
7
+ private $error = null;
8
+ private $success = false;
9
+ private $submitted_form_instance = 0;
10
+
11
+ public function __construct()
12
+ {
13
+ $this->options = $opts = MC4WP_Lite::instance()->get_options();
14
+
15
+ if($opts['form_css']) {
16
+ add_action( 'wp_enqueue_scripts', array($this, 'load_stylesheet') );
17
+ }
18
+
19
+ add_shortcode('mc4wp-form', array($this, 'output_form'));
20
+
21
+ // enable shortcodes in text widgets
22
+ add_filter( 'widget_text', 'shortcode_unautop');
23
+ add_filter( 'widget_text', 'do_shortcode', 11);
24
+
25
+ if(isset($_POST['mc4wp_form_submit'])) {
26
+ $this->ensure_backwards_compatibility();
27
+ add_action('init', array($this, 'submit'));
28
+ }
29
+
30
+
31
+ }
32
+
33
+ public function load_stylesheet()
34
+ {
35
+ wp_enqueue_style( 'mc4wp-form-reset', plugins_url('mailchimp-for-wp/css/form.css') );
36
+ }
37
+
38
+ public function output_form($atts, $content = null)
39
+ {
40
+ $opts = $this->options;
41
+
42
+ // add some useful css classes
43
+ $css_classes = ' ';
44
+ if($this->error) $css_classes .= 'mc4wp-form-error ';
45
+ if($this->success) $css_classes .= 'mc4wp-form-success ';
46
+
47
+ $content = "\n<!-- Form by MailChimp for WP plugin v". MC4WP_LITE_VERSION ." - http://dannyvankooten.com/wordpress-plugins/mailchimp-for-wordpress/ -->\n";
48
+ $content .= '<form method="post" action="'. $this->get_current_url() .'#mc4wp-form-'. $this->form_instance_number .'" id="mc4wp-form-'.$this->form_instance_number.'" class="mc4wp-form form'.$css_classes.'">';
49
+
50
+
51
+ // maybe hide the form
52
+ if(!($this->success && $opts['form_hide_after_success'])) {
53
+ $form_markup = __($this->options['form_markup']);
54
+ // replace special values
55
+ $form_markup = $this->replace_form_variables($form_markup);
56
+
57
+ $content .= $form_markup;
58
+
59
+ // hidden fields
60
+ $content .= '<textarea name="mc4wp_required_but_not_really" style="display: none;"></textarea>';
61
+ $content .= '<input type="hidden" name="mc4wp_form_submit" value="1" />';
62
+ $content .= '<input type="hidden" name="mc4wp_form_instance" value="'. $this->form_instance_number .'" />';
63
+ }
64
+
65
+
66
+ if($this->form_instance_number == $this->submitted_form_instance) {
67
+
68
+ if($this->success) {
69
+ $content .= '<div class="mc4wp-alert mc4wp-success">' . __($opts['form_text_success']) . '</div>';
70
+ } elseif($this->error) {
71
+
72
+ $api = MC4WP_Lite::instance()->get_mailchimp_api();
73
+ $e = $this->error;
74
+
75
+ if($e == 'already_subscribed') {
76
+ $text = (empty($opts['form_text_already_subscribed'])) ? $api->errorMessage : $opts['form_text_already_subscribed'];
77
+ $content .= '<div class="mc4wp-alert mc4wp-notice">'. __($text) .'</div>';
78
+ } elseif(isset($opts['form_text_' . $e]) && !empty($opts['form_text_'. $e] )) {
79
+ $content .= '<div class="mc4wp-alert mc4wp-error">' . __($opts['form_text_' . $e]) . '</div>';
80
+ }
81
+
82
+ if(current_user_can('manage_options')) {
83
+
84
+ if($api->errorCode && !empty($api->errorMessage)) {
85
+ $content .= '<div class="mc4wp-alert mc4wp-error"><strong>Admin notice:</strong> '. $api->errorMessage . '</div>';
86
+ }
87
+ }
88
+
89
+ }
90
+ // endif
91
+ }
92
+
93
+ if(current_user_can('manage_options') && empty($opts['form_lists'])) {
94
+ $content .= '<div class="mc4wp-alert mc4wp-error"><strong>Admin notice:</strong> you have not selected a MailChimp list for this sign-up form to subscribe to yet. <a href="'. get_admin_url(null, 'admin.php?page=mailchimp-for-wp&tab=form-settings') .'">Edit your form settings</a> and select at least 1 list.</div>';
95
+ }
96
+
97
+ $content .= "</form>";
98
+ $content .= "\n<!-- / MailChimp for WP Plugin -->\n";
99
+
100
+ // increase form instance number in case there is more than one form on a page
101
+ $this->form_instance_number++;
102
+
103
+ return $content;
104
+ }
105
+
106
+ public function submit()
107
+ {
108
+ $opts = $this->options;
109
+ $this->submitted_form_instance = (int) $_POST['mc4wp_form_instance'];
110
+
111
+ if(!isset($_POST['EMAIL']) || !is_email($_POST['EMAIL'])) {
112
+ // no (valid) e-mail address has been given
113
+
114
+ $this->error = 'invalid_email';
115
+ return false;
116
+ }
117
+
118
+ if(isset($_POST['mc4wp_required_but_not_really']) && !empty($_POST['mc4wp_required_but_not_really'])) {
119
+ // spam bot filled the honeypot field
120
+ return false;
121
+ }
122
+
123
+ $email = $_POST['EMAIL'];
124
+
125
+ // setup merge vars
126
+ $merge_vars = array();
127
+
128
+ foreach($_POST as $name => $value) {
129
+
130
+ // only add uppercases fields to merge variables array
131
+ if(!empty($name) && $name == 'EMAIL' || $name !== strtoupper($name)) { continue; }
132
+
133
+ if($name === 'GROUPINGS') {
134
+
135
+ $groupings = $value;
136
+
137
+ // malformed
138
+ if(!is_array($groupings)) { continue; }
139
+
140
+ // setup groupings array
141
+ $merge_vars['GROUPINGS'] = array();
142
+
143
+ foreach($groupings as $grouping_id_or_name => $groups) {
144
+
145
+ $grouping = array();
146
+
147
+ if(is_numeric($grouping_id_or_name)) {
148
+ $grouping['id'] = $grouping_id_or_name;
149
+ } else {
150
+ $grouping['name'] = $grouping_id_or_name;
151
+ }
152
+
153
+ if(is_array($groups)) {
154
+ $grouping['groups'] = implode(',', $groups);
155
+ } else {
156
+ $grouping['groups'] = $groups;
157
+ }
158
+
159
+ // add grouping to array
160
+ $merge_vars['GROUPINGS'][] = $grouping;
161
+ }
162
+
163
+ if(empty($merge_vars['GROUPINGS'])) { unset($merge_vars['GROUPINGS']); }
164
+
165
+ } else {
166
+ $merge_vars[$name] = $value;
167
+ }
168
+
169
+ }
170
+
171
+ $result = $this->subscribe($email, $merge_vars);
172
+
173
+ if($result === true) {
174
+ $this->success = true;
175
+
176
+ // check if we want to redirect the visitor
177
+ if(!empty($opts['form_redirect'])) {
178
+ wp_redirect($opts['form_redirect']);
179
+ exit;
180
+ }
181
+
182
+ return true;
183
+ } else {
184
+
185
+ $this->success = false;
186
+ $this->error = $result;
187
+
188
+ return false;
189
+ }
190
+ }
191
+
192
+ private function get_ip_address()
193
+ {
194
+ if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
195
+ $ip = $_SERVER['HTTP_CLIENT_IP'];
196
+ } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
197
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
198
+ } else {
199
+ $ip = $_SERVER['REMOTE_ADDR'];
200
+ }
201
+
202
+ return $ip;
203
+ }
204
+
205
+ private function get_current_url() {
206
+ $page_url = 'http';
207
+
208
+ if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) { $page_url .= 's'; }
209
+
210
+ $page_url .= '://';
211
+
212
+ if (!isset($_SERVER['REQUEST_URI'])) {
213
+ $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);
214
+ if (isset($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'] .='?'.$_SERVER['QUERY_STRING']; }
215
+ }
216
+
217
+ if($_SERVER['SERVER_PORT'] != '80') {
218
+ $page_url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
219
+ } else {
220
+ $page_url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
221
+ }
222
+
223
+ return $page_url;
224
+ }
225
+
226
+ /*
227
+ Ensure backwards compatibility so sign-up forms that contain old form mark-up rules don't break
228
+ - Uppercase $_POST variables that should be sent to MailChimp
229
+ - Format GROUPINGS in one of the following formats.
230
+ $_POST[GROUPINGS][$group_id] = "Group 1, Group 2"
231
+ $_POST[GROUPINGS][$group_name] = array("Group 1", "Group 2")
232
+ */
233
+ public function ensure_backwards_compatibility()
234
+ {
235
+
236
+ // upercase $_POST variables
237
+ foreach($_POST as $name => $value) {
238
+
239
+ // only uppercase variables which are not already uppercased, skip mc4wp internal vars
240
+ if($name === strtoupper($name) || in_array($name, array('mc4wp_form_instance', 'mc4wp_required_but_not_really', 'mc4wp_form_submit'))) continue;
241
+ $uppercased_name = strtoupper($name);
242
+
243
+ // set new (uppercased) $_POST variable, unset old one.
244
+ $_POST[$uppercased_name] = $value;
245
+ unset($_POST[$name]);
246
+ }
247
+
248
+ // detect old style GROUPINGS, then fix it.
249
+ if(isset($_POST['GROUPINGS']) && is_array($_POST['GROUPINGS']) && isset($_POST['GROUPINGS'][0])) {
250
+
251
+ $old_groupings = $_POST['GROUPINGS'];
252
+ unset($_POST['GROUPINGS']);
253
+ $new_groupings = array();
254
+
255
+ foreach($old_groupings as $grouping) {
256
+
257
+ if(!isset($grouping['id']) && !isset($grouping['name'])) { continue; }
258
+
259
+ $key = (isset($grouping['id'])) ? $grouping['id'] : $grouping['name'];
260
+
261
+ $new_groupings[$key] = $grouping['groups'];
262
+
263
+ }
264
+
265
+ // re-fill $_POST array with new groupings
266
+ if(!empty($new_groupings)) { $_POST['GROUPINGS'] = $new_groupings; }
267
+
268
+ }
269
+
270
+ return;
271
+ }
272
+
273
+ public function subscribe($email, array $merge_vars = array())
274
+ {
275
+ $api = MC4WP_Lite::instance()->get_mailchimp_api();
276
+ $opts = $this->options;
277
+
278
+ $lists = $opts['form_lists'];
279
+
280
+ if(empty($lists)) {
281
+ return 'no_lists_selected';
282
+ }
283
+
284
+ // guess FNAME and LNAME
285
+ if(isset($merge_vars['NAME']) && !isset($merge_vars['FNAME']) && !isset($merge_vars['LNAME'])) {
286
+
287
+ $strpos = strpos($name, ' ');
288
+
289
+ if($strpos) {
290
+ $merge_vars['FNAME'] = substr($name, 0, $strpos);
291
+ $merge_vars['LNAME'] = substr($name, $strpos);
292
+ } else {
293
+ $merge_vars['FNAME'] = $name;
294
+ }
295
+ }
296
+
297
+ foreach($lists as $list) {
298
+ $result = $api->listSubscribe($list, $email, $merge_vars, 'html', $opts['form_double_optin']);
299
+ }
300
+
301
+ if($api->errorCode) {
302
+
303
+ if($api->errorCode == 214) {
304
+ return 'already_subscribed';
305
+ }
306
+
307
+ return 'error';
308
+ }
309
+
310
+ // flawed
311
+ // this will only return the result of the last list a subscribe attempt has been sent to
312
+ return $result;
313
+ }
314
+
315
+ private function replace_form_variables($markup)
316
+ {
317
+
318
+ $markup = str_replace(array('%N%', '{n}'), $this->form_instance_number, $markup);
319
+ $markup = str_replace(array('%IP_ADDRESS%', '{ip}'), $this->get_ip_address(), $markup);
320
+ $markup = str_replace(array('%DATE%', '{date}'), date('Y/m/d'), $markup);
321
+ $markup = str_replace('{time}', date("H:i:s"), $markup);
322
+ $markup = str_replace('{current_url}', $this->get_current_url(), $markup);
323
+
324
+ $needles = array('{user_email}', '{user_firstname}', '{user_lastname}', '{user_name}', '{user_id}');
325
+ if(is_user_logged_in()) {
326
+ // logged in user, replace vars by user vars
327
+ $user = wp_get_current_user();
328
+ $replacements = array($user->user_email, $user->user_firstname, $user->user_lastname, $user->display_name, $user->ID);
329
+ $markup = str_replace($needles, $replacements, $markup);
330
+ } else {
331
+ // no logged in user, remove vars
332
+ $markup = str_replace($needles, '', $markup);
333
+ }
334
+
335
+ return $markup;
336
+ }
337
+
338
+ }
includes/MCAPI.php ADDED
@@ -0,0 +1,2485 @@