WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/23/2016 02:47:44 PM (5 years ago)
Author:
swissspidy
Message:

I18N: Enable unloading of text domains that have been loaded just in time.

[37415] removed the requirement to call load_plugin_textdomain() / load_theme_textdomain(). This caused unload_textdomain() to not work properly anymore in these cases.

With this change, unloaded text domains need to be explicitly loaded manually if you want to use them again.

Props swissspidy, ocean90.
Fixes #37113. See #34114.

File:
1 edited

Legend:

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

    r37517 r37855  
    510510 * @since 1.5.0
    511511 *
    512  * @global array $l10n
     512 * @global array $l10n          An array of all currently loaded text domains.
     513 * @global array $l10n_unloaded An array of all text domains that have been unloaded again.
    513514 *
    514515 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
     
    517518 */
    518519function load_textdomain( $domain, $mofile ) {
    519     global $l10n;
     520    global $l10n, $l10n_unloaded;
     521
     522    $l10n_unloaded = (array) $l10n_unloaded;
    520523
    521524    /**
     
    531534
    532535    if ( true == $plugin_override ) {
     536        unset( $l10n_unloaded[ $domain ] );
     537
    533538        return true;
    534539    }
     
    562567        $mo->merge_with( $l10n[$domain] );
    563568
     569    unset( $l10n_unloaded[ $domain ] );
     570
    564571    $l10n[$domain] = &$mo;
    565572
     
    572579 * @since 3.0.0
    573580 *
    574  * @global array $l10n
     581 * @global array $l10n          An array of all currently loaded text domains.
     582 * @global array $l10n_unloaded An array of all text domains that have been unloaded again.
    575583 *
    576584 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
     
    578586 */
    579587function unload_textdomain( $domain ) {
    580     global $l10n;
     588    global $l10n, $l10n_unloaded;
     589
     590    $l10n_unloaded = (array) $l10n_unloaded;
    581591
    582592    /**
     
    590600    $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain );
    591601
    592     if ( $plugin_override )
     602    if ( $plugin_override ) {
     603        $l10n_unloaded[ $domain ] = true;
     604
    593605        return true;
     606    }
    594607
    595608    /**
     
    604617    if ( isset( $l10n[$domain] ) ) {
    605618        unset( $l10n[$domain] );
     619
     620        $l10n_unloaded[ $domain ] = true;
     621
    606622        return true;
    607623    }
     
    794810 *
    795811 * @see get_translations_for_domain()
     812 * @global array $l10n_unloaded An array of all text domains that have been unloaded again.
    796813 *
    797814 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
     
    799816 */
    800817function _load_textdomain_just_in_time( $domain ) {
     818    global $l10n_unloaded;
     819
     820    $l10n_unloaded = (array) $l10n_unloaded;
     821
    801822    static $cached_mofiles = null;
    802823
    803824    // Short-circuit if domain is 'default' which is reserved for core.
    804     if ( 'default' === $domain ) {
     825    if ( 'default' === $domain || isset( $l10n_unloaded[ $domain ] ) ) {
    805826        return false;
    806827    }
Note: See TracChangeset for help on using the changeset viewer.