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.
Built from https://develop.svn.wordpress.org/branches/6.5@58066


git-svn-id: http://core.svn.wordpress.org/branches/6.5@57531 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2024-04-30 09:47:06 +00:00
parent 5186adde1b
commit def147d01e
2 changed files with 17 additions and 1 deletions

View File

@ -728,6 +728,10 @@ function load_textdomain( $domain, $mofile, $locale = null ) {
$l10n_unloaded = (array) $l10n_unloaded;
if ( ! is_string( $domain ) ) {
return false;
}
/**
* Filters whether to short-circuit loading .mo file.
*
@ -989,6 +993,10 @@ function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path
/** @var WP_Textdomain_Registry $wp_textdomain_registry */
global $wp_textdomain_registry;
if ( ! is_string( $domain ) ) {
return false;
}
/**
* Filters a plugin's locale.
*
@ -1037,6 +1045,10 @@ function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
/** @var WP_Textdomain_Registry $wp_textdomain_registry */
global $wp_textdomain_registry;
if ( ! is_string( $domain ) ) {
return false;
}
/** This filter is documented in wp-includes/l10n.php */
$locale = apply_filters( 'plugin_locale', determine_locale(), $domain );
@ -1076,6 +1088,10 @@ function load_theme_textdomain( $domain, $path = false ) {
/** @var WP_Textdomain_Registry $wp_textdomain_registry */
global $wp_textdomain_registry;
if ( ! is_string( $domain ) ) {
return false;
}
/**
* Filters a theme's locale.
*

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.5.3-alpha-58058';
$wp_version = '6.5.3-alpha-58066';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.