Users: Ensure reset password emails are in the receiving user’s locale.

This ensures that reset password emails initiated by an administrator are sent to the user in their preferred locale.

Follow up to [50129,50139-50141,50152].

Props chouby, davidbaumwald, audrasjb, johnbillion.
Fixes #52605. See #34281.

git-svn-id: https://develop.svn.wordpress.org/trunk@50415 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2021-02-23 16:37:01 +00:00
parent 4c046a1bfd
commit 9b160263da

View File

@ -2759,6 +2759,11 @@ function retrieve_password( $user_login = null ) {
$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
}
// Localize password reset message content for user.
$locale = get_user_locale( $user_data );
$switched_locale = switch_to_locale( $locale );
$message = __( 'Someone has requested a password reset for the following account:' ) . "\r\n\r\n";
/* translators: %s: Site name. */
$message .= sprintf( __( 'Site Name: %s' ), $site_name ) . "\r\n\r\n";
@ -2807,6 +2812,10 @@ function retrieve_password( $user_login = null ) {
*/
$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
if ( $switched_locale ) {
restore_previous_locale();
}
if ( $message && ! wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) ) {
$errors->add(
'retrieve_password_email_failure',