WordPress.org

Make WordPress Core

Changeset 49747


Ignore:
Timestamp:
12/03/2020 09:07:49 PM (12 months ago)
Author:
SergeyBiryukov
Message:

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.
Reviewed by TimothyBlynJacobs, SergeyBiryukov.
Merges [49746] to the 5.6 branch.
Fixes #51918.
See [35811].

Location:
branches/5.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.6

  • branches/5.6/src/wp-admin/includes/class-wp-application-passwords-list-table.php

    r49549 r49747  
    6969            echo '—';
    7070        } else {
    71             echo gmdate( get_option( 'date_format', 'r' ), $item['created'] );
     71            echo date_i18n( __( 'F j, Y' ), $item['created'] );
    7272        }
    7373    }
     
    8484            echo '—';
    8585        } else {
    86             echo gmdate( get_option( 'date_format', 'r' ), $item['last_used'] );
     86            echo date_i18n( __( 'F j, Y' ), $item['last_used'] );
    8787        }
    8888    }
     
    225225                    break;
    226226                case 'created':
    227                     echo "<# print( wp.date.dateI18n( '" . esc_js( get_option( 'date_format' ) ) . "', data.created ) ) #>";
     227                    // JSON encoding automatically doubles backslashes to ensure they don't get lost when printing the inline JS.
     228                    echo '<# print( wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ', data.created ) ) #>';
    228229                    break;
    229230                case 'last_used':
    230                     echo "<# print( data.last_used !== null ? wp.date.dateI18n( '" . esc_js( get_option( 'date_format' ) ) . "', data.last_used ) : '—' ) #>";
     231                    echo '<# print( data.last_used !== null ? wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ", data.last_used ) : '—' ) #>";
    231232                    break;
    232233                case 'last_ip':
Note: See TracChangeset for help on using the changeset viewer.