From af60a3c2bf0ff435a5de184dac0f9a892b18e572 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 4 Apr 2019 21:23:29 +0000 Subject: [PATCH] Site Health: Ensure the user locale is listed in debug information. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. git-svn-id: https://develop.svn.wordpress.org/trunk@45110 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-debug-data.php | 10 ++++------ src/wp-admin/site-health-info.php | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php index fefd67c9e4..b20776743e 100644 --- a/src/wp-admin/includes/class-wp-debug-data.php +++ b/src/wp-admin/includes/class-wp-debug-data.php @@ -34,10 +34,8 @@ class WP_Debug_Data { global $wpdb; if ( ! empty( $locale ) ) { // Change the language used for translations - if ( function_exists( 'switch_to_locale' ) ) { - $original_locale = get_locale(); - $switched_locale = switch_to_locale( $locale ); - } + $original_locale = get_user_locale(); + $switched_locale = switch_to_locale( $locale ); } $upload_dir = wp_get_upload_dir(); @@ -73,7 +71,7 @@ class WP_Debug_Data { ), 'language' => array( 'label' => __( 'Language' ), - 'value' => ( ! empty( $locale ) ? $original_locale : get_locale() ), + 'value' => ( ! empty( $locale ) ? $original_locale : get_user_locale() ), ), 'home_url' => array( 'label' => __( 'Home URL' ), @@ -888,7 +886,7 @@ class WP_Debug_Data { if ( ! empty( $locale ) ) { // Change the language used for translations - if ( function_exists( 'restore_previous_locale' ) && $switched_locale ) { + if ( $switched_locale ) { restore_previous_locale(); } } diff --git a/src/wp-admin/site-health-info.php b/src/wp-admin/site-health-info.php index abe178f366..ef1af1fc50 100644 --- a/src/wp-admin/site-health-info.php +++ b/src/wp-admin/site-health-info.php @@ -68,7 +68,7 @@ require_once( ABSPATH . 'wp-admin/admin-header.php' ); $info = WP_Debug_Data::debug_data(); $english_info = ''; - if ( 0 !== strpos( get_locale(), 'en' ) ) { + if ( 0 !== strpos( get_user_locale(), 'en' ) ) { $english_info = WP_Debug_Data::debug_data( 'en_US' ); } ?>