Skip to content

Commit 1ca9223

Browse files
committed
Make the form field show or hide based on the WordPress "Include?" settings instead of the Mailchimp settings.
1 parent ef41f56 commit 1ca9223

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

mailchimp.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,15 @@ function mailchimp_sf_get_merge_vars( $list_id, $new_list ) {
683683
update_option( 'mc_merge_vars', $mv['merge_fields'] );
684684
foreach ( $mv['merge_fields'] as $mv_var ) {
685685
$opt = 'mc_mv_' . $mv_var['tag'];
686-
// turn them all on by default
687686
if ( $new_list ) {
688-
update_option( $opt, 'on' );
687+
$public = isset( $mv_var['public'] ) ? $mv_var['public'] : false;
688+
if ( ! $public ) {
689+
// This is a hidden field, so we don't want to include it.
690+
update_option( $opt, 'off' );
691+
} else {
692+
// We need to set the option to 'on' so that it shows up in the form.
693+
update_option( $opt, 'on' );
694+
}
689695
}
690696
}
691697
return $mv['merge_fields'];

mailchimp_upgrade.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ function mailchimp_version_check() {
2222
mailchimp_update_1_6_0();
2323
}
2424

25+
if ( false === $db_option || version_compare( '1.7.0', $db_option, '>' ) ) {
26+
mailchimp_update_1_7_0();
27+
}
28+
2529
update_option( 'mc_version', MCSF_VER );
2630
}
2731

@@ -36,3 +40,24 @@ function mailchimp_version_check() {
3640
function mailchimp_update_1_6_0() {
3741
delete_option( 'mc_rewards' );
3842
}
43+
44+
/**
45+
* Version 1.7.0 update routine
46+
* - Set "Include?" value to "off" for hidden fields
47+
*
48+
* @return void
49+
*/
50+
function mailchimp_update_1_7_0() {
51+
$form_fields = get_option( 'mc_merge_vars' );
52+
53+
if ( ! empty( $form_fields ) && is_array( $form_fields ) ) {
54+
foreach ( $form_fields as $field ) {
55+
if ( ! $field['required'] && ! $field['public'] ) {
56+
$option = 'mc_mv_' . $field['tag'];
57+
// This is a hidden field, so we don't want to include it.
58+
// We need to set the option to 'off' so that it doesn't show up in the form.
59+
update_option( $option, 'off' );
60+
}
61+
}
62+
}
63+
}

mailchimp_widget.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,7 @@ function mailchimp_sf_signup_form( $args = array() ) {
204204

205205
// Loop over our vars, and output the ones that are set to display
206206
foreach ( $mv as $mv_var ) {
207-
if ( ! $mv_var['public'] ) {
208-
echo '<div style="display:none;">' . mailchimp_form_field( $mv_var, $num_fields ) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignoring because form field is escaped in function
209-
} else {
210-
echo mailchimp_form_field( $mv_var, $num_fields ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignoring because form field is escaped in function
211-
}
207+
echo mailchimp_form_field( $mv_var, $num_fields ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignoring because form field is escaped in function
212208
}
213209

214210
// Show an explanation of the * if there's more than one field

views/setup_page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ function ( $ele ) {
302302
<td><?php echo esc_html( ( 1 === intval( $mv_var['required'] ) ) ? 'Y' : 'N' ); ?></td>
303303
<td>
304304
<?php
305-
if ( ! $mv_var['required'] && $mv_var['public'] ) {
305+
if ( ! $mv_var['required'] ) {
306306
$opt = 'mc_mv_' . $mv_var['tag'];
307307
?>
308308
<label class="screen-reader-text" for="<?php echo esc_attr( $opt ); ?>">

0 commit comments

Comments
 (0)