Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions features/language-core.feature
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,12 @@ Feature: Manage core translation files for a WordPress install
Given an empty directory
And WP files
And a database
And I run `wp core download --version=<original> --force`
And I try `wp core download --version=<original> --force`
And the return code should be 0
And wp-config.php
And I run `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1`
# The SQLite object cache drop-in might produce a "no such table: wp_options" STDERR during installation.
And I try `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1`
And the return code should be 0

When I run `wp language core list --fields=language,status,update`
Then STDOUT should be a table containing rows:
Expand Down Expand Up @@ -505,9 +508,12 @@ Feature: Manage core translation files for a WordPress install
Given an empty directory
And WP files
And a database
And I run `wp core download --version=<original> --force`
And I try `wp core download --version=<original> --force`
And the return code should be 0
And wp-config.php
And I run `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1`
# The SQLite object cache drop-in might produce a "no such table: wp_options" STDERR during installation.
And I try `wp core install --url='localhost:8001' --title='Test' --admin_user=wpcli --admin_email=admin@example.com --admin_password=1`
And the return code should be 0

When I run `wp language core install en_CA ja`
Then STDERR should be empty
Expand Down
5 changes: 4 additions & 1 deletion src/Core_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,13 @@ public function uninstall( $args ) {
}

/** @var WP_Filesystem_Base $wp_filesystem */
$deleted = $wp_filesystem->delete( WP_LANG_DIR . $dir . '/' . $file );
if ( $wp_filesystem->delete( WP_LANG_DIR . $dir . '/' . $file ) ) {
$deleted = true;
}
}

if ( $deleted ) {
$this->clear_translation_files_cache( WP_LANG_DIR . $dir );
WP_CLI::success( 'Language uninstalled.' );
} else {
WP_CLI::error( "Couldn't uninstall language." );
Expand Down
2 changes: 2 additions & 0 deletions src/Plugin_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,13 @@ public function uninstall( $args, $assoc_args ) {
if ( $count_files_to_remove === $count_files_removed ) {
$result['status'] = 'uninstalled';
++$successes;
$this->clear_translation_files_cache( $dir );
\WP_CLI::log( "Language '{$language_code}' for '{$plugin}' uninstalled." );
} elseif ( $count_files_removed ) {
\WP_CLI::log( "Language '{$language_code}' for '{$plugin}' partially uninstalled." );
$result['status'] = 'partial uninstall';
++$errors;
$this->clear_translation_files_cache( $dir );
} elseif ( $had_one_file ) { /* $count_files_removed == 0 */
\WP_CLI::log( "Couldn't uninstall language '{$language_code}' from plugin {$plugin}." );
$result['status'] = 'failed to uninstall';
Expand Down
2 changes: 2 additions & 0 deletions src/Theme_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,13 @@ public function uninstall( $args, $assoc_args ) {
if ( $count_files_to_remove === $count_files_removed ) {
$result['status'] = 'uninstalled';
++$successes;
$this->clear_translation_files_cache( $dir );
\WP_CLI::log( "Language '{$language_code}' for '{$theme}' uninstalled." );
} elseif ( $count_files_removed ) {
\WP_CLI::log( "Language '{$language_code}' for '{$theme}' partially uninstalled." );
$result['status'] = 'partial uninstall';
++$errors;
$this->clear_translation_files_cache( $dir );
} elseif ( $had_one_file ) { /* $count_files_removed == 0 */
\WP_CLI::log( "Couldn't uninstall language '{$language_code}' from theme {$theme}." );
$result['status'] = 'failed to uninstall';
Expand Down
12 changes: 12 additions & 0 deletions src/WP_CLI/CommandWithTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,16 @@ protected function get_all_languages( $slug = null ) {
protected function get_formatter( &$assoc_args ) {
return new Formatter( $assoc_args, $this->obj_fields, $this->obj_type );
}

/**
* Clears the translation files cache for a given directory.
*
* As of WP 6.5, the presence of .mo and .l10n.php files is cached.
*
* @param string $dir The directory to clear the cache for.
*/
protected function clear_translation_files_cache( $dir ) {
$path = rtrim( $dir, '/' ) . '/';
wp_cache_delete( md5( $path ), 'translation_files' );
}
}