PluginProbe
Mailchimp List Subscribe Form / 1.2.4
Mailchimp List Subscribe Form v1.2.4
1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 All 55 releases
mailchimp / mailchimp_widget.php

mailchimp_widget.php in Mailchimp List Subscribe Form 1.2.4, at mailchimp_widget.php

230 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Displays a MailChimp Signup Form
4 **/
5 function mailchimpSF_signup_form($args = array()) {
6 extract($args);
7
8 $mv = get_option('mc_merge_vars');
9 $ig = get_option('mc_interest_groups');
10
11 // See if we have valid Merge Vars
12 if (!is_array($mv)){
13 echo $before_widget;
14 ?>
15 <div class="mc_error_msg">
16 <?php esc_html_e('There was a problem loading your MailChimp details. Please re-run the setup process under Settings->MailChimp Setup', 'mailchimp_i18n'); ?>
17 </div>
18 <?php
19 echo $after_widget;
20 return;
21 }
22
23 // Get some options
24 $uid = get_option('mc_user_id');
25 $list_name = get_option('mc_list_name');
26
27 echo $before_widget;
28
29 $header = get_option('mc_header_content');
30 // See if we have custom header content
31 if (!empty($header)) {
32 // See if we need to wrap the header content in our own div
33 if (strlen($header) == strlen(strip_tags($header))){
34 echo $before_title ? $before_title : '<div class="mc_custom_border_hdr">';
35 echo $header; // don't escape $header b/c it may have HTML allowed
36 echo $after_title ? $after_title : '</div><!-- /mc_custom_border_hdr -->';
37 }
38 else {
39 echo $header; // don't escape $header b/c it may have HTML allowed
40 }
41 }
42
43 $sub_heading = trim(get_option('mc_subheader_content'));
44 ?>
45
46 <div id="mc_signup">
47 <form method="post" action="#mc_signup" id="mc_signup_form">
48 <input type="hidden" id="mc_submit_type" name="mc_submit_type" value="html" />
49 <input type="hidden" name="mcsf_action" value="mc_submit_signup_form" />
50 <?php wp_nonce_field('mc_submit_signup_form', '_mc_submit_signup_form_nonce', false); ?>
51
52 <?php
53 if ($sub_heading) {
54 ?>
55 <div id="mc_subheader">
56 <?php echo $sub_heading; ?>
57 </div><!-- /mc_subheader -->
58 <?php
59 }
60 ?>
61
62 <div class="mc_form_inside">
63
64 <div class="updated" id="mc_message">
65 <?php echo mailchimpSF_global_msg(); ?>
66 </div><!-- /mc_message -->
67
68 <?php
69 //don't show the "required" stuff if there's only 1 field to display.
70 $num_fields = 0;
71 foreach((array)$mv as $var) {
72 $opt = 'mc_mv_'.$var['tag'];
73 if ($var['req'] || get_option($opt) == 'on') {
74 $num_fields++;
75 }
76 }
77
78 if (is_array($mv)) {
79 // head on back to the beginning of the array
80 reset($mv);
81 }
82
83 // Loop over our vars, and output the ones that are set to display
84 foreach($mv as $var) {
85 $opt = 'mc_mv_'.$var['tag'];
86 // See if that var is set as required, or turned on (for display)
87 if ($var['req'] || get_option($opt) == 'on') {
88 ?>
89 <div class="mc_merge_var">
90 <label for="<?php echo esc_attr($opt); ?>" class="mc_var_label"><?php echo esc_html($var['name']); ?>
91 <?php
92 if ($var['req'] && $num_fields > 1) {
93 ?>
94 <span class="mc_required">*</span>
95 <?php
96 }
97 ?>
98 </label>
99
100 <br />
101
102 <input type="text" size="18" value="" name="<?php echo esc_attr($opt); ?>" id="<?php echo esc_attr($opt); ?>" class="mc_input"/>
103 </div><!-- /mc_merge_var -->
104 <?php
105 }
106 }
107
108
109 // Show an explanation of the * if there's more than one field
110 if ($num_fields > 1){
111 ?>
112 <div id="mc-indicates-required">
113 * = <?php esc_html_e('required field', 'mailchimp_i18n'); ?>
114 </div><!-- /mc-indicates-required -->
115 <?php
116 }
117
118
119 // Show our Interest groups fields if we have them, and they're set to on
120 if ($ig && get_option('mc_show_interest_groups') == 'on') {
121 ?>
122
123 <div id="mc_interests_header">
124 <?php echo esc_html($ig['name']); ?>
125 </div><!-- /mc_interests_header -->
126
127 <div class="mc_interest">
128
129 <?php
130 $i=0; // Set our counter
131 switch ($ig['form_field']) {
132 case 'checkbox':
133 case 'checkboxes':
134 foreach($ig['groups'] as $interest){
135 $interest = $interest['name'];
136 ?>
137 <input type="checkbox" name="<?php echo esc_attr('interests['.$interest.']'); ?>" id="<?php echo esc_attr('mc_interest_'.$i); ?>" class="mc_interest"/>
138 <label for="<?php echo esc_attr('mc_interest_'.$i); ?>" class="mc_interest_label"> <?php echo esc_html($interest); ?></label>
139 <br/>
140 <?php
141 $i++;
142 }
143 break;
144 case 'radio':
145 foreach($ig['groups'] as $interest){
146 $interest = $interest['name'];
147 ?>
148 <input type="radio" name="interests" id="<?php echo esc_attr('mc_interest_'.$i); ?>" class="mc_interest" value="<?php echo esc_attr($interest); ?>"/>
149 <label for="<?php echo esc_attr('mc_interest_'.$i); ?>" class="mc_interest_label"> <?php echo esc_html($interest); ?></label>
150 <br/>
151 <?php
152 $i++;
153 }
154 break;
155 case 'select':
156 case 'dropdown':
157 ?>
158 <select name="interests">
159 <option value=""></option>
160 <?php
161 foreach($ig['groups'] as $interest){
162 $interest = $interest['name'];
163 ?>
164 <option value="<?php echo esc_attr($interest); ?>"><?php echo esc_html($interest); ?></option>
165 <?php
166 }
167 ?>
168 </select>
169 <?php
170 break;
171 }
172 ?>
173
174 </div><!-- /mc_interest -->
175
176 <?php
177 }
178 ?>
179
180 <div class="mc_signup_submit">
181 <input type="submit" name="mc_signup_submit" id="mc_signup_submit" value="<?php echo esc_attr(get_option('mc_submit_text')); ?>" class="button" />
182 </div><!-- /mc_signup_submit -->
183
184
185 <?php
186 if ( get_option('mc_use_unsub_link') == 'on') {
187 list($key, $dc) = explode("-",get_option('mc_apikey'),2);
188 if (!$dc) $dc = "us1";
189 $host = 'http://'.$dc.'.list-manage.com';
190 ?>
191 <div id="mc_unsub_link" align="center">
192 <a href="<?php echo esc_url($host.'/unsubscribe/?u='.get_option('mc_user_id').'&amp;id='.get_option('mc_list_id')); ?>" target="_blank"><?php esc_html_e('unsubscribe from list', 'mailchimp_i18n'); ?></a>
193 </div><!-- /mc_unsub_link -->
194 <?php
195 }
196 if ( get_option('mc_rewards') == 'on') {
197 ?>
198 <br/>
199 <div id="mc_display_rewards" align="center">
200 <?php esc_html_e('powered by', 'mailchimp_i18n'); ?> <a href="<?php echo esc_url('http://www.mailchimp.com/affiliates/?aid='.get_option('mc_user_id').'&amp;afl=1'); ?>">MailChimp</a>!
201 </div><!-- /mc_display_rewards -->
202 <?php
203 }
204 ?>
205 </div><!-- /mc_form_inside -->
206 </form><!-- /mc_signup_form -->
207 </div><!-- /mc_signup_container -->
208 <?php
209 echo $after_widget;
210 }
211
212
213 /**
214 * MailChimp Subscribe Box widget class
215 */
216 class mailchimpSF_Widget extends WP_Widget {
217
218 function mailchimpSF_Widget() {
219 $widget_ops = array(
220 'description' => __('Displays a MailChimp Subscribe box', 'mailchimp_i18n')
221 );
222 $this->WP_Widget('mailchimpSF_widget', __('MailChimp Widget', 'mailchimp_i18n'), $widget_ops);
223 }
224
225 function widget( $args, $instance ) {
226 mailchimpSF_signup_form(array_merge($args, $instance));
227 }
228 }
229 ?>
230