Skip to content

Commit

Permalink
switch locale to admin locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Benni Ledl committed Jun 27, 2024
1 parent dc788c6 commit 12a88d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/wp-includes/l10n.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 9 additions & 1 deletion src/wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
/*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 12a88d1

Please sign in to comment.