Skip to content

Commit cae09ce

Browse files
committed
Ensure we use esc_html__ where possible, to be consistent. Ensure all strings are passed through translation
1 parent 55a6dcb commit cae09ce

File tree

3 files changed

+98
-71
lines changed

3 files changed

+98
-71
lines changed

mailchimp.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
/**
6262
* Do the following plugin setup steps here
6363
*
64-
* Internationalization
6564
* Resource (JS & CSS) enqueuing
6665
*
6766
* @return void
@@ -200,8 +199,8 @@ function mailchimp_sf_main_css() {
200199
function mailchimp_sf_add_pages() {
201200
// Add settings page for users who can edit plugins
202201
add_menu_page(
203-
__( 'Mailchimp Setup', 'mailchimp' ),
204-
__( 'Mailchimp', 'mailchimp' ),
202+
esc_html__( 'Mailchimp Setup', 'mailchimp' ),
203+
esc_html__( 'Mailchimp', 'mailchimp' ),
205204
MCSF_CAP_THRESHOLD,
206205
'mailchimp_sf_options',
207206
'mailchimp_sf_setup_page',
@@ -479,8 +478,8 @@ function mailchimp_sf_global_msg( $msg = null ) {
479478
* @return void
480479
*/
481480
function mailchimp_sf_set_form_defaults( $list_name = '' ) {
482-
update_option( 'mc_header_content', __( 'Sign up for', 'mailchimp' ) . ' ' . $list_name );
483-
update_option( 'mc_submit_text', __( 'Subscribe', 'mailchimp' ) );
481+
update_option( 'mc_header_content', esc_html__( 'Sign up for', 'mailchimp' ) . ' ' . $list_name );
482+
update_option( 'mc_submit_text', esc_html__( 'Subscribe', 'mailchimp' ) );
484483

485484
update_option( 'mc_use_datepicker', 'on' );
486485
update_option( 'mc_custom_style', 'off' );
@@ -508,64 +507,64 @@ function mailchimp_sf_save_general_form_settings() {
508507
// IF NOT DEV MODE
509508
if ( isset( $_POST['mc_use_javascript'] ) ) {
510509
update_option( 'mc_use_javascript', 'on' );
511-
$msg = '<p class="success_msg">' . __( 'Fancy Javascript submission turned On!', 'mailchimp' ) . '</p>';
510+
$msg = '<p class="success_msg">' . esc_html__( 'Fancy Javascript submission turned On!', 'mailchimp' ) . '</p>';
512511
mailchimp_sf_global_msg( $msg );
513512
} elseif ( get_option( 'mc_use_javascript' ) !== 'off' ) {
514513
update_option( 'mc_use_javascript', 'off' );
515-
$msg = '<p class="success_msg">' . __( 'Fancy Javascript submission turned Off!', 'mailchimp' ) . '</p>';
514+
$msg = '<p class="success_msg">' . esc_html__( 'Fancy Javascript submission turned Off!', 'mailchimp' ) . '</p>';
516515
mailchimp_sf_global_msg( $msg );
517516
}
518517

519518
if ( isset( $_POST['mc_use_datepicker'] ) ) {
520519
update_option( 'mc_use_datepicker', 'on' );
521-
$msg = '<p class="success_msg">' . __( 'Datepicker turned On!', 'mailchimp' ) . '</p>';
520+
$msg = '<p class="success_msg">' . esc_html__( 'Datepicker turned On!', 'mailchimp' ) . '</p>';
522521
mailchimp_sf_global_msg( $msg );
523522
} elseif ( get_option( 'mc_use_datepicker' ) !== 'off' ) {
524523
update_option( 'mc_use_datepicker', 'off' );
525-
$msg = '<p class="success_msg">' . __( 'Datepicker turned Off!', 'mailchimp' ) . '</p>';
524+
$msg = '<p class="success_msg">' . esc_html__( 'Datepicker turned Off!', 'mailchimp' ) . '</p>';
526525
mailchimp_sf_global_msg( $msg );
527526
}
528527

529528
/*Enable double optin toggle*/
530529
if ( isset( $_POST['mc_double_optin'] ) ) {
531530
update_option( 'mc_double_optin', true );
532-
$msg = '<p class="success_msg">' . __( 'Double opt-in turned On!', 'mailchimp' ) . '</p>';
531+
$msg = '<p class="success_msg">' . esc_html__( 'Double opt-in turned On!', 'mailchimp' ) . '</p>';
533532
mailchimp_sf_global_msg( $msg );
534533
} elseif ( get_option( 'mc_double_optin' ) !== false ) {
535534
update_option( 'mc_double_optin', false );
536-
$msg = '<p class="success_msg">' . __( 'Double opt-in turned Off!', 'mailchimp' ) . '</p>';
535+
$msg = '<p class="success_msg">' . esc_html__( 'Double opt-in turned Off!', 'mailchimp' ) . '</p>';
537536
mailchimp_sf_global_msg( $msg );
538537
}
539538

540539
/* NUKE the CSS! */
541540
if ( isset( $_POST['mc_nuke_all_styles'] ) ) {
542541
update_option( 'mc_nuke_all_styles', true );
543-
$msg = '<p class="success_msg">' . __( 'Mailchimp CSS turned Off!', 'mailchimp' ) . '</p>';
542+
$msg = '<p class="success_msg">' . esc_html__( 'Mailchimp CSS turned Off!', 'mailchimp' ) . '</p>';
544543
mailchimp_sf_global_msg( $msg );
545544
} elseif ( get_option( 'mc_nuke_all_styles' ) !== false ) {
546545
update_option( 'mc_nuke_all_styles', false );
547-
$msg = '<p class="success_msg">' . __( 'Mailchimp CSS turned On!', 'mailchimp' ) . '</p>';
546+
$msg = '<p class="success_msg">' . esc_html__( 'Mailchimp CSS turned On!', 'mailchimp' ) . '</p>';
548547
mailchimp_sf_global_msg( $msg );
549548
}
550549

551550
/* Update existing */
552551
if ( isset( $_POST['mc_update_existing'] ) ) {
553552
update_option( 'mc_update_existing', true );
554-
$msg = '<p class="success_msg">' . __( 'Update existing subscribers turned On!' ) . '</p>';
553+
$msg = '<p class="success_msg">' . esc_html__( 'Update existing subscribers turned On!' ) . '</p>';
555554
mailchimp_sf_global_msg( $msg );
556555
} elseif ( get_option( 'mc_update_existing' ) !== false ) {
557556
update_option( 'mc_update_existing', false );
558-
$msg = '<p class="success_msg">' . __( 'Update existing subscribers turned Off!' ) . '</p>';
557+
$msg = '<p class="success_msg">' . esc_html__( 'Update existing subscribers turned Off!' ) . '</p>';
559558
mailchimp_sf_global_msg( $msg );
560559
}
561560

562561
if ( isset( $_POST['mc_use_unsub_link'] ) ) {
563562
update_option( 'mc_use_unsub_link', 'on' );
564-
$msg = '<p class="success_msg">' . __( 'Unsubscribe link turned On!', 'mailchimp' ) . '</p>';
563+
$msg = '<p class="success_msg">' . esc_html__( 'Unsubscribe link turned On!', 'mailchimp' ) . '</p>';
565564
mailchimp_sf_global_msg( $msg );
566565
} elseif ( get_option( 'mc_use_unsub_link' ) !== 'off' ) {
567566
update_option( 'mc_use_unsub_link', 'off' );
568-
$msg = '<p class="success_msg">' . __( 'Unsubscribe link turned Off!', 'mailchimp' ) . '</p>';
567+
$msg = '<p class="success_msg">' . esc_html__( 'Unsubscribe link turned Off!', 'mailchimp' ) . '</p>';
569568
mailchimp_sf_global_msg( $msg );
570569
}
571570

@@ -623,7 +622,7 @@ function mailchimp_sf_save_general_form_settings() {
623622
}
624623
}
625624

626-
$msg = '<p class="success_msg">' . esc_html( __( 'Successfully Updated your List Subscribe Form Settings!', 'mailchimp' ) ) . '</p>';
625+
$msg = '<p class="success_msg">' . esc_html__( 'Successfully Updated your List Subscribe Form Settings!', 'mailchimp' ) . '</p>';
627626
mailchimp_sf_global_msg( $msg );
628627
}
629628

@@ -682,7 +681,7 @@ function mailchimp_sf_change_list_if_necessary() {
682681
$igs_text = ' ';
683682
if ( is_array( $igs ) ) {
684683
/* translators: %s: count (number) */
685-
$igs_text .= sprintf( __( 'and %s Sets of Interest Groups', 'mailchimp' ), count( $igs ) );
684+
$igs_text .= sprintf( esc_html__( 'and %s Sets of Interest Groups', 'mailchimp' ), count( $igs ) );
686685
}
687686

688687
$msg = '<p class="success_msg">' .
@@ -691,8 +690,9 @@ function mailchimp_sf_change_list_if_necessary() {
691690
__( '<b>Success!</b> Loaded and saved the info for %d Merge Variables', 'mailchimp' ) . $igs_text,
692691
count( $mv )
693692
) . ' ' .
694-
__( 'from your list' ) . ' "' . $list_name . '"<br/><br/>' .
695-
__( 'Now you should either Turn On the Mailchimp Widget or change your options below, then turn it on.', 'mailchimp' ) . '</p>';
693+
esc_html__( 'from your list' ) . ' "' . $list_name . '"<br/><br/>' .
694+
esc_html__( 'Now you should either Turn On the Mailchimp Widget or change your options below, then turn it on.', 'mailchimp' ) . '</p>';
695+
696696
mailchimp_sf_global_msg( $msg );
697697
}
698698
}
@@ -735,7 +735,7 @@ function mailchimp_sf_get_merge_vars( $list_id, $new_list ) {
735735
function mailchimp_sf_add_email_field( $merge ) {
736736
$email = array(
737737
'tag' => 'EMAIL',
738-
'name' => __( 'Email Address', 'mailchimp' ),
738+
'name' => esc_html__( 'Email Address', 'mailchimp' ),
739739
'type' => 'email',
740740
'required' => true,
741741
'public' => true,
@@ -903,7 +903,7 @@ function mailchimp_sf_signup_submit() {
903903
),
904904
[
905905
'a' => [
906-
'href',
906+
'href' => [],
907907
],
908908
]
909909
)
@@ -917,7 +917,7 @@ function mailchimp_sf_signup_submit() {
917917

918918
// If update existing is turned off and the subscriber exists, error out.
919919
if ( get_option( 'mc_update_existing' ) === false && 'subscribed' === $status ) {
920-
$msg = 'This email address is already subscribed to the list.';
920+
$msg = esc_html__( 'This email address is already subscribed to the list.', 'mailchimp' );
921921
$error = new WP_Error( 'mailchimp-update-existing', $msg );
922922
mailchimp_sf_global_msg( '<strong class="mc_error_msg">' . $msg . '</strong>' );
923923
return false;
@@ -934,10 +934,10 @@ function mailchimp_sf_signup_submit() {
934934
}
935935

936936
if ( 'subscribed' === $retval['status'] ) {
937-
$esc = __( 'Success, you\'ve been signed up.', 'mailchimp' );
937+
$esc = esc_html__( 'Success, you\'ve been signed up.', 'mailchimp' );
938938
$msg = "<strong class='mc_success_msg'>{$esc}</strong>";
939939
} else {
940-
$esc = __( 'Success, you\'ve been signed up! Please look for our confirmation email.', 'mailchimp' );
940+
$esc = esc_html__( 'Success, you\'ve been signed up! Please look for our confirmation email.', 'mailchimp' );
941941
$msg = "<strong class='mc_success_msg'>{$esc}</strong>";
942942
}
943943

@@ -1042,7 +1042,7 @@ function mailchimp_sf_merge_submit( $mv ) {
10421042

10431043
if ( 'Y' === $mv_var['required'] && trim( $opt_val ) === '' ) {
10441044
/* translators: %s: field name */
1045-
$message = sprintf( __( 'You must fill in %s.', 'mailchimp' ), esc_html( $mv_var['name'] ) );
1045+
$message = sprintf( esc_html__( 'You must fill in %s.', 'mailchimp' ), esc_html( $mv_var['name'] ) );
10461046
$error = new WP_Error( 'missing_required_field', $message );
10471047
return $error;
10481048
} elseif ( 'EMAIL' !== $tag ) {
@@ -1074,7 +1074,7 @@ function mailchimp_sf_merge_validate_phone( $opt_val, $data ) {
10741074

10751075
if ( ! preg_match( '/[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,4}/A', $opt_val ) ) {
10761076
/* translators: %s: field name */
1077-
$message = sprintf( __( '%s must consist of only numbers', 'mailchimp' ), esc_html( $data['name'] ) );
1077+
$message = sprintf( esc_html__( '%s must consist of only numbers', 'mailchimp' ), esc_html( $data['name'] ) );
10781078
$error = new WP_Error( 'mc_phone_validation', $message );
10791079
return $error;
10801080
}
@@ -1093,7 +1093,7 @@ function mailchimp_sf_merge_validate_address( $opt_val, $data ) {
10931093
if ( 'Y' === $data['required'] ) {
10941094
if ( empty( $opt_val['addr1'] ) || empty( $opt_val['city'] ) ) {
10951095
/* translators: %s: field name */
1096-
$message = sprintf( __( 'You must fill in %s.', 'mailchimp' ), esc_html( $data['name'] ) );
1096+
$message = sprintf( esc_html__( 'You must fill in %s.', 'mailchimp' ), esc_html( $data['name'] ) );
10971097
$error = new WP_Error( 'invalid_address_merge', $message );
10981098
return $error;
10991099
}
@@ -1219,7 +1219,7 @@ function mailchimp_sf_verify_key( $api ) {
12191219
update_option( 'mc_datacenter', $api->datacenter );
12201220

12211221
} else {
1222-
$msg = __( 'API Key must belong to "Owner", "Admin", or "Manager."', 'mailchimp' );
1222+
$msg = esc_html__( 'API Key must belong to "Owner", "Admin", or "Manager."', 'mailchimp' );
12231223
return new WP_Error( 'mc-invalid-role', $msg );
12241224
}
12251225
}

mailchimp_widget.php

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -401,18 +401,18 @@ function mailchimp_form_field( $data, $num_fields ) {
401401
case 'birthday-old':
402402
$days = range( 1, 31 );
403403
$months = array(
404-
__( 'January', 'mailchimp' ),
405-
__( 'February', 'mailchimp' ),
406-
__( 'March', 'mailchimp' ),
407-
__( 'April', 'mailchimp' ),
408-
__( 'May', 'mailchimp' ),
409-
__( 'June', 'mailchimp' ),
410-
__( 'July', 'mailchimp' ),
411-
__( 'August', 'mailchimp' ),
412-
__( 'September', 'mailchimp' ),
413-
__( 'October', 'mailchimp' ),
414-
__( 'November', 'mailchimp' ),
415-
__( 'December', 'mailchimp' ),
404+
esc_html__( 'January', 'mailchimp' ),
405+
esc_html__( 'February', 'mailchimp' ),
406+
esc_html__( 'March', 'mailchimp' ),
407+
esc_html__( 'April', 'mailchimp' ),
408+
esc_html__( 'May', 'mailchimp' ),
409+
esc_html__( 'June', 'mailchimp' ),
410+
esc_html__( 'July', 'mailchimp' ),
411+
esc_html__( 'August', 'mailchimp' ),
412+
esc_html__( 'September', 'mailchimp' ),
413+
esc_html__( 'October', 'mailchimp' ),
414+
esc_html__( 'November', 'mailchimp' ),
415+
esc_html__( 'December', 'mailchimp' ),
416416
);
417417

418418
$html .= '
@@ -437,17 +437,17 @@ function mailchimp_form_field( $data, $num_fields ) {
437437
$countries = mailchimp_country_list();
438438
$html .= '
439439
440-
<label for="' . esc_attr( $opt . '-addr1' ) . '" class="mc_address_label">' . __( 'Street Address', 'mailchimp' ) . '</label>
440+
<label for="' . esc_attr( $opt . '-addr1' ) . '" class="mc_address_label">' . esc_html__( 'Street Address', 'mailchimp' ) . '</label>
441441
<input type="text" size="18" value="" name="' . esc_attr( $opt . '[addr1]' ) . '" id="' . esc_attr( $opt . '-addr1' ) . '" class="mc_input" />
442-
<label for="' . esc_attr( $opt . '-addr2' ) . '" class="mc_address_label">' . __( 'Address Line 2', 'mailchimp' ) . '</label>
442+
<label for="' . esc_attr( $opt . '-addr2' ) . '" class="mc_address_label">' . esc_html__( 'Address Line 2', 'mailchimp' ) . '</label>
443443
<input type="text" size="18" value="" name="' . esc_attr( $opt . '[addr2]' ) . '" id="' . esc_attr( $opt . '-addr2' ) . '" class="mc_input" />
444-
<label for="' . esc_attr( $opt . '-city' ) . '" class="mc_address_label">' . __( 'City', 'mailchimp' ) . '</label>
444+
<label for="' . esc_attr( $opt . '-city' ) . '" class="mc_address_label">' . esc_html__( 'City', 'mailchimp' ) . '</label>
445445
<input type="text" size="18" value="" name="' . esc_attr( $opt . '[city]' ) . '" id="' . esc_attr( $opt . '-city' ) . '" class="mc_input" />
446-
<label for="' . esc_attr( $opt . '-state' ) . '" class="mc_address_label">' . __( 'State', 'mailchimp' ) . '</label>
446+
<label for="' . esc_attr( $opt . '-state' ) . '" class="mc_address_label">' . esc_html__( 'State', 'mailchimp' ) . '</label>
447447
<input type="text" size="18" value="" name="' . esc_attr( $opt . '[state]' ) . '" id="' . esc_attr( $opt . '-state' ) . '" class="mc_input" />
448-
<label for="' . esc_attr( $opt . '-zip' ) . '" class="mc_address_label">' . __( 'Zip / Postal', 'mailchimp' ) . '</label>
448+
<label for="' . esc_attr( $opt . '-zip' ) . '" class="mc_address_label">' . esc_html__( 'Zip / Postal', 'mailchimp' ) . '</label>
449449
<input type="text" size="18" value="" maxlength="5" name="' . esc_attr( $opt . '[zip]' ) . '" id="' . esc_attr( $opt . '-zip' ) . '" class="mc_input" />
450-
<label for="' . esc_attr( $opt . '-country' ) . '" class="mc_address_label">' . __( 'Country', 'mailchimp' ) . '</label>
450+
<label for="' . esc_attr( $opt . '-country' ) . '" class="mc_address_label">' . esc_html__( 'Country', 'mailchimp' ) . '</label>
451451
<select name="' . esc_attr( $opt . '[country]' ) . '" id="' . esc_attr( $opt . '-country' ) . '">';
452452
foreach ( $countries as $country_code => $country_name ) {
453453
$html .= '
@@ -530,7 +530,25 @@ public function widget( $args, $instance ) {
530530
*/
531531
public function form( $instance ) {
532532
?>
533-
<p>Great work! Your widget is ready to go — just head <a href="<?php echo esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) ); ?>">over here</a> if you'd like to adjust your settings.</p>
533+
<p>
534+
<?php
535+
echo wp_kses(
536+
sprintf(
537+
/* translators: 1: admin url */
538+
__(
539+
'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.',
540+
'mailchimp'
541+
),
542+
esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) )
543+
),
544+
[
545+
'a' => [
546+
'href' => [],
547+
],
548+
]
549+
);
550+
?>
551+
</p>
534552
<?php
535553
}
536554
}

0 commit comments

Comments
 (0)