From babba89dd81c7b9944d619b5aa628f33003bd896 Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Thu, 3 Dec 2020 21:04:05 +0000 Subject: [PATCH] App Passwords: Ensure the Created At and Last Used dates are properly translated. The `date_i18n` function is now used when formatting the dates in PHP instead of `gmdate` which doesn't handle localization properly. Additionally, we now use a translation to get the date format to use instead of pulling from the `date_format` option which is only supposed to affect the front-end. Lastly, when passing the date format to the Backbone JS template, we now use `wp_json_encode()` to format the value for JavaScript. This ensures that backslashes are properly preserved which are used by some locales to escape date formatting control characters. Props pedromendonca, TimothyBlynJacobs, ocean90, hellofromtonya, SergeyBiryukov, antpb. Fixes #51918. See [35811]. git-svn-id: https://develop.svn.wordpress.org/trunk@49746 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-application-passwords-list-table.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/class-wp-application-passwords-list-table.php b/src/wp-admin/includes/class-wp-application-passwords-list-table.php index d0ecd0be75..d1c128b50a 100644 --- a/src/wp-admin/includes/class-wp-application-passwords-list-table.php +++ b/src/wp-admin/includes/class-wp-application-passwords-list-table.php @@ -68,7 +68,7 @@ class WP_Application_Passwords_List_Table extends WP_List_Table { if ( empty( $item['created'] ) ) { echo '—'; } else { - echo gmdate( get_option( 'date_format', 'r' ), $item['created'] ); + echo date_i18n( __( 'F j, Y' ), $item['created'] ); } } @@ -83,7 +83,7 @@ class WP_Application_Passwords_List_Table extends WP_List_Table { if ( empty( $item['last_used'] ) ) { echo '—'; } else { - echo gmdate( get_option( 'date_format', 'r' ), $item['last_used'] ); + echo date_i18n( __( 'F j, Y' ), $item['last_used'] ); } } @@ -224,10 +224,11 @@ class WP_Application_Passwords_List_Table extends WP_List_Table { echo '{{ data.name }}'; break; case 'created': - echo "<# print( wp.date.dateI18n( '" . esc_js( get_option( 'date_format' ) ) . "', data.created ) ) #>"; + // JSON encoding automatically doubles backslashes to ensure they don't get lost when printing the inline JS. + echo '<# print( wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ', data.created ) ) #>'; break; case 'last_used': - echo "<# print( data.last_used !== null ? wp.date.dateI18n( '" . esc_js( get_option( 'date_format' ) ) . "', data.last_used ) : '—' ) #>"; + echo '<# print( data.last_used !== null ? wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ", data.last_used ) : '—' ) #>"; break; case 'last_ip': echo "{{ data.last_ip || '—' }}";