I18N: Do not use trailingslashit in WP_Textdomain_Registry.

This usage of `trailingslashit()`, introduced in [57287], is not only redundant, but also discouraged in order to avoid `formatting.php` dependency (which might not always be loaded).

Props SergeyBiryukov.
See #58919.

git-svn-id: https://develop.svn.wordpress.org/trunk@57290 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2024-01-16 12:10:47 +00:00
parent 8dee781969
commit c3fd114539
2 changed files with 22 additions and 22 deletions

View File

@ -161,7 +161,7 @@ class WP_Textdomain_Registry {
* @return array Array of .mo file paths.
*/
public function get_language_files_from_path( $path ) {
$path = trailingslashit( $path );
$path = rtrim( $path, '/' ) . '/';
/**
* Filters the .mo files retrieved from a specified path before the actual lookup.
@ -237,13 +237,13 @@ class WP_Textdomain_Registry {
foreach ( $translation_types as $type ) {
switch ( $type ) {
case 'plugin':
wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/plugins/' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' );
break;
case 'theme':
wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/themes/' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes' ), 'translations' );
break;
default:
wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR ), 'translations' );
break;
}
}

View File

@ -19,10 +19,10 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
}
public function tear_down() {
wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/foobar/' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/plugins/' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/themes/' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes' ), 'translations' );
wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR ), 'translations' );
parent::tear_down();
}
@ -84,14 +84,14 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
* @covers ::get_language_files_from_path
*/
public function test_get_language_files_from_path_caches_results() {
$this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/foobar/' );
$this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/plugins/' );
$this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/themes/' );
$this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . 'foobar/' );
$this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . 'plugins/' );
$this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . 'themes/' );
$this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/plugins/' ), 'translations' ) );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/themes/' ), 'translations' ) );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/foobar/' ), 'translations' ) );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . 'plugins/' ), 'translations' ) );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . 'themes/' ), 'translations' ) );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . 'foobar/' ), 'translations' ) );
$this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) ), 'translations' ) );
}
@ -100,10 +100,10 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
*/
public function test_get_language_files_from_path_short_circuit() {
add_filter( 'pre_get_language_files_from_path', '__return_empty_array' );
$result = $this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/plugins/' );
$result = $this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins' );
remove_filter( 'pre_get_language_files_from_path', '__return_empty_array' );
$cache = wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/plugins/' ), 'translations' );
$cache = wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . 'plugins' ), 'translations' );
$this->assertEmpty( $result );
$this->assertFalse( $cache );
@ -113,9 +113,9 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
* @covers ::invalidate_mo_files_cache
*/
public function test_invalidate_mo_files_cache() {
$this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/plugins/' );
$this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/themes/' );
$this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) );
$this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins' );
$this->instance->get_language_files_from_path( WP_LANG_DIR . '/themes' );
$this->instance->get_language_files_from_path( WP_LANG_DIR );
$this->instance->invalidate_mo_files_cache(
null,
@ -144,9 +144,9 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
)
);
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/plugins/' ), 'translations' ) );
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/themes/' ), 'translations' ) );
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) ), 'translations' ) );
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' ) );
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes' ), 'translations' ) );
$this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR ), 'translations' ) );
}
public function data_domains_locales() {