Make WordPress Core

Changeset 55302


Ignore:
Timestamp:
02/09/2023 04:33:36 PM (13 months ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-textdomain-registry.php

    r55010 r55302  
    11<?php
    22/**
    3  * Locale API: WP_Textdomain_Registry class
     3 * Locale API: WP_Textdomain_Registry class.
     4 *
     5 * This file uses rtrim() instead of untrailingslashit() and trailingslashit()
     6 * to avoid formatting.php dependency.
    47 *
    58 * @package WordPress
     
    114117     */
    115118    public function set( $domain, $locale, $path ) {
    116         $this->all[ $domain ][ $locale ] = $path ? trailingslashit( $path ) : false;
     119        $this->all[ $domain ][ $locale ] = $path ? rtrim( $path, '/' ) . '/' : false;
    117120        $this->current[ $domain ]        = $this->all[ $domain ][ $locale ];
    118121    }
     
    129132     */
    130133    public function set_custom_path( $domain, $path ) {
    131         $this->custom_paths[ $domain ] = untrailingslashit( $path );
     134        $this->custom_paths[ $domain ] = rtrim( $path, '/' );
    132135    }
    133136
     
    188191
    189192                if ( $mo_path === $path ) {
    190                     $found_location = trailingslashit( $location );
     193                    $found_location = rtrim( $location, '/' ) . '/';
    191194                }
    192195            }
     
    202205        // using load_plugin_textdomain/load_theme_textdomain, use that one.
    203206        if ( 'en_US' !== $locale && isset( $this->custom_paths[ $domain ] ) ) {
    204             $fallback_location = trailingslashit( $this->custom_paths[ $domain ] );
     207            $fallback_location = rtrim( $this->custom_paths[ $domain ], '/' ) . '/';
    205208            $this->set( $domain, $locale, $fallback_location );
    206209            return $fallback_location;
Note: See TracChangeset for help on using the changeset viewer.