From f3707b2135084f9eace2a1ea18a5f023fbe74a1f Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 9 Feb 2023 16:33:36 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@55302 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-textdomain-registry.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/class-wp-textdomain-registry.php b/src/wp-includes/class-wp-textdomain-registry.php index e13cd76e62..40fa66309c 100644 --- a/src/wp-includes/class-wp-textdomain-registry.php +++ b/src/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; }