Skip to content

Commit bd21a8a

Browse files
committed
I18N: Switch locale to admin locale when sending auto update emails.
If sending an auto update email to the site administrator's email address, look up if a user with the same email exists and switch to that user's locale. If not, explicitly switches to the site locale. This is a follow-up to [59128] where this was previously added for other types of emails. Props benniledl, swissspidy. Fixes #62496. git-svn-id: https://develop.svn.wordpress.org/trunk@59460 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 75c587f commit bd21a8a

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

src/wp-admin/includes/class-wp-automatic-updater.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,14 @@ protected function send_email( $type, $core_update, $result = null ) {
936936
return;
937937
}
938938

939+
$admin_user = get_user_by( 'email', get_site_option( 'admin_email' ) );
940+
941+
if ( $admin_user ) {
942+
$switched_locale = switch_to_user_locale( $admin_user->ID );
943+
} else {
944+
$switched_locale = switch_to_locale( get_locale() );
945+
}
946+
939947
switch ( $type ) {
940948
case 'success': // We updated.
941949
/* translators: Site updated notification email subject. 1: Site title, 2: WordPress version. */
@@ -1139,8 +1147,11 @@ protected function send_email( $type, $core_update, $result = null ) {
11391147
$email = apply_filters( 'auto_core_update_email', $email, $type, $core_update, $result );
11401148

11411149
wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] );
1142-
}
11431150

1151+
if ( $switched_locale ) {
1152+
restore_previous_locale();
1153+
}
1154+
}
11441155

11451156
/**
11461157
* Checks whether an email should be sent after attempting plugin or theme updates.
@@ -1255,6 +1266,14 @@ protected function send_plugin_theme_email( $type, $successful_updates, $failed_
12551266
}
12561267
}
12571268

1269+
$admin_user = get_user_by( 'email', get_site_option( 'admin_email' ) );
1270+
1271+
if ( $admin_user ) {
1272+
$switched_locale = switch_to_user_locale( $admin_user->ID );
1273+
} else {
1274+
$switched_locale = switch_to_locale( get_locale() );
1275+
}
1276+
12581277
$body = array();
12591278
$successful_plugins = ( ! empty( $successful_updates['plugin'] ) );
12601279
$successful_themes = ( ! empty( $successful_updates['theme'] ) );
@@ -1526,6 +1545,10 @@ protected function send_plugin_theme_email( $type, $successful_updates, $failed_
15261545
if ( $result ) {
15271546
update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
15281547
}
1548+
1549+
if ( $switched_locale ) {
1550+
restore_previous_locale();
1551+
}
15291552
}
15301553

15311554
/**
@@ -1534,9 +1557,12 @@ protected function send_plugin_theme_email( $type, $successful_updates, $failed_
15341557
* @since 3.7.0
15351558
*/
15361559
protected function send_debug_email() {
1537-
$update_count = 0;
1538-
foreach ( $this->update_results as $type => $updates ) {
1539-
$update_count += count( $updates );
1560+
$admin_user = get_user_by( 'email', get_site_option( 'admin_email' ) );
1561+
1562+
if ( $admin_user ) {
1563+
$switched_locale = switch_to_user_locale( $admin_user->ID );
1564+
} else {
1565+
$switched_locale = switch_to_locale( get_locale() );
15401566
}
15411567

15421568
$body = array();
@@ -1715,6 +1741,10 @@ protected function send_debug_email() {
17151741
$email = apply_filters( 'automatic_updates_debug_email', $email, $failures, $this->update_results );
17161742

17171743
wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] );
1744+
1745+
if ( $switched_locale ) {
1746+
restore_previous_locale();
1747+
}
17181748
}
17191749

17201750
/**

0 commit comments

Comments
 (0)