From 1c8b25a7a59bf11fdfc9332a3e5739220d383322 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 4 Apr 2024 13:56:13 +0000 Subject: [PATCH] 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. Props verygoode, swissspidy. Fixes #60888. Built from https://develop.svn.wordpress.org/trunk@57925 git-svn-id: http://core.svn.wordpress.org/trunk@57426 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/l10n.php | 16 ++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index b4f1701fe7..3b99ff848b 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 1b68a025e6..701e4cc208 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-57924'; +$wp_version = '6.6-alpha-57925'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.