Make WordPress Core


Ignore:
Timestamp:
06/23/2023 04:01:08 PM (3 years ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r55990 r56003  
    146146                        $determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] );
    147147                }
    148         } else if (
    149                 ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) ||
    150                 is_admin()
     148        } elseif (
     149                is_admin() ||
     150                ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() )
    151151        ) {
    152152                $determined_locale = get_user_locale();
    153         } else {
     153        }
     154
     155        if ( ! $determined_locale ) {
    154156                $determined_locale = get_locale();
    155157        }
Note: See TracChangeset for help on using the changeset viewer.