Skip to content

Commit 3861381

Browse files
committed
Switch back to default locale.
1 parent cce75d6 commit 3861381

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

gravity-forms/gw-format-date-merge-tags.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public function init() {
3434
}
3535

3636
public function replace_merge_tags( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
37-
$locale = $this->_args['locale'];
37+
$current_locale = determine_locale();
38+
$locale = $this->_args['locale'];
39+
if ( $locale ) {
40+
switch_to_locale( $locale );
41+
}
3842

3943
preg_match_all( '/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi', $text, $matches, PREG_SET_ORDER );
4044

@@ -71,16 +75,17 @@ public function replace_merge_tags( $text, $form, $entry, $url_encode, $esc_html
7175

7276
$timestamp = strtotime( sprintf( '%d-%d-%d', $parsed_date['year'], $parsed_date['month'], $parsed_date['day'] ) );
7377

74-
if ( $locale ) {
75-
switch_to_locale( $locale );
76-
}
77-
7878
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
7979
$replace = wp_date( $modifier, $timestamp );
8080

8181
$text = str_replace( $match[0], $replace, $text );
8282
}
8383

84+
// Switch back to default locale.
85+
if ( $locale ) {
86+
switch_to_locale( $current_locale );
87+
}
88+
8489
return $text;
8590
}
8691

0 commit comments

Comments
 (0)