From 692c6498e948785e0364f0fb5ca2443c9c70a201 Mon Sep 17 00:00:00 2001 From: TimothyBlynJacobs Date: Thu, 3 Dec 2020 21:06:08 +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]. Built from https://develop.svn.wordpress.org/trunk@49746 git-svn-id: http://core.svn.wordpress.org/trunk@49469 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-application-passwords-list-table.php | 9 +++++---- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/class-wp-application-passwords-list-table.php b/wp-admin/includes/class-wp-application-passwords-list-table.php index d0ecd0be75..d1c128b50a 100644 --- a/wp-admin/includes/class-wp-application-passwords-list-table.php +++ b/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 || '—' }}"; diff --git a/wp-includes/version.php b/wp-includes/version.php index 7ec9f69aed..25cc1d5783 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7-alpha-49744'; +$wp_version = '5.7-alpha-49746'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.