From 1c5c130af9846bdfcd67c73c4150465054384084 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Thu, 27 Oct 2016 03:43:49 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@38976 git-svn-id: http://core.svn.wordpress.org/trunk@38919 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/l10n.php | 11 ++++++++++- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index ba856491af..30cacf4a67 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -28,7 +28,7 @@ * @return string The locale of the blog or from the {@see 'locale'} hook. */ function get_locale() { - global $locale, $wp_local_package; + global $locale, $wp_local_package, $wpdb; if ( isset( $locale ) ) { /** @@ -50,6 +50,15 @@ function get_locale() { $locale = WPLANG; } + // If $wpdb hasn't been initialised yet, we can only return what we have. + if ( ! $wpdb ) { + if ( ! $locale ) { + return 'en_US'; + } + + return $locale; + } + // If multisite, check options. if ( is_multisite() ) { // Don't check blog option when installing. diff --git a/wp-includes/version.php b/wp-includes/version.php index 0585b83ec4..e78caf4af9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38975'; +$wp_version = '4.7-alpha-38976'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.