Skip to content

Commit

Permalink
Remove hardcoded fallback string.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Aug 23, 2024
1 parent 435e10c commit da72685
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 46 deletions.
7 changes: 2 additions & 5 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@

// Validate inputs.
const validateFormInput = (input) => {
let inputLabel = 'This field';
let inputLabel = '';
if (
$('label[for="' + input.id + '"] span').length > 0 &&
$('label[for="' + input.id + '"] span').text()
Expand All @@ -200,10 +200,7 @@
inputLabel = inputLabel.split('/')[0];
inputLabel = inputLabel.split('(')[0];
}
const requiredError = (params.required_error || "%s can't be blank.").replace(
'%s',
inputLabel,
);
const requiredError = (params.required_error || '').replace('%s', inputLabel);
const requiredInputs = [
'first_name',
'last_name',
Expand Down
13 changes: 7 additions & 6 deletions includes/admin/templates/create-account-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.05715 8.00005L6.19522 5.13812L7.13803 4.19531L10.9428 8.00005L7.13803 11.8048L6.19522 10.862L9.05715 8.00005Z" fill="#241C15" fill-opacity="0.3"/>
</svg>
</span>
<div class="step-2 <?php echo esc_attr( ( $signup_initiated ) ? 'current' : 'deselected' ); ?>"><?php echo esc_html__( 'Activate account', 'mailchimp' ); ?></div>
<div class="step-2 <?php echo esc_attr( ( $signup_initiated ) ? 'current' : 'deselected' ); ?>"><?php esc_html_e( 'Activate account', 'mailchimp' ); ?></div>
<span class="chevron">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.05715 8.00005L6.19522 5.13812L7.13803 4.19531L10.9428 8.00005L7.13803 11.8048L6.19522 10.862L9.05715 8.00005Z" fill="#241C15" fill-opacity="0.3"/>
</svg>
</span>
<div class="step-3 deselected"><?php echo esc_html__( 'Choose plan', 'mailchimp' ); ?></div>
<div class="step-3 deselected"><?php esc_html_e( 'Choose plan', 'mailchimp' ); ?></div>
</div>
</div>
</div>
Expand Down Expand Up @@ -109,7 +109,7 @@
<div class="box box-half">
<label for="phone_number" class="optional flex justify-between">
<span><?php esc_html_e( 'Phone number', 'mailchimp' ); ?></span>
<span>Optional</span>
<span><?php esc_html_e( 'Optional', 'mailchimp' ); ?></span>
</label>
<input type="text" id="phone_number" name="phone_number" value=""/>
</div>
Expand Down Expand Up @@ -139,7 +139,7 @@
</div>

<div id="mailchimp-sf-business-address" class="mailchimp-sf-create-account-step">
<div class="subtitle"><?php echo esc_html__( 'Business Address', 'mailchimp' ); ?></div>
<div class="subtitle"><?php esc_html_e( 'Business Address', 'mailchimp' ); ?></div>

<div class="mailchimp-sf-form-wrapper">
<fieldset>
Expand Down Expand Up @@ -211,6 +211,7 @@
<div class="mailchimp-select-wrapper">
<select id="timezone" name="timezone" required>
<?php
$selected_timezone = wp_timezone_string();
foreach ( $timezones as $timezone ) {
?>
<option value="<?php echo esc_attr( $timezone['zone'] ); ?>" <?php selected( $timezone['zone'] === $selected_timezone, true ); ?>>
Expand Down Expand Up @@ -261,9 +262,9 @@
</form>

<div class="mailchimp-sf-confirm-email <?php echo esc_attr( ( ! $signup_initiated ) ? 'hidden' : '' ); ?>">
<div class="title"><?php echo esc_html__( 'Check your email', 'mailchimp' ); ?></div>
<div class="title"><?php esc_html_e( 'Check your email', 'mailchimp' ); ?></div>
<p class="h4">
<?php echo esc_html__( 'To start using Mailchimp, activate your account with the link sent to ', 'mailchimp' ); ?><span class="mailchimp-sf-email"><?php echo esc_html( $email ); ?></span>
<?php esc_html_e( 'To start using Mailchimp, activate your account with the link sent to ', 'mailchimp' ); ?><span class="mailchimp-sf-email"><?php echo esc_html( $email ); ?></span>
</p>

<div class="flex items-center gap-x-6">
Expand Down
42 changes: 7 additions & 35 deletions includes/class-mailchimp-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,12 @@ public function enqueue_admin_page_scripts( $hook_suffix ) {
* Add the create account page.
*
* @since x.x.x
*
* @return void
*/
public function add_create_account_page() {
add_submenu_page(
'admin.php',
'Create Mailchimp Account',
'Create Mailchimp Account',
esc_html__( 'Create Mailchimp Account', 'mailchimp' ),
esc_html__( 'Create Mailchimp Account', 'mailchimp' ),
'manage_options',
'mailchimp_sf_create_account',
array( $this, 'create_account_page' )
Expand All @@ -458,9 +456,8 @@ public function add_create_account_page() {
* @return void
*/
public function create_account_page() {
$countries = $this->get_countries();
$timezones = $this->get_timezones();
$selected_timezone = $this->get_current_timezone();
$countries = $this->get_countries();
$timezones = $this->get_timezones();
?>
<div class="wrap" id="mailchimp-sf-create-account">
<hr class="wp-header-end">
Expand All @@ -480,41 +477,16 @@ public function create_account_page() {
*/
private function get_timezones() {
$zones_array = array();
$timestamp = time();
$current = date_default_timezone_get();

foreach ( timezone_identifiers_list() as $key => $zone ) {
date_default_timezone_set( $zone ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
$timezone = new DateTimeZone( $zone );
$diff_string = ( new DateTime( 'now', $timezone ) )->format( 'P' );
$zones_array[ $key ]['zone'] = $zone;
$zones_array[ $key ]['diff_from_GMT'] = 'UTC/GMT ' . date( 'P', $timestamp ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
$zones_array[ $key ]['diff_from_GMT'] = 'UTC/GMT ' . $diff_string;
}

date_default_timezone_set( $current ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set

return $zones_array;
}

/**
* Get the current timezone from WordPress settings.
*
* @return mixed|string|void
*/
private function get_current_timezone() {
// Get timezone data from options.
$timezone_string = get_option( 'timezone_string' );
$offset = get_option( 'gmt_offset' );

$signal = ( $offset <=> 0 ) < 0 ? '-' : '+';
$offset = sprintf( '%1s%02d:%02d', $signal, abs( (int) $offset ), abs( fmod( $offset, 1 ) * 60 ) );

$timezone = $offset;
if ( $timezone_string ) {
$timezone = $timezone_string;
}

return $timezone;
}

/**
* Get a list of countries.
*
Expand Down

0 comments on commit da72685

Please sign in to comment.