From cb9f9d81b24cc009b0d81e63a1b0b43a4e8ea30c Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 9 Feb 2023 16:35:22 +0000 Subject: [PATCH] I18N: Prevent fatal error in `WP_Textdomain_Registry`. Use `rtrim` instead of `untrailingslashit` and `trailingslashit` directly. Avoids `formatting.php` dependency and thus prevents an error when called via `wp_load_translations_early()`, which happens e.g. when in maintenance mode. Props grl570810, ocean90. Fixes #57218. Built from https://develop.svn.wordpress.org/trunk@55302 git-svn-id: http://core.svn.wordpress.org/trunk@54835 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-textdomain-registry.php | 13 ++++++++----- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/wp-includes/class-wp-textdomain-registry.php b/wp-includes/class-wp-textdomain-registry.php index e13cd76e62..40fa66309c 100644 --- a/wp-includes/class-wp-textdomain-registry.php +++ b/wp-includes/class-wp-textdomain-registry.php @@ -1,6 +1,9 @@ all[ $domain ][ $locale ] = $path ? trailingslashit( $path ) : false; + $this->all[ $domain ][ $locale ] = $path ? rtrim( $path, '/' ) . '/' : false; $this->current[ $domain ] = $this->all[ $domain ][ $locale ]; } @@ -128,7 +131,7 @@ class WP_Textdomain_Registry { * @param string $path Language directory path. */ public function set_custom_path( $domain, $path ) { - $this->custom_paths[ $domain ] = untrailingslashit( $path ); + $this->custom_paths[ $domain ] = rtrim( $path, '/' ); } /** @@ -187,7 +190,7 @@ class WP_Textdomain_Registry { } if ( $mo_path === $path ) { - $found_location = trailingslashit( $location ); + $found_location = rtrim( $location, '/' ) . '/'; } } } @@ -201,7 +204,7 @@ class WP_Textdomain_Registry { // If no path is found for the given locale and a custom path has been set // using load_plugin_textdomain/load_theme_textdomain, use that one. if ( 'en_US' !== $locale && isset( $this->custom_paths[ $domain ] ) ) { - $fallback_location = trailingslashit( $this->custom_paths[ $domain ] ); + $fallback_location = rtrim( $this->custom_paths[ $domain ], '/' ) . '/'; $this->set( $domain, $locale, $fallback_location ); return $fallback_location; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 14aa06f560..1b82eec41f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-beta1-55301'; +$wp_version = '6.2-beta1-55302'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.