Make WordPress Core

Changeset 39005


Ignore:
Timestamp:
10/29/2016 11:22:50 AM (8 years ago)
Author:
ocean90
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

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

    r38978 r39005  
    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             $locale = 'en_US';
    57         }
    58 
    59         /** This filter is documented in wp-includes/l10n.php */
    60         return apply_filters( 'locale', $locale );
    6151    }
    6252
  • trunk/src/wp-includes/load.php

    r38961 r39005  
    918918
    919919    $wp_locale = new WP_Locale();
    920     $wp_locale_switcher = new WP_Locale_Switcher();
    921     $wp_locale_switcher->init();
    922920}
    923921
  • trunk/tests/phpunit/tests/l10n/getLocale.php

    r38976 r39005  
    8282    }
    8383
    84     public function test_should_fall_back_on_locale_when_wpdb_is_unavailable() {
    85         global $locale, $wpdb;
    86 
    87         $old_locale = $locale;
    88         $old_wpdb = $wpdb;
    89 
    90         $locale = $expected = "Is this a locale? No. No it isn't.";
    91         $wpdb = null;
    92 
    93         $found = get_locale();
    94 
    95         $locale = $old_locale;
    96         $wpdb = $old_wpdb;
    97 
    98         $this->assertSame( $expected, $found );
    99     }
    100 
    101     public function test_should_fall_back_on_es_US_when_locale_and_wpdb_are_unavailable() {
    102         global $locale, $wpdb;
    103 
    104         $old_locale = $locale;
    105         $old_wpdb = $wpdb;
    106 
    107         $locale = null;
    108         $wpdb = null;
    109 
    110         $found = get_locale();
    111 
    112         $locale = $old_locale;
    113         $wpdb = $old_wpdb;
    114 
    115         $this->assertSame( 'en_US', $found );
    116     }
    117 
    11884    public function test_should_respect_get_locale_filter() {
    11985        add_filter( 'locale', array( $this, 'filter_get_locale' ) );
Note: See TracChangeset for help on using the changeset viewer.