diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php index 038b9160499ce..f9fc550342264 100644 --- a/src/wp-includes/l10n.php +++ b/src/wp-includes/l10n.php @@ -111,6 +111,25 @@ function get_user_locale( $user = 0 ) { return $locale ? $locale : get_locale(); } +/** + * Retrieves the locale of a user that is associated with the admin_email. + * + * If there is no user associated with the admin_email, defaults to the site_language + * + * @since 6.7.0 + * + * @return string The locale of the admin. + */ +function get_admin_locale() { + $admin_email = get_option( 'admin_email' ); + $admin_user = get_user_by( 'email', $admin_email ); + if ( $admin_user ) { + $locale = get_user_locale( $admin_user ); + } + + return $locale ? $locale : get_locale(); +} + /** * Determines the current locale desired for the request. * diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 5ed63e539cf66..390afa1b6bc3f 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -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() ); + /* translators: %s: User name. */ $message = sprintf( __( 'Password changed for user: %s' ), $user->user_login ) . "\r\n"; /* @@ -2103,6 +2106,10 @@ function wp_password_change_notification( $user ) { $wp_password_change_notification_email['message'], $wp_password_change_notification_email['headers'] ); + + if ( $switched_locale ) { + restore_previous_locale(); + } } } endif; @@ -2152,7 +2159,8 @@ function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) $send_notification_to_admin = apply_filters( 'wp_send_new_user_notification_to_admin', true, $user ); if ( 'user' !== $notify && true === $send_notification_to_admin ) { - $switched_locale = switch_to_locale( get_locale() ); + + $switched_locale = switch_to_locale( get_admin_locale() ); /* translators: %s: Site title. */ $message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";