Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 4 weeks ago

#52605 closed defect (bug) (fixed)

Reset password email sent in wrong language

Reported by: Chouby Owned by: desrosj
Priority: normal Milestone: 5.7
Component: Users Version: 5.7
Severity: normal Keywords: has-patch commit dev-reviewed has-unit-tests
Cc: Focuses:

Description

Testing the new WP 5.7 feature allowing admin to send a reset password link to users. ​https://make.wordpress.org/core/2021/02/22/send-reset-password-links-in-wordpress-5-7/ in 5.7-beta3-50398.

On a fresh WordPress site,

  1. Select Spanish as website language.
  2. Assign French as language for the administrator.
  3. Create a subscriber and select German for his/her language.
  4. As admin, click on "Send password reset" (not yet translated) for the German subscriber in the users list.

The email is sent in French (the language of the administrator).
I expect it to be sent in German.

If I assign the default site language to the German user, the email is still sent in French. I expect it to be sent in Spanish.

Attachments (2)

52605.diff​ (1.1 KB ) - added by davidbaumwald 6 years ago.
Quick first pass
52605.2.diff​ (1004 bytes ) - added by Chouby 6 years ago.

Download all attachments as: .zip

Change History (17)

#1 @johnbillion
6 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone Awaiting Review → 5.7

Moving to 5.7 to see if we can get a switch_to_locale() in there in time.

@davidbaumwald
6 years ago

Quick first pass

#2 @audrasjb
6 years ago

  • Keywords has-patch added; needs-patch removed

Thanks @davidbaumwald, I tested your patch and it looks good to me.

Testing instructions I followed:

  • Set up your website to English
  • Changes its locale to French
  • Set the website back to English
  • Create a new user
  • Set their locale to French
  • Send a password reset link to the user: the email is in English. It should be in French (user's Locale)
  • Apply the patch proposed by @davidbaumwald
  • Send a password reset link to the user: the email is in French, merveilleux 🍷

#4 @desrosj
6 years ago

  • Owner set to desrosj
  • Status new → reviewing

#5 @desrosj
6 years ago

  • Resolution → fixed
  • Status reviewing → closed

In 50415:

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.

#6 @Chouby
6 years ago

  • Resolution fixed
  • Status closed → reopened

May I suggest 52605.2.diff​ as an improvement?

The reason for my proposal to move the switch_to_locale() above the evaluation of the site name is to allow Polylang to translate the site name on the fly when retrieving the blogname option.

#7 @peterwilsoncc
6 years ago

Thanks @Chouby, this makes sense to me and I am sure will prove useful for other plugins for multilingual sites.

#8 @peterwilsoncc
6 years ago

  • Resolution → fixed
  • Status reopened → closed

In 50439:

Users: Use localized site title for password reset emails.

When sending password reset emails, switch to the user's locale prior to obtaining the site title to allow for plugins filtering based on locale.

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

Props chouby.
Fixes #52605. See #34281.

#9 @peterwilsoncc
6 years ago

  • Keywords dev-feedback fixed-major added
  • Resolution fixed
  • Status closed → reopened

Reopening for [50439] to be back-ported to the 5.7 branch after a second committer reviews.

#10 @SergeyBiryukov
6 years ago

  • Keywords commit dev-reviewed added; dev-feedback fixed-major removed

[50439] looks good to backport.

#11 @SergeyBiryukov
6 years ago

  • Resolution → fixed
  • Status reopened → closed

In 50440:

Users: Use localized site title for password reset emails.

When sending password reset emails, switch to the user's locale prior to obtaining the site title to allow for plugins filtering based on locale.

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

Props chouby.
Merges [50439] to the 5.7 branch.
Fixes #52605. See #34281.

This ticket was mentioned in ​Slack in #core by monikarao. ​View the logs.


6 years ago

#13 @apedog
6 years ago

related #49971 - Admin locale setting that is independent of front/site locale and user locale.

#14 @ocean90
5 years ago

In 51077:

Users: Add user’s locale to password reset link to ensure login screen matches the language of the email.

Props walbo.
See #34281, #52605.
Fixes #53321.

This ticket was mentioned in ​PR #14279 on ​WordPress/wordpress-develop by ​@irozum.


4 weeks ago
#15

  • Keywords has-unit-tests added; needs-unit-tests removed

What

  • Adds two tests to Tests_User_RetrievePassword covering the user-locale behaviour of retrieve_password(), follow-up to [50415], [50439] and [51077].
  • This change is test-only and adds no production behaviour.

Cases covered

  • The reset link includes &wp_lang=<user locale> (added in [51077] for #53321).
  • The email content is built while switched to the recipient's locale (get_locale() inside retrieve_password_title returns the user's locale) and the locale is restored afterwards. This is the core of #52605: the email must not use the requesting admin's locale.

Verification

  • Each test was confirmed to fail when the corresponding line in src/wp-includes/user.php is broken (removing switch_to_user_locale(), hardcoding the wp_lang value), then pass again after reverting.

This PR is for code review only and won't be merged on GitHub.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Test implementation and PR description. Reviewed by the author.

Note: See TracTickets for help on using tickets.