Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#40205 closed defect (bug) (fixed)

Interim login modal window uses front end language instead of admin language

Reported by: johnbillion's profile johnbillion Owned by: johnbillion's profile johnbillion
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.7
Component: I18N Keywords: needs-screenshots has-patch needs-testing
Focuses: administration Cc:

Description

When the interim login modal appears (for example your cookies expire or you log out in another tab), the login screen is show in the language of the site instead of the language that the user has selected for the admin area.

It should be possible to, for example, pass a ?lang=<lang> attribute to wp-login.php in order to specify the UI language, and use this attribute in the interim login modal URL to pass through the user's chosen admin language.

Such as URL parameter would also potentially allow for a language switcher to be added to the login screen.

Attachments (5)

Screen Shot 2017-03-19 at 15.08.42.png (407.6 KB) - added by johnbillion 7 years ago.
Example of an Arabic modal login screen showing for a user with English language admin
40205.1.diff (1.4 KB) - added by Nikschavan 7 years ago.
40205.2.diff (1.1 KB) - added by Nikschavan 7 years ago.
40205.3.diff (1.2 KB) - added by Nikschavan 7 years ago.
Improved indentation after 40205.2.diff
40205.4.diff (2.4 KB) - added by Nikschavan 7 years ago.

Download all attachments as: .zip

Change History (14)

@johnbillion
7 years ago

Example of an Arabic modal login screen showing for a user with English language admin

@Nikschavan
7 years ago

#1 @Nikschavan
7 years ago

Checks if the locale is passed through the URL in get_locale() and returns if it's set.

#2 follow-up: @swissspidy
7 years ago

Thanks for the patch, @Nikschavan!

I don't think that logic should be inside get_locale() though. Plus, there probably needs to be more robust sanitization.

We could add this to wp-settings.php directly, however we could also leverage switch_to_locale() inside wp-login.php. Seems cleaner to me this way.

Perhaps we could even add a link to switch the language back to the site's locale if that makes sense.

Any thoughts?

#3 in reply to: ↑ 2 @johnbillion
7 years ago

  • Component changed from Login and Registration to I18N

Replying to swissspidy:

we could also leverage switch_to_locale() inside wp-login.php.

This is the best approach.

@Nikschavan
7 years ago

#4 @Nikschavan
7 years ago

I have updated the patch to use switch_to_locale() inside wp-login.php

For sanitization right now I am just using sanitize_text_field () will this need more sanitization for this?

@Nikschavan
7 years ago

Improved indentation after 40205.2.diff

#5 @swissspidy
7 years ago

  • Keywords has-patch added; needs-patch removed

Thanks for the patch!

A few notes:

  • I think switch_to_locale() should happen before the login_init action fires.
  • Should we add a restore_previous_locale() call for consistency? (only if switch_to_locale() returns true)
  • sanitize_text_field() should be fine. switch_to_locale() bails early when the locale is not invalid.

@Nikschavan
7 years ago

#6 @Nikschavan
7 years ago

Thank you for the feedback @swissspidy

I have updated the patch accordingly.

About restore_previous_locale () I have added them for all the switch/cases.

#7 @swissspidy
7 years ago

  • Keywords needs-testing added

#8 @johnbillion
7 years ago

  • Milestone changed from Future Release to 4.9
  • Owner set to johnbillion
  • Status changed from new to reviewing

#9 @johnbillion
7 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 41692:

I18N: Allow the login screen language to be specified via a wp_lang query variable, and use this for the interim login modal.

This allows users who are using the admin area in a language other than the site language to read the notice on the login screen
(which explains that they need to log in again) in their chosen language.

Props Nikschavan, swissspidy

Fixes #40205

Note: See TracTickets for help on using tickets.