From 404c584956b87a7034e79cc91640e3fcc6676647 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Sat, 29 Oct 2016 11:22:50 +0000 Subject: [PATCH] I18N: Don't initialize `WP_Locale_Switcher` in `wp_load_translations_early()`. `wp_load_translations_early()` is used when WordPress isn't fully initialized. Therefore using the `WP_Locale_Switcher` with `get_locale()`/`get_user_locale()` can cause PHP fatal errors. This reverts [38976] and [38977], and instead removes `WP_Locale_Switcher` from `wp_load_translations_early()`. See #29783. Fixes #38535. git-svn-id: https://develop.svn.wordpress.org/trunk@39005 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/l10n.php | 10 -------- src/wp-includes/load.php | 2 -- tests/phpunit/tests/l10n/getLocale.php | 34 -------------------------- 3 files changed, 46 deletions(-) diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php index 2c227bc1da..e8bb37a54b 100644 --- a/src/wp-includes/l10n.php +++ b/src/wp-includes/l10n.php @@ -50,16 +50,6 @@ function get_locale() { $locale = WPLANG; } - // If $wpdb hasn't been initialised yet, we can only return what we have. - if ( ! $wpdb ) { - if ( ! $locale ) { - $locale = 'en_US'; - } - - /** This filter is documented in wp-includes/l10n.php */ - return apply_filters( 'locale', $locale ); - } - // If multisite, check options. if ( is_multisite() ) { // Don't check blog option when installing. diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index 523960f023..940eb660b4 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -917,8 +917,6 @@ function wp_load_translations_early() { } $wp_locale = new WP_Locale(); - $wp_locale_switcher = new WP_Locale_Switcher(); - $wp_locale_switcher->init(); } /** diff --git a/tests/phpunit/tests/l10n/getLocale.php b/tests/phpunit/tests/l10n/getLocale.php index e7dc7255ab..64b9900ab4 100644 --- a/tests/phpunit/tests/l10n/getLocale.php +++ b/tests/phpunit/tests/l10n/getLocale.php @@ -81,40 +81,6 @@ class Tests_L10n_GetLocale extends WP_UnitTestCase { $this->assertSame( 'en_US', $found ); } - public function test_should_fall_back_on_locale_when_wpdb_is_unavailable() { - global $locale, $wpdb; - - $old_locale = $locale; - $old_wpdb = $wpdb; - - $locale = $expected = "Is this a locale? No. No it isn't."; - $wpdb = null; - - $found = get_locale(); - - $locale = $old_locale; - $wpdb = $old_wpdb; - - $this->assertSame( $expected, $found ); - } - - public function test_should_fall_back_on_es_US_when_locale_and_wpdb_are_unavailable() { - global $locale, $wpdb; - - $old_locale = $locale; - $old_wpdb = $wpdb; - - $locale = null; - $wpdb = null; - - $found = get_locale(); - - $locale = $old_locale; - $wpdb = $old_wpdb; - - $this->assertSame( 'en_US', $found ); - } - public function test_should_respect_get_locale_filter() { add_filter( 'locale', array( $this, 'filter_get_locale' ) ); $found = get_locale();