Make WordPress Core


Ignore:
Timestamp:
10/27/2016 03:42:09 AM (9 years ago)
Author:
pento
Message:

I18N: Fix a PHP fatal when get_locale() is called before $wpdb is ready.

If WPDB needs to bail early, it loads the translations, which need to load the locale. Without WPDB, we can't get any database options, so can only rely on what's been loaded so far.

Fixes #29783.

File:
1 edited

Legend:

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

    r38961 r38976  
    2929 */
    3030function get_locale() {
    31     global $locale, $wp_local_package;
     31    global $locale, $wp_local_package, $wpdb;
    3232
    3333    if ( isset( $locale ) ) {
     
    4949    if ( defined( 'WPLANG' ) ) {
    5050        $locale = WPLANG;
     51    }
     52
     53    // If $wpdb hasn't been initialised yet, we can only return what we have.
     54    if ( ! $wpdb ) {
     55        if ( ! $locale ) {
     56            return 'en_US';
     57        }
     58
     59        return $locale;
    5160    }
    5261
Note: See TracChangeset for help on using the changeset viewer.