Make WordPress Core

Changeset 59460


Ignore:
Timestamp:
11/26/2024 10:01:08 AM (3 months ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-automatic-updater.php

    r59159 r59460  
    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.
     
    11401148
    11411149        wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] );
     1150
     1151        if ( $switched_locale ) {
     1152            restore_previous_locale();
     1153        }
    11421154    }
    1143 
    11441155
    11451156    /**
     
    12541265                return;
    12551266            }
     1267        }
     1268
     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() );
    12561275        }
    12571276
     
    15271546            update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
    15281547        }
     1548
     1549        if ( $switched_locale ) {
     1550            restore_previous_locale();
     1551        }
    15291552    }
    15301553
     
    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
     
    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
Note: See TracChangeset for help on using the changeset viewer.