WordPress.org

Make WordPress Core

Changeset 37440


Ignore:
Timestamp:
05/16/2016 03:09:33 PM (4 years ago)
Author:
ocean90
Message:

I18N: In get_translations_for_domain() check if the global $l10n was set by _load_textdomain_just_in_time() before accessing it.

Props danielhuesken.
Fixes #34114.

Location:
trunk
Files:
2 edited

Legend:

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

    r37416 r37440  
    849849function get_translations_for_domain( $domain ) {
    850850    global $l10n;
    851     if ( isset( $l10n[ $domain ] ) || _load_textdomain_just_in_time( $domain ) ) {
     851    if ( isset( $l10n[ $domain ] ) || ( _load_textdomain_just_in_time( $domain ) && isset( $l10n[ $domain ] ) ) ) {
    852852        return $l10n[ $domain ];
    853853    }
  • trunk/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php

    r37415 r37440  
    5959        $is_textdomain_loaded_after  = is_textdomain_loaded( 'internationalized-plugin' );
    6060
     61        unload_textdomain( 'internationalized-plugin' );
    6162        remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
    6263
     
    8081        $is_textdomain_loaded_after  = is_textdomain_loaded( 'internationalized-theme' );
    8182
     83        unload_textdomain( 'internationalized-theme' );
    8284        remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
    8385
     
    8688        $this->assertTrue( $is_textdomain_loaded_after );
    8789    }
     90
     91    /**
     92     * @ticket 341142
     93     */
     94    public function test_get_translations_for_domain_does_not_return_null_if_override_load_textdomain_is_used() {
     95        add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     96        add_filter( 'override_load_textdomain', '__return_true' );
     97        $translations = get_translations_for_domain( 'internationalized-plugin' );
     98        remove_filter( 'override_load_textdomain', '__return_true' );
     99        remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     100
     101        $this->assertTrue( $translations instanceof NOOP_Translations );
     102    }
    88103}
Note: See TracChangeset for help on using the changeset viewer.