Make WordPress Core


Ignore:
Timestamp:
04/30/2024 09:45:39 AM (5 months ago)
Author:
swissspidy
Message:

I18N: Bail early if an invalid text domain is passed to load_textdomain() et al.

Some plugins pass invalid values such as null instead of a string, which has never been supported by WordPress (no translations are loaded) and was technically undefined behavior. With the introduction of the new l10n library in #59656, which has stricter type hints, this could end up causing warnings or even fatal errors.

This change adds a deliberate short-circuit to load_textdomain() & co. to better handle such a case and document that it is not supported.

Merges [57925] to the 6.5 branch.
Reviewed by jorbin.

Props verygoode, swissspidy.
Fixes #60888.

Location:
branches/6.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.5

  • branches/6.5/src/wp-includes/l10n.php

    r57639 r58066  
    729729    $l10n_unloaded = (array) $l10n_unloaded;
    730730
     731    if ( ! is_string( $domain ) ) {
     732        return false;
     733    }
     734
    731735    /**
    732736     * Filters whether to short-circuit loading .mo file.
     
    990994    global $wp_textdomain_registry;
    991995
     996    if ( ! is_string( $domain ) ) {
     997        return false;
     998    }
     999
    9921000    /**
    9931001     * Filters a plugin's locale.
     
    10381046    global $wp_textdomain_registry;
    10391047
     1048    if ( ! is_string( $domain ) ) {
     1049        return false;
     1050    }
     1051
    10401052    /** This filter is documented in wp-includes/l10n.php */
    10411053    $locale = apply_filters( 'plugin_locale', determine_locale(), $domain );
     
    10761088    /** @var WP_Textdomain_Registry $wp_textdomain_registry */
    10771089    global $wp_textdomain_registry;
     1090
     1091    if ( ! is_string( $domain ) ) {
     1092        return false;
     1093    }
    10781094
    10791095    /**
Note: See TracChangeset for help on using the changeset viewer.