Site Health: Ensure the user locale is listed in debug information.

This change switches to using `get_user_locale()` when adding the language to the Site Health debug information to ensure the user’s locale preference is reflected.

Also, `function_exists()` checks for `switch_to_locale()` and `restore_previous_locale()` were required in the plugin to support older versions of WordPress, but they are not required in core/

Props: Clorith, desrosj.
Fixes #46694.
Built from https://develop.svn.wordpress.org/trunk@45110


git-svn-id: http://core.svn.wordpress.org/trunk@44919 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
desrosj 2019-04-04 21:24:52 +00:00
parent fc2c675582
commit adbaba7d56
3 changed files with 6 additions and 8 deletions

View File

@ -34,10 +34,8 @@ class WP_Debug_Data {
global $wpdb; global $wpdb;
if ( ! empty( $locale ) ) { if ( ! empty( $locale ) ) {
// Change the language used for translations // Change the language used for translations
if ( function_exists( 'switch_to_locale' ) ) { $original_locale = get_user_locale();
$original_locale = get_locale(); $switched_locale = switch_to_locale( $locale );
$switched_locale = switch_to_locale( $locale );
}
} }
$upload_dir = wp_get_upload_dir(); $upload_dir = wp_get_upload_dir();
@ -73,7 +71,7 @@ class WP_Debug_Data {
), ),
'language' => array( 'language' => array(
'label' => __( 'Language' ), 'label' => __( 'Language' ),
'value' => ( ! empty( $locale ) ? $original_locale : get_locale() ), 'value' => ( ! empty( $locale ) ? $original_locale : get_user_locale() ),
), ),
'home_url' => array( 'home_url' => array(
'label' => __( 'Home URL' ), 'label' => __( 'Home URL' ),
@ -888,7 +886,7 @@ class WP_Debug_Data {
if ( ! empty( $locale ) ) { if ( ! empty( $locale ) ) {
// Change the language used for translations // Change the language used for translations
if ( function_exists( 'restore_previous_locale' ) && $switched_locale ) { if ( $switched_locale ) {
restore_previous_locale(); restore_previous_locale();
} }
} }

View File

@ -68,7 +68,7 @@ require_once( ABSPATH . 'wp-admin/admin-header.php' );
$info = WP_Debug_Data::debug_data(); $info = WP_Debug_Data::debug_data();
$english_info = ''; $english_info = '';
if ( 0 !== strpos( get_locale(), 'en' ) ) { if ( 0 !== strpos( get_user_locale(), 'en' ) ) {
$english_info = WP_Debug_Data::debug_data( 'en_US' ); $english_info = WP_Debug_Data::debug_data( 'en_US' );
} }
?> ?>

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.2-beta1-45109'; $wp_version = '5.2-beta1-45110';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.