From f8dd6946fc90c3fcf1bb310ac8b73035acdbbb2f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 15 Feb 2023 23:37:17 +0000 Subject: [PATCH] I18N: Check that `$wp_locale` global is set before calling its methods. This avoids a fatal error if these functions are called in a mu-plugin before `$wp_locale` is set: * `wp_get_list_item_separator()` * `wp_get_word_count_type()` Follow-up to [52929], [52933], [55279], [55295]. Props kraftbj. Fixes #56698. Built from https://develop.svn.wordpress.org/trunk@55351 git-svn-id: http://core.svn.wordpress.org/trunk@54884 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-locale.php | 2 +- wp-includes/l10n.php | 11 +++++++++++ wp-includes/version.php | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/wp-includes/class-wp-locale.php b/wp-includes/class-wp-locale.php index 38b1860b89..140b93b482 100644 --- a/wp-includes/class-wp-locale.php +++ b/wp-includes/class-wp-locale.php @@ -235,7 +235,7 @@ class WP_Locale { $this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point; - /* translators: used between list items, there is a space after the comma */ + /* translators: Used between list items, there is a space after the comma. */ $this->list_item_separator = __( ', ' ); // Set text direction. diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 52a51d5147..eb1a2cc5a9 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -1807,6 +1807,12 @@ function translate_settings_using_i18n_schema( $i18n_schema, $settings, $textdom function wp_get_list_item_separator() { global $wp_locale; + if ( ! ( $wp_locale instanceof WP_Locale ) ) { + // Default value of WP_Locale::get_list_item_separator(). + /* translators: Used between list items, there is a space after the comma. */ + return __( ', ' ); + } + return $wp_locale->get_list_item_separator(); } @@ -1823,5 +1829,10 @@ function wp_get_list_item_separator() { function wp_get_word_count_type() { global $wp_locale; + if ( ! ( $wp_locale instanceof WP_Locale ) ) { + // Default value of WP_Locale::get_word_count_type(). + return 'words'; + } + return $wp_locale->get_word_count_type(); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 5a10c2ac4f..dc2942647b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-beta2-55350'; +$wp_version = '6.2-beta2-55351'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.