I18N: Ensure `determine_locale()` does not potentially return an empty string.

Call `get_locale()` as a last resort in case the sanitized locale is an empty string.

Also swaps conditionals to cater for more typical use case and adds tests.

Follow-up to [55862]

Props Cybr, swissspidy.
Fixes #58317.
Built from https://develop.svn.wordpress.org/trunk@56003


git-svn-id: http://core.svn.wordpress.org/trunk@55515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2023-06-23 16:03:25 +00:00
parent 6efef07ff8
commit 72fda0359f
2 changed files with 7 additions and 5 deletions

View File

@ -145,12 +145,14 @@ function determine_locale() {
} else { } else {
$determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] ); $determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] );
} }
} else if ( } elseif (
( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) || is_admin() ||
is_admin() ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() )
) { ) {
$determined_locale = get_user_locale(); $determined_locale = get_user_locale();
} else { }
if ( ! $determined_locale ) {
$determined_locale = get_locale(); $determined_locale = get_locale();
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.3-alpha-56002'; $wp_version = '6.3-alpha-56003';
/** /**
* 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.