Skip to content

Commit 06379c6

Browse files
committed
Clear translation file cache after uninstall
As of WP 6.5, the presence of .mo and .l10n.php files is cached.
1 parent b0c6b6b commit 06379c6

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/Core_Language_Command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ public function uninstall( $args ) {
374374
}
375375

376376
if ( $deleted ) {
377+
$this->clear_translation_files_cache( WP_LANG_DIR . $dir );
377378
WP_CLI::success( 'Language uninstalled.' );
378379
} else {
379380
WP_CLI::error( "Couldn't uninstall language." );

src/Plugin_Language_Command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ public function uninstall( $args, $assoc_args ) {
551551
if ( $count_files_to_remove === $count_files_removed ) {
552552
$result['status'] = 'uninstalled';
553553
++$successes;
554+
$this->clear_translation_files_cache( $dir );
554555
\WP_CLI::log( "Language '{$language_code}' for '{$plugin}' uninstalled." );
555556
} elseif ( $count_files_removed ) {
556557
\WP_CLI::log( "Language '{$language_code}' for '{$plugin}' partially uninstalled." );

src/Theme_Language_Command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ public function uninstall( $args, $assoc_args ) {
570570
if ( $count_files_to_remove === $count_files_removed ) {
571571
$result['status'] = 'uninstalled';
572572
++$successes;
573+
$this->clear_translation_files_cache( $dir );
573574
\WP_CLI::log( "Language '{$language_code}' for '{$theme}' uninstalled." );
574575
} elseif ( $count_files_removed ) {
575576
\WP_CLI::log( "Language '{$language_code}' for '{$theme}' partially uninstalled." );

src/WP_CLI/CommandWithTranslation.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,17 @@ protected function get_all_languages( $slug = null ) {
439439
protected function get_formatter( &$assoc_args ) {
440440
return new Formatter( $assoc_args, $this->obj_fields, $this->obj_type );
441441
}
442+
443+
/**
444+
* Clears the translation files cache for a given directory.
445+
*
446+
* @param string $dir The directory to clear the cache for.
447+
*/
448+
protected function clear_translation_files_cache( $dir ) {
449+
// As of WP 6.5, the presence of .mo and .l10n.php files is cached.
450+
if ( function_exists( 'wp_cache_delete' ) ) {
451+
$path = rtrim( $dir, '/' ) . '/';
452+
wp_cache_delete( md5( $path ), 'translation_files' );
453+
}
454+
}
442455
}

0 commit comments

Comments
 (0)