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
This commit is contained in:
TimothyBlynJacobs 2020-12-03 21:06:08 +00:00
parent 4de6175227
commit 692c6498e9
2 changed files with 6 additions and 5 deletions

View File

@ -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 || '—' }}";

View File

@ -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.