-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
switch locale to admin locale #6919
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @[email protected]. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
* | ||
* @return string The locale of the admin. | ||
*/ | ||
function get_admin_locale() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this name clashes with https://core.trac.wordpress.org/ticket/49971
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not just the name, but the whole idea is also very similar :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes very similar, but instead of adding a new "Admin language" setting, it's trying to figure out the language by looking for a user.
src/wp-includes/pluggable.php
Outdated
@@ -2063,6 +2063,9 @@ function wp_password_change_notification( $user ) { | |||
* but check to see if it's the admin whose password we're changing, and skip this. | |||
*/ | |||
if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { | |||
|
|||
$switched_locale = switch_to_locale( get_admin_locale() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to leverage switch_to_user_locale
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, just to clarify, will this switch to the language of the user who changed their email? For example, if a user named "Bob" with the role of subscriber and language set to ES changes his password, will the email that is sent to the administrator be sent in ES, regardless of the site locale and admin locale?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that wouldn‘t change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this would become something like this:
$switched_locale = switch_to_locale( get_admin_locale() ); | |
$admin_user = get_user_by( 'email', get_option( 'admin_email' ) ); | |
$switched_locale = $admin_user && switch_to_user_locale( $admin_user ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that change also necessary on line 2165?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, when an Administrator with the locale set to something different than the site locale registers a new user, and the admin_email is not associated with a registered account, it does not fall back to the default site language. Instead, it sends the email in the locale used by the Administrator who registered the new user.
Eg.
ES = standard site locale
DE Administrator registers a new user
- admin_email is not associated with a user -> Expected: send email in ES, Actual: email gets sent in DE
- admin_email is associated with a user -> Expected and Actual: email gets sent in locale that the user associated with the admin_email has set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then use switch_to_user_locale if a user exists and switch_to_locale if it doesn‘t
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Co-authored-by: Mukesh Panchal <[email protected]>
Co-authored-by: Pascal Birchler <[email protected]>
Missing end period. Co-authored-by: Mukesh Panchal <[email protected]>
This patch adds a new funciton called
get_admin_locale
it takes the locale of the user associated with the admin_email and falls back to the site language if there is no user associated with this email address.Also the patch switches to the get_admin_locale function in the admin email notifications instead of get_locale
Trac ticket: https://core.trac.wordpress.org/ticket/61518
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.