I18N: Introduce switch_to_user_locale().

This new function makes it easier to switch to a specific user’s locale by reducing duplicate code and storing the user’s ID as additional context for plugins to consume. Existing usage of `switch_to_locale()` in core has been replaced with `switch_to_user_locale()` where appropriate.

Also, this change ensures `WP_Locale_Switcher` properly filters `determine_locale` so that anyyone using the `determine_locale()` function will get the correct locale information when switching is in effect.

Props costdev.
Fixes #57123.
See #26511.

git-svn-id: https://develop.svn.wordpress.org/trunk@55161 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler
2023-01-30 10:25:53 +00:00
parent 3b4132d6c0
commit bce2a0a534
13 changed files with 215 additions and 72 deletions
+1 -1
View File
@@ -1457,7 +1457,7 @@ function update_option_new_admin_email( $old_value, $value ) {
);
update_option( 'adminhash', $new_admin_email );
$switched_locale = switch_to_locale( get_user_locale() );
$switched_locale = switch_to_user_locale( get_current_user_id() );
/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
$email_text = __(