PluginProbe
Mailchimp List Subscribe Form / trunk
Mailchimp List Subscribe Form vtrunk
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
← All changes | mailchimp_widget.php +671 -154 1.2.4trunk View file →
@@ -1,229 +1,746 @@
1 1 <?php
2 2 /**
3 - * Displays a MailChimp Signup Form
4 - **/
5 -function mailchimpSF_signup_form($args = array()) {
6 - extract($args);
3 + * Mailchimp widget
4 + *
5 + * @package Mailchimp
6 + */
7 7
8 - $mv = get_option('mc_merge_vars');
9 - $ig = get_option('mc_interest_groups');
8 +/**
9 + * Displays a Mailchimp Signup Form
10 + *
11 + * @param array $args Args
12 + * @return void
13 + */
14 +function mailchimp_sf_signup_form( $args = array() ) {
15 + // Check if we should display the form.
16 + if ( ! mailchimp_sf_should_display_form() ) {
17 + return;
18 + }
10 19
20 + $before_title = isset( $args['before_title'] ) ? $args['before_title'] : '';
21 + $after_title = isset( $args['after_title'] ) ? $args['after_title'] : '';
22 + $before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : '';
23 + $after_widget = isset( $args['after_widget'] ) ? $args['after_widget'] : '';
24 + $is_preview = isset( $args['is_preview'] ) ? (bool) $args['is_preview'] : false;
25 + $preview_data = isset( $args['preview_data'] ) ? $args['preview_data'] : array();
26 +
27 + $mv = get_option( 'mc_merge_vars' );
28 + $igs = get_option( 'mc_interest_groups' );
29 +
11 30 // See if we have valid Merge Vars
12 - if (!is_array($mv)){
13 - echo $before_widget;
31 + if ( ! is_array( $mv ) ) {
32 + if ( ! empty( $before_widget ) ) {
33 + echo wp_kses_post( $before_widget );
34 + } else {
35 + echo '<div class="mc_container">';
36 + }
14 37 ?>
15 38 <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'); ?>
39 + <?php
40 + echo wp_kses(
41 + __(
42 + 'Sorry, there was a problem loading your Mailchimp details. Please navigate to <strong>Settings</strong> and click <strong>Mailchimp Setup</strong> to try again.',
43 + 'mailchimp'
44 + ),
45 + [
46 + 'strong' => [],
47 + ]
48 + );
49 + ?>
17 50 </div>
18 51 <?php
19 - echo $after_widget;
52 + if ( ! empty( $after_widget ) ) {
53 + echo wp_kses_post( $after_widget );
54 + }
55 +
56 + if ( empty( $before_widget ) ) {
57 + echo '</div>';
58 + }
59 +
20 60 return;
21 61 }
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 62
29 - $header = get_option('mc_header_content');
63 + if ( ! empty( $before_widget ) ) {
64 + echo wp_kses_post( $before_widget );
65 + } else {
66 + echo '<div class="mc_container">';
67 + }
68 +
69 + $header = get_option( 'mc_header_content' );
70 + if ( $is_preview && ! empty( $preview_data ) ) {
71 + $header = $preview_data['header'] ?? $header;
72 + }
73 +
30 74 // See if we have custom header content
31 - if (!empty($header)) {
75 + if ( ! empty( $header ) ) {
32 76 // 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 -->';
77 + if ( strlen( $header ) === strlen( wp_strip_all_tags( $header ) ) ) {
78 + echo ! empty( $before_title ) ? wp_kses_post( $before_title ) : '<div class="mc_custom_border_hdr">';
79 + echo wp_kses_post( $header );
80 + echo ! empty( $after_title ) ? wp_kses_post( $after_title ) : '</div><!-- /mc_custom_border_hdr -->';
81 + } else {
82 + echo wp_kses_post( $header );
37 83 }
38 - else {
39 - echo $header; // don't escape $header b/c it may have HTML allowed
40 - }
41 84 }
42 -
43 - $sub_heading = trim(get_option('mc_subheader_content'));
85 +
86 + $sub_heading = trim( get_option( 'mc_subheader_content' ) );
87 + $list_id = get_option( 'mc_list_id' );
88 + $form_id = wp_unique_id( $list_id . '_' );
89 + if ( $is_preview && ! empty( $preview_data ) ) {
90 + $sub_heading = $preview_data['sub_heading'] ?? $sub_heading;
91 + }
44 92 ?>
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" />
93 +
94 +<div id="mc_signup_<?php echo esc_attr( $form_id ); ?>">
95 + <form method="post" action="#mc_signup_<?php echo esc_attr( $form_id ); ?>" id="mc_signup_form_<?php echo esc_attr( $form_id ); ?>" class="mc_signup_form" data-list-id="<?php echo esc_attr( $list_id ); ?>">
96 + <input type="hidden" class="mc_submit_type" name="mc_submit_type" value="html" />
49 97 <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) {
98 + <?php wp_nonce_field( 'mc_submit_signup_form', '_mc_submit_signup_form_nonce', false ); ?>
99 +
100 + <?php
101 + if ( $sub_heading ) {
54 102 ?>
55 - <div id="mc_subheader">
56 - <?php echo $sub_heading; ?>
103 + <div class="mc_subheader">
104 + <?php echo wp_kses_post( $sub_heading ); ?>
57 105 </div><!-- /mc_subheader -->
58 106 <?php
59 - }
107 + }
60 108 ?>
61 -
109 +
62 110 <div class="mc_form_inside">
63 -
64 - <div class="updated" id="mc_message">
65 - <?php echo mailchimpSF_global_msg(); ?>
66 - </div><!-- /mc_message -->
67 111
112 + <div class="mc_message_wrapper">
113 + <?php echo wp_kses_post( mailchimp_sf_frontend_msg() ); ?>
114 + </div><!-- /mc_message_wrapper -->
115 +
68 116 <?php
69 - //don't show the "required" stuff if there's only 1 field to display.
117 + // don't show the "required" stuff if there's only 1 field to display.
70 118 $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++;
119 + foreach ( (array) $mv as $mv_var ) {
120 + $opt = 'mc_mv_' . $mv_var['tag'];
121 + if ( $is_preview && ! empty( $preview_data ) ) {
122 + if ( $mv_var['required'] || ( isset( $preview_data['fields'][ $mv_var['tag'] ] ) && $preview_data['fields'][ $mv_var['tag'] ] ) ) {
123 + ++$num_fields;
124 + }
125 + } elseif ( $mv_var['required'] || get_option( $opt ) === 'on' ) {
126 + ++$num_fields;
75 127 }
76 128 }
77 129
78 - if (is_array($mv)) {
130 + if ( is_array( $mv ) ) {
79 131 // head on back to the beginning of the array
80 - reset($mv);
132 + reset( $mv );
81 133 }
82 -
134 +
83 135 // 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
136 + foreach ( $mv as $mv_var ) {
137 + $opt = 'mc_mv_' . $mv_var['tag'];
138 + $should_display = 'on' === get_option( $opt );
139 + if ( $is_preview && ! empty( $preview_data ) ) {
140 + $should_display = $preview_data['fields'][ $mv_var['tag'] ] ?? $should_display;
105 141 }
142 +
143 + echo mailchimp_form_field( $mv_var, $num_fields, $should_display ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignoring because form field is escaped in function
106 144 }
107 -
108 -
145 +
109 146 // Show an explanation of the * if there's more than one field
110 - if ($num_fields > 1){
147 + if ( $num_fields > 1 ) {
111 148 ?>
112 - <div id="mc-indicates-required">
113 - * = <?php esc_html_e('required field', 'mailchimp_i18n'); ?>
149 + <div class="mc-indicates-required">
150 + * = <?php esc_html_e( 'required field', 'mailchimp' ); ?>
114 151 </div><!-- /mc-indicates-required -->
115 152 <?php
116 153 }
117 -
118 -
154 +
119 155 // 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'];
156 + if ( is_array( $igs ) && ! empty( $igs ) ) {
157 + foreach ( $igs as $ig ) {
158 + if ( is_array( $ig ) && isset( $ig['id'] ) ) {
159 + $should_display = 'on' === get_option( 'mc_show_interest_groups_' . $ig['id'] );
160 + if ( $is_preview && ! empty( $preview_data ) ) {
161 + $should_display = $preview_data['groups'][ $ig['id'] ] ?? $should_display;
162 + }
163 + if ( ( $igs && $should_display ) ) {
164 + if ( 'hidden' !== $ig['type'] ) {
136 165 ?>
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/>
166 + <div class="mc_interests_header">
167 + <?php echo esc_html( $ig['title'] ); ?>
168 + </div><!-- /mc_interests_header -->
169 + <div class="mc_interest">
140 170 <?php
141 - $i++;
142 - }
143 - break;
144 - case 'radio':
145 - foreach($ig['groups'] as $interest){
146 - $interest = $interest['name'];
171 + } else {
147 172 ?>
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/>
173 + <div class="mc_interest" style="display: none;">
151 174 <?php
152 - $i++;
153 175 }
154 - break;
155 - case 'select':
156 - case 'dropdown':
157 176 ?>
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>
177 +
169 178 <?php
170 - break;
179 + mailchimp_interest_group_field( $ig );
180 + ?>
181 + </div><!-- /mc_interest -->
182 +
183 + <?php
184 + }
171 185 }
172 - ?>
173 -
174 - </div><!-- /mc_interest -->
175 -
186 + }
187 + }
188 +
189 + if ( get_option( 'mc_email_type_option' ) ) {
190 + ?>
191 + <div class="mergeRow">
192 + <label class="mc_email_format"><?php esc_html_e( 'Preferred Format', 'mailchimp' ); ?></label>
193 + <div class="field-group groups mc_email_options">
194 + <ul class="mc_list">
195 + <li><input type="radio" name="email_type" id="email_type_html_<?php echo esc_attr( $form_id ); ?>" value="html" checked="checked"><label for="email_type_html_<?php echo esc_attr( $form_id ); ?>" class="mc_email_type"><?php esc_html_e( 'HTML', 'mailchimp' ); ?></label></li>
196 + <li><input type="radio" name="email_type" id="email_type_text_<?php echo esc_attr( $form_id ); ?>" value="text"><label for="email_type_text_<?php echo esc_attr( $form_id ); ?>" class="mc_email_type"><?php esc_html_e( 'Text', 'mailchimp' ); ?></label></li>
197 + </ul>
198 + </div>
199 + </div>
200 +
176 201 <?php
177 202 }
203 +
204 + // Add a honeypot field.
205 + mailchimp_sf_honeypot_field();
206 +
207 + $submit_text = get_option( 'mc_submit_text' );
208 +
209 + // Preview.
210 + if ( $is_preview && ! empty( $preview_data ) ) {
211 + $submit_text = $preview_data['submit_text'] ?? $submit_text;
212 + }
178 213 ?>
179 214
180 215 <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" />
216 + <input type="submit" name="mc_signup_submit" class="mc_signup_submit_button" id="mc_signup_submit_<?php echo esc_attr( $form_id ); ?>" value="<?php echo esc_attr( $submit_text ); ?>" class="button" />
182 217 </div><!-- /mc_signup_submit -->
183 -
184 -
218 +
185 219 <?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';
220 + $user = get_option( 'mc_user' );
221 + $display_unsub_link = 'on' === get_option( 'mc_use_unsub_link' );
222 + if ( $is_preview && ! empty( $preview_data ) ) {
223 + $display_unsub_link = $preview_data['display_unsub_link'] ?? $display_unsub_link;
224 + }
225 +
226 + if ( $user && $display_unsub_link ) {
227 + $api = mailchimp_sf_get_api();
228 + $host = 'http://' . $api->datacenter . '.list-manage.com';
190 229 ?>
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>
230 + <div class="mc_unsub_link" align="center">
231 + <a href="<?php echo esc_url( $host . '/unsubscribe/?u=' . $user['account_id'] . '&amp;id=' . get_option( 'mc_list_id' ) ); ?>" target="_blank"><?php esc_html_e( 'unsubscribe from list', 'mailchimp' ); ?></a>
193 232 </div><!-- /mc_unsub_link -->
194 233 <?php
195 234 }
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 235 ?>
236 +
205 237 </div><!-- /mc_form_inside -->
206 238 </form><!-- /mc_signup_form -->
207 239 </div><!-- /mc_signup_container -->
208 240 <?php
209 - echo $after_widget;
241 + if ( ! empty( $after_widget ) ) {
242 + echo wp_kses_post( $after_widget );
243 + }
244 +
245 + if ( empty( $before_widget ) ) {
246 + echo '</div>';
247 + }
210 248 }
211 249
250 +/**
251 + * Add a hidden honeypot field
252 + *
253 + * @return void
254 + */
255 +function mailchimp_sf_honeypot_field() {
256 + ?>
257 + <div style="display: none; !important">
258 + <label for="mailchimp_sf_alt_email"><?php esc_html_e( 'Alternative Email:', 'mailchimp' ); ?></label>
259 + <input type="text" name="mailchimp_sf_alt_email" autocomplete="off"/>
260 + </div>
261 + <input type="hidden" class="mailchimp_sf_no_js" name="mailchimp_sf_no_js" value="1" />
262 + <?php
263 +}
212 264
213 265 /**
214 - * MailChimp Subscribe Box widget class
266 + * Generate and display markup for Interest Groups
267 + *
268 + * @param array $ig Set of Interest Groups to generate markup for
269 + * @return void
215 270 */
216 -class mailchimpSF_Widget extends WP_Widget {
271 +function mailchimp_interest_group_field( $ig ) {
272 + if ( ! is_array( $ig ) ) {
273 + return;
274 + }
275 + $html = '';
276 + $set_name = 'group[' . $ig['id'] . ']';
277 + switch ( $ig['type'] ) {
278 + case 'checkboxes':
279 + $i = 1;
280 + foreach ( $ig['groups'] as $interest ) {
281 + $interest_name = $interest['name'];
282 + $interest_id = $interest['id'];
283 + $unique_id = wp_unique_id( 'mc_interest_' . $ig['id'] . '_' . $interest_id . '_' );
284 + $html .= '
217 285
218 - function mailchimpSF_Widget() {
219 - $widget_ops = array(
220 - 'description' => __('Displays a MailChimp Subscribe box', 'mailchimp_i18n')
286 + <input type="checkbox" name="' . esc_attr( $set_name . '[' . $interest_id . ']' ) . '" id="' . esc_attr( $unique_id ) . '" class="mc_interest" value="' . esc_attr( $interest_name ) . '" />
287 + <label for="' . esc_attr( $unique_id ) . '" class="mc_interest_label">' . esc_html( $interest_name ) . '</label>
288 + <br/>';
289 + ++$i;
290 + }
291 + break;
292 + case 'radio':
293 + foreach ( $ig['groups'] as $interest ) {
294 + $interest_name = $interest['name'];
295 + $interest_id = $interest['id'];
296 + $unique_id = wp_unique_id( 'mc_interest_' . $ig['id'] . '_' . $interest_id . '_' );
297 + $html .= '
298 + <input type="radio" name="' . esc_attr( $set_name ) . '" id="' . esc_attr( $unique_id ) . '" class="mc_interest" value="' . esc_attr( $interest_id ) . '"/>
299 + <label for="' . esc_attr( $unique_id ) . '" class="mc_interest_label">' . esc_html( $interest_name ) . '</label>
300 + <br/>';
301 + }
302 + break;
303 + case 'dropdown':
304 + $html .= '
305 + <select name="' . esc_attr( $set_name ) . '">
306 + <option value=""></option>';
307 + foreach ( $ig['groups'] as $interest ) {
308 + $interest_name = $interest['name'];
309 + $interest_id = $interest['id'];
310 + $html .= '
311 + <option value="' . esc_attr( $interest_id ) . '">' . esc_html( $interest_name ) . '</option>';
312 + }
313 + $html .= '
314 + </select>';
315 + break;
316 + case 'hidden':
317 + $i = 1;
318 + foreach ( $ig['groups'] as $interest ) {
319 + $interest_name = $interest['name'];
320 + $interest_id = $interest['id'];
321 + $unique_id = wp_unique_id( 'mc_interest_' . $ig['id'] . '_' . $interest_id . '_' );
322 + $html .= '
323 + <input type="checkbox" name="' . esc_attr( $set_name . '[' . $i . ']' ) . '" id="' . esc_attr( $unique_id ) . '" class="mc_interest" value="' . esc_attr( $interest_name ) . '" />
324 + <label for="' . esc_attr( $unique_id ) . '" class="mc_interest_label">' . esc_html( $interest_name ) . '</label>';
325 + ++$i;
326 + }
327 + break;
328 + }
329 + echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignoring because html is previously escaped
330 +}
331 +
332 +/**
333 + * Generate and display markup for form fields
334 + *
335 + * @param array $data Array containing informaoin about the field.
336 + * @param int $num_fields The number of fields total we'll be generating markup for. Used in calculating required text logic.
337 + * @param bool $should_display Whether or not the field should be displayed.
338 + * @param string $label The label for the field.
339 + * @return string
340 + */
341 +function mailchimp_form_field( $data, $num_fields, $should_display = null, $label = '' ) {
342 + $html = '';
343 + $opt = 'mc_mv_' . $data['tag'];
344 + $opt_id = wp_unique_id( $opt . '_' );
345 + if ( is_null( $should_display ) ) {
346 + $should_display = 'on' === get_option( $opt );
347 + }
348 +
349 + $label = ( ! empty( $label ) ) ? $label : $data['name'];
350 +
351 + // See if that var is set as required, or turned on (for display)
352 + if ( $data['required'] || $should_display ) {
353 + $label = '<label for="' . esc_attr( $opt_id ) . '" class="mc_var_label mc_header mc_header_' . esc_attr( $data['type'] ) . '">' . wp_kses_post( $label );
354 + if ( $data['required'] && $num_fields > 1 ) {
355 + $label .= '<span class="mc_required">*</span>';
356 + }
357 + $label .= '</label>';
358 +
359 + $html .= '
360 +<div class="mc_merge_var">
361 + ' . $label;
362 + switch ( $data['type'] ) {
363 + case 'date':
364 + $html .= '
365 + <input type="text" size="18" placeholder="' . esc_attr( $data['default_value'] ) . '" data-format="' . esc_attr( $data['options']['date_format'] ) . '" name="' . esc_attr( $opt ) . '" id="' . esc_attr( $opt_id ) . '" class="date-pick mc_input"/>';
366 + break;
367 + case 'radio':
368 + if ( is_array( $data['options']['choices'] ) ) {
369 + $html .= '
370 + <ul class="mc_list">';
371 + foreach ( $data['options']['choices'] as $key => $value ) {
372 + $html .= '
373 + <li>
374 + <input type="radio" id="' . esc_attr( $opt_id . '_' . $key ) . '" name="' . esc_attr( $opt ) . '" class="mc_radio" value="' . $value . '"' . checked( $data['default_value'], $value, false ) . ' />
375 + <label for="' . esc_attr( $opt_id . '_' . $key ) . '" class="mc_radio_label">' . esc_html( $value ) . '</label>
376 + </li>';
377 + }
378 + $html .= '
379 + </ul>';
380 + }
381 + break;
382 + case 'dropdown':
383 + if ( is_array( $data['options']['choices'] ) ) {
384 + $html .= '
385 + <select id="' . esc_attr( $opt_id ) . '" name="' . esc_attr( $opt ) . '" class="mc_select">';
386 + foreach ( $data['options']['choices'] as $value ) {
387 + $html .= '
388 + <option value="' . esc_attr( $value ) . '"' . selected( $value, $data['default_value'], false ) . '>' . esc_html( $value ) . '</option>';
389 + }
390 + $html .= '
391 + </select>';
392 + }
393 + break;
394 + case 'birthday':
395 + $html .= '
396 + <input type="text" size="18" placeholder="' . esc_attr( $data['default_value'] ) . '" data-format="' . esc_attr( $data['options']['date_format'] ) . '" name="' . esc_attr( $opt ) . '" id="' . esc_attr( $opt_id ) . '" class="birthdate-pick mc_input"/>';
397 + break;
398 + case 'birthday-old':
399 + $days = range( 1, 31 );
400 + $months = array(
401 + esc_html__( 'January', 'mailchimp' ),
402 + esc_html__( 'February', 'mailchimp' ),
403 + esc_html__( 'March', 'mailchimp' ),
404 + esc_html__( 'April', 'mailchimp' ),
405 + esc_html__( 'May', 'mailchimp' ),
406 + esc_html__( 'June', 'mailchimp' ),
407 + esc_html__( 'July', 'mailchimp' ),
408 + esc_html__( 'August', 'mailchimp' ),
409 + esc_html__( 'September', 'mailchimp' ),
410 + esc_html__( 'October', 'mailchimp' ),
411 + esc_html__( 'November', 'mailchimp' ),
412 + esc_html__( 'December', 'mailchimp' ),
413 + );
414 +
415 + $html .= '
416 + <br /><select id="' . esc_attr( $opt_id ) . '" name="' . esc_attr( $opt . '[month]' ) . '" class="mc_select">';
417 + foreach ( $months as $month_key => $month ) {
418 + $html .= '
419 + <option value="' . $month_key . '">' . $month . '</option>';
420 + }
421 + $html .= '
422 + </select>';
423 +
424 + $html .= '
425 + <select id="' . esc_attr( $opt_id ) . '" name="' . esc_attr( $opt . '[day]' ) . '" class="mc_select">';
426 + foreach ( $days as $day ) {
427 + $html .= '
428 + <option value="' . $day . '">' . $day . '</option>';
429 + }
430 + $html .= '
431 + </select>';
432 + break;
433 + case 'address':
434 + $countries = mailchimp_country_list();
435 + $html .= '
436 +
437 + <label for="' . esc_attr( $opt_id . '-addr1' ) . '" class="mc_address_label">' . esc_html__( 'Street Address', 'mailchimp' ) . '</label>
438 + <input type="text" size="18" value="" name="' . esc_attr( $opt . '[addr1]' ) . '" id="' . esc_attr( $opt_id . '-addr1' ) . '" class="mc_input" />
439 + <label for="' . esc_attr( $opt_id . '-addr2' ) . '" class="mc_address_label">' . esc_html__( 'Address Line 2', 'mailchimp' ) . '</label>
440 + <input type="text" size="18" value="" name="' . esc_attr( $opt . '[addr2]' ) . '" id="' . esc_attr( $opt_id . '-addr2' ) . '" class="mc_input" />
441 + <label for="' . esc_attr( $opt_id . '-city' ) . '" class="mc_address_label">' . esc_html__( 'City', 'mailchimp' ) . '</label>
442 + <input type="text" size="18" value="" name="' . esc_attr( $opt . '[city]' ) . '" id="' . esc_attr( $opt_id . '-city' ) . '" class="mc_input" />
443 + <label for="' . esc_attr( $opt_id . '-state' ) . '" class="mc_address_label">' . esc_html__( 'State', 'mailchimp' ) . '</label>
444 + <input type="text" size="18" value="" name="' . esc_attr( $opt . '[state]' ) . '" id="' . esc_attr( $opt_id . '-state' ) . '" class="mc_input" />
445 + <label for="' . esc_attr( $opt_id . '-zip' ) . '" class="mc_address_label">' . esc_html__( 'Zip / Postal', 'mailchimp' ) . '</label>
446 + <input type="text" size="18" value="" maxlength="5" name="' . esc_attr( $opt . '[zip]' ) . '" id="' . esc_attr( $opt_id . '-zip' ) . '" class="mc_input" />
447 + <label for="' . esc_attr( $opt_id . '-country' ) . '" class="mc_address_label">' . esc_html__( 'Country', 'mailchimp' ) . '</label>
448 + <select name="' . esc_attr( $opt . '[country]' ) . '" id="' . esc_attr( $opt_id . '-country' ) . '">';
449 + foreach ( $countries as $country_code => $country_name ) {
450 + $html .= '
451 + <option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $data['options']['default_country'], false ) . '>' . esc_html( $country_name ) . '</option>';
452 + }
453 + $html .= '
454 + </select>';
455 + break;
456 + case 'zip':
457 + $html .= '
458 + <input type="text" size="18" maxlength="5" value="" name="' . esc_attr( $opt ) . '" id="' . esc_attr( $opt_id ) . '" class="mc_input" />';
459 + break;
460 + case 'phone':
461 + $is_us_phone = isset( $data['options']['phone_format'] ) && 'US' === $data['options']['phone_format'];
462 + $html .= '
463 + <input type="tel" size="20" minlength="6" maxlength="20" pattern="^\+?[\d\s\-\(\)\.]*$" value="" name="' . esc_attr( $opt ) . '" id="' . esc_attr( $opt_id ) . '" class="mc_input mailchimp-sf-phone" placeholder="' . esc_attr( $is_us_phone ? '(###) ### - ####' : '' ) . '" />';
464 + break;
465 + case 'email':
466 + case 'url':
467 + case 'imageurl':
468 + case 'text':
469 + case 'number':
470 + default:
471 + $html .= '
472 + <input type="text" size="18" placeholder="' . esc_attr( $data['default_value'] ) . '" name="' . esc_attr( $opt ) . '" id="' . esc_attr( $opt_id ) . '" class="mc_input"/>';
473 + break;
474 + }
475 + if ( ! empty( $data['help_text'] ) ) {
476 + $html .= '<span class="mc_help">' . esc_html( $data['help_text'] ) . '</span>';
477 + }
478 + $html .= '
479 +</div><!-- /mc_merge_var -->';
480 + }
481 +
482 + return $html;
483 +}
484 +
485 +/**
486 + * Mailchimp Subscribe Box widget class
487 + */
488 +class Mailchimp_SF_Widget extends WP_Widget /* phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed */ {
489 +
490 + /**
491 + * Initialize class
492 + */
493 + public function __construct() {
494 + $widget_ops = array(
495 + 'description' => __( 'Displays a Mailchimp Subscribe box', 'mailchimp' ),
221 496 );
222 - $this->WP_Widget('mailchimpSF_widget', __('MailChimp Widget', 'mailchimp_i18n'), $widget_ops);
497 + parent::__construct( 'Mailchimp_SF_Widget', __( 'Mailchimp Widget', 'mailchimp' ), $widget_ops );
223 498 }
224 499
225 - function widget( $args, $instance ) {
226 - mailchimpSF_signup_form(array_merge($args, $instance));
500 + /**
501 + * Echoes the widget content.
502 + *
503 + * @param array $args Display arguments including 'before_title', 'after_title',
504 + * 'before_widget', and 'after_widget'.
505 + * @param array $instance The settings for the particular instance of the widget.
506 + * @return void
507 + */
508 + public function widget( $args, $instance ) {
509 + if ( ! is_array( $instance ) ) {
510 + $instance = array();
511 + }
512 + mailchimp_sf_signup_form( array_merge( $args, $instance ) );
227 513 }
514 +
515 + /**
516 + * Outputs the settings update form.
517 + *
518 + * @param array $instance Current settings.
519 + */
520 + public function form( $instance ) {
521 + ?>
522 +<p>
523 + <?php
524 + echo wp_kses(
525 + sprintf(
526 + /* translators: 1: admin url */
527 + __(
528 + 'Great work! Your widget is ready to go — just head <a href="%1$s">over here</a> if you\'d like to adjust your settings.',
529 + 'mailchimp'
530 + ),
531 + esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) )
532 + ),
533 + [
534 + 'a' => [
535 + 'href' => [],
536 + ],
537 + ]
538 + );
539 + ?>
540 +</p>
541 + <?php
542 + }
228 543 }
229 -?>
544 +
545 +/**
546 + * Return country list
547 + *
548 + * @return array
549 + */
550 +function mailchimp_country_list() {
551 + return array(
552 + '164' => __( 'USA', 'mailchimp' ),
553 + '286' => __( 'Aaland Islands', 'mailchimp' ),
554 + '274' => __( 'Afghanistan', 'mailchimp' ),
555 + '2' => __( 'Albania', 'mailchimp' ),
556 + '3' => __( 'Algeria', 'mailchimp' ),
557 + '178' => __( 'American Samoa', 'mailchimp' ),
558 + '4' => __( 'Andorra', 'mailchimp' ),
559 + '5' => __( 'Angola', 'mailchimp' ),
560 + '176' => __( 'Anguilla', 'mailchimp' ),
561 + '175' => __( 'Antigua And Barbuda', 'mailchimp' ),
562 + '6' => __( 'Argentina', 'mailchimp' ),
563 + '7' => __( 'Armenia', 'mailchimp' ),
564 + '179' => __( 'Aruba', 'mailchimp' ),
565 + '8' => __( 'Australia', 'mailchimp' ),
566 + '9' => __( 'Austria', 'mailchimp' ),
567 + '10' => __( 'Azerbaijan', 'mailchimp' ),
568 + '11' => __( 'Bahamas', 'mailchimp' ),
569 + '12' => __( 'Bahrain', 'mailchimp' ),
570 + '13' => __( 'Bangladesh', 'mailchimp' ),
571 + '14' => __( 'Barbados', 'mailchimp' ),
572 + '15' => __( 'Belarus', 'mailchimp' ),
573 + '16' => __( 'Belgium', 'mailchimp' ),
574 + '17' => __( 'Belize', 'mailchimp' ),
575 + '18' => __( 'Benin', 'mailchimp' ),
576 + '19' => __( 'Bermuda', 'mailchimp' ),
577 + '20' => __( 'Bhutan', 'mailchimp' ),
578 + '21' => __( 'Bolivia', 'mailchimp' ),
579 + '22' => __( 'Bosnia and Herzegovina', 'mailchimp' ),
580 + '23' => __( 'Botswana', 'mailchimp' ),
581 + '24' => __( 'Brazil', 'mailchimp' ),
582 + '180' => __( 'Brunei Darussalam', 'mailchimp' ),
583 + '25' => __( 'Bulgaria', 'mailchimp' ),
584 + '26' => __( 'Burkina Faso', 'mailchimp' ),
585 + '27' => __( 'Burundi', 'mailchimp' ),
586 + '28' => __( 'Cambodia', 'mailchimp' ),
587 + '29' => __( 'Cameroon', 'mailchimp' ),
588 + '30' => __( 'Canada', 'mailchimp' ),
589 + '31' => __( 'Cape Verde', 'mailchimp' ),
590 + '32' => __( 'Cayman Islands', 'mailchimp' ),
591 + '33' => __( 'Central African Republic', 'mailchimp' ),
592 + '34' => __( 'Chad', 'mailchimp' ),
593 + '35' => __( 'Chile', 'mailchimp' ),
594 + '36' => __( 'China', 'mailchimp' ),
595 + '37' => __( 'Colombia', 'mailchimp' ),
596 + '38' => __( 'Congo', 'mailchimp' ),
597 + '183' => __( 'Cook Islands', 'mailchimp' ),
598 + '268' => __( 'Costa Rica', 'mailchimp' ),
599 + '275' => __( 'Cote D\'Ivoire', 'mailchimp' ),
600 + '40' => __( 'Croatia', 'mailchimp' ),
601 + '276' => __( 'Cuba', 'mailchimp' ),
602 + '41' => __( 'Cyprus', 'mailchimp' ),
603 + '42' => __( 'Czech Republic', 'mailchimp' ),
604 + '43' => __( 'Denmark', 'mailchimp' ),
605 + '44' => __( 'Djibouti', 'mailchimp' ),
606 + '289' => __( 'Dominica', 'mailchimp' ),
607 + '187' => __( 'Dominican Republic', 'mailchimp' ),
608 + '233' => __( 'East Timor', 'mailchimp' ),
609 + '45' => __( 'Ecuador', 'mailchimp' ),
610 + '46' => __( 'Egypt', 'mailchimp' ),
611 + '47' => __( 'El Salvador', 'mailchimp' ),
612 + '48' => __( 'Equatorial Guinea', 'mailchimp' ),
613 + '49' => __( 'Eritrea', 'mailchimp' ),
614 + '50' => __( 'Estonia', 'mailchimp' ),
615 + '51' => __( 'Ethiopia', 'mailchimp' ),
616 + '191' => __( 'Faroe Islands', 'mailchimp' ),
617 + '52' => __( 'Fiji', 'mailchimp' ),
618 + '53' => __( 'Finland', 'mailchimp' ),
619 + '54' => __( 'France', 'mailchimp' ),
620 + '277' => __( 'French Polynesia', 'mailchimp' ),
621 + '59' => __( 'Germany', 'mailchimp' ),
622 + '60' => __( 'Ghana', 'mailchimp' ),
623 + '194' => __( 'Gibraltar', 'mailchimp' ),
624 + '61' => __( 'Greece', 'mailchimp' ),
625 + '195' => __( 'Greenland', 'mailchimp' ),
626 + '192' => __( 'Grenada', 'mailchimp' ),
627 + '62' => __( 'Guam', 'mailchimp' ),
628 + '198' => __( 'Guatemala', 'mailchimp' ),
629 + '270' => __( 'Guernsey', 'mailchimp' ),
630 + '65' => __( 'Guyana', 'mailchimp' ),
631 + '200' => __( 'Haiti', 'mailchimp' ),
632 + '66' => __( 'Honduras', 'mailchimp' ),
633 + '67' => __( 'Hong Kong', 'mailchimp' ),
634 + '68' => __( 'Hungary', 'mailchimp' ),
635 + '69' => __( 'Iceland', 'mailchimp' ),
636 + '70' => __( 'India', 'mailchimp' ),
637 + '71' => __( 'Indonesia', 'mailchimp' ),
638 + '278' => __( 'Iran', 'mailchimp' ),
639 + '279' => __( 'Iraq', 'mailchimp' ),
640 + '74' => __( 'Ireland', 'mailchimp' ),
641 + '75' => __( 'Israel', 'mailchimp' ),
642 + '76' => __( 'Italy', 'mailchimp' ),
643 + '202' => __( 'Jamaica', 'mailchimp' ),
644 + '78' => __( 'Japan', 'mailchimp' ),
645 + '288' => __( 'Jersey (Channel Islands)', 'mailchimp' ),
646 + '79' => __( 'Jordan', 'mailchimp' ),
647 + '80' => __( 'Kazakhstan', 'mailchimp' ),
648 + '81' => __( 'Kenya', 'mailchimp' ),
649 + '82' => __( 'Kuwait', 'mailchimp' ),
650 + '83' => __( 'Kyrgyzstan', 'mailchimp' ),
651 + '84' => __( 'Lao People\'s Democratic Republic', 'mailchimp' ),
652 + '85' => __( 'Latvia', 'mailchimp' ),
653 + '86' => __( 'Lebanon', 'mailchimp' ),
654 + '281' => __( 'Libya', 'mailchimp' ),
655 + '90' => __( 'Liechtenstein', 'mailchimp' ),
656 + '91' => __( 'Lithuania', 'mailchimp' ),
657 + '92' => __( 'Luxembourg', 'mailchimp' ),
658 + '208' => __( 'Macau', 'mailchimp' ),
659 + '93' => __( 'Macedonia', 'mailchimp' ),
660 + '94' => __( 'Madagascar', 'mailchimp' ),
661 + '95' => __( 'Malawi', 'mailchimp' ),
662 + '96' => __( 'Malaysia', 'mailchimp' ),
663 + '97' => __( 'Maldives', 'mailchimp' ),
664 + '98' => __( 'Mali', 'mailchimp' ),
665 + '99' => __( 'Malta', 'mailchimp' ),
666 + '212' => __( 'Mauritius', 'mailchimp' ),
667 + '101' => __( 'Mexico', 'mailchimp' ),
668 + '102' => __( 'Moldova, Republic of', 'mailchimp' ),
669 + '103' => __( 'Monaco', 'mailchimp' ),
670 + '104' => __( 'Mongolia', 'mailchimp' ),
671 + '290' => __( 'Montenegro', 'mailchimp' ),
672 + '105' => __( 'Morocco', 'mailchimp' ),
673 + '106' => __( 'Mozambique', 'mailchimp' ),
674 + '242' => __( 'Myanmar', 'mailchimp' ),
675 + '107' => __( 'Namibia', 'mailchimp' ),
676 + '108' => __( 'Nepal', 'mailchimp' ),
677 + '109' => __( 'Netherlands', 'mailchimp' ),
678 + '110' => __( 'Netherlands Antilles', 'mailchimp' ),
679 + '213' => __( 'New Caledonia', 'mailchimp' ),
680 + '111' => __( 'New Zealand', 'mailchimp' ),
681 + '112' => __( 'Nicaragua', 'mailchimp' ),
682 + '113' => __( 'Niger', 'mailchimp' ),
683 + '114' => __( 'Nigeria', 'mailchimp' ),
684 + '272' => __( 'North Korea', 'mailchimp' ),
685 + '116' => __( 'Norway', 'mailchimp' ),
686 + '117' => __( 'Oman', 'mailchimp' ),
687 + '118' => __( 'Pakistan', 'mailchimp' ),
688 + '222' => __( 'Palau', 'mailchimp' ),
689 + '282' => __( 'Palestine', 'mailchimp' ),
690 + '119' => __( 'Panama', 'mailchimp' ),
691 + '219' => __( 'Papua New Guinea', 'mailchimp' ),
692 + '120' => __( 'Paraguay', 'mailchimp' ),
693 + '121' => __( 'Peru', 'mailchimp' ),
694 + '122' => __( 'Philippines', 'mailchimp' ),
695 + '123' => __( 'Poland', 'mailchimp' ),
696 + '124' => __( 'Portugal', 'mailchimp' ),
697 + '126' => __( 'Qatar', 'mailchimp' ),
698 + '58' => __( 'Republic of Georgia', 'mailchimp' ),
699 + '128' => __( 'Romania', 'mailchimp' ),
700 + '129' => __( 'Russia', 'mailchimp' ),
701 + '130' => __( 'Rwanda', 'mailchimp' ),
702 + '205' => __( 'Saint Kitts and Nevis', 'mailchimp' ),
703 + '206' => __( 'Saint Lucia', 'mailchimp' ),
704 + '132' => __( 'Samoa (Independent)', 'mailchimp' ),
705 + '227' => __( 'San Marino', 'mailchimp' ),
706 + '133' => __( 'Saudi Arabia', 'mailchimp' ),
707 + '134' => __( 'Senegal', 'mailchimp' ),
708 + '266' => __( 'Serbia', 'mailchimp' ),
709 + '135' => __( 'Seychelles', 'mailchimp' ),
710 + '137' => __( 'Singapore', 'mailchimp' ),
711 + '138' => __( 'Slovakia', 'mailchimp' ),
712 + '139' => __( 'Slovenia', 'mailchimp' ),
713 + '223' => __( 'Solomon Islands', 'mailchimp' ),
714 + '141' => __( 'South Africa', 'mailchimp' ),
715 + '142' => __( 'South Korea', 'mailchimp' ),
716 + '143' => __( 'Spain', 'mailchimp' ),
717 + '144' => __( 'Sri Lanka', 'mailchimp' ),
718 + '293' => __( 'Sudan', 'mailchimp' ),
719 + '146' => __( 'Suriname', 'mailchimp' ),
720 + '147' => __( 'Swaziland', 'mailchimp' ),
721 + '148' => __( 'Sweden', 'mailchimp' ),
722 + '149' => __( 'Switzerland', 'mailchimp' ),
723 + '152' => __( 'Taiwan', 'mailchimp' ),
724 + '153' => __( 'Tanzania', 'mailchimp' ),
725 + '154' => __( 'Thailand', 'mailchimp' ),
726 + '155' => __( 'Togo', 'mailchimp' ),
727 + '232' => __( 'Tonga', 'mailchimp' ),
728 + '234' => __( 'Trinidad and Tobago', 'mailchimp' ),
729 + '156' => __( 'Tunisia', 'mailchimp' ),
730 + '157' => __( 'Turkey', 'mailchimp' ),
731 + '287' => __( 'Turks &amp; Caicos Islands', 'mailchimp' ),
732 + '159' => __( 'Uganda', 'mailchimp' ),
733 + '161' => __( 'Ukraine', 'mailchimp' ),
734 + '162' => __( 'United Arab Emirates', 'mailchimp' ),
735 + '262' => __( 'United Kingdom', 'mailchimp' ),
736 + '163' => __( 'Uruguay', 'mailchimp' ),
737 + '239' => __( 'Vanuatu', 'mailchimp' ),
738 + '166' => __( 'Vatican City State (Holy See)', 'mailchimp' ),
739 + '167' => __( 'Venezuela', 'mailchimp' ),
740 + '168' => __( 'Vietnam', 'mailchimp' ),
741 + '169' => __( 'Virgin Islands (British)', 'mailchimp' ),
742 + '238' => __( 'Virgin Islands (U.S.)', 'mailchimp' ),
743 + '173' => __( 'Zambia', 'mailchimp' ),
744 + '174' => __( 'Zimbabwe', 'mailchimp' ),
745 + );
746 +}