Skip to content

Commit 09298a9

Browse files
Merge pull request #5 from 1naveengiri/Fix-multi-uninstall
Fix multi lang uninstall
2 parents 99165fe + 7aac324 commit 09298a9

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

features/core-language.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ Feature: Manage translation files for a WordPress install
145145
Success: Language uninstalled.
146146
"""
147147

148+
When I run `wp core language uninstall en_CA en_NZ`
149+
Then the wp-content/languages/admin-en_CA.po file should not exist
150+
And the wp-content/languages/en_CA.po file should not exist
151+
And STDOUT should be:
152+
"""
153+
Success: Language uninstalled.
154+
Success: Language uninstalled.
155+
"""
156+
148157
When I try `wp core language uninstall en_GB`
149158
Then STDERR should be:
150159
"""

src/WP_CLI/CommandWithTranslation.php

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ protected function get_all_languages() {
399399
/**
400400
* Uninstall a given language.
401401
*
402-
* <language>
402+
* <language>...
403403
* : Language code to uninstall.
404404
*
405405
* ## EXAMPLES
@@ -412,45 +412,49 @@ protected function get_all_languages() {
412412
public function uninstall( $args, $assoc_args ) {
413413
global $wp_filesystem;
414414

415-
list( $language_code ) = $args;
415+
$language_codes = $args;
416416

417417
$available = $this->get_installed_languages();
418418

419-
if ( ! in_array( $language_code, $available ) ) {
420-
\WP_CLI::error( "Language not installed." );
421-
}
419+
foreach ($language_codes as $language_code) {
422420

423-
$dir = 'core' === $this->obj_type ? '' : "/$this->obj_type";
424-
$files = scandir( WP_LANG_DIR . $dir );
425-
if ( ! $files ) {
426-
\WP_CLI::error( "No files found in language directory." );
427-
}
421+
if ( ! in_array( $language_code, $available ) ) {
422+
\WP_CLI::error( "Language not installed." );
423+
}
428424

429-
$current_locale = get_locale();
430-
if ( $language_code === $current_locale ) {
431-
\WP_CLI::warning( "The '{$language_code}' language is active." );
432-
exit;
433-
}
425+
$dir = 'core' === $this->obj_type ? '' : "/$this->obj_type";
426+
$files = scandir( WP_LANG_DIR . $dir );
427+
if ( ! $files ) {
428+
\WP_CLI::error( "No files found in language directory." );
429+
}
434430

435-
// As of WP 4.0, no API for deleting a language pack
436-
WP_Filesystem();
437-
$deleted = false;
438-
foreach ( $files as $file ) {
439-
if ( '.' === $file[0] || is_dir( $file ) ) {
440-
continue;
431+
$current_locale = get_locale();
432+
if ( $language_code === $current_locale ) {
433+
\WP_CLI::warning( "The '{$language_code}' language is active." );
434+
exit;
435+
}
436+
437+
// As of WP 4.0, no API for deleting a language pack
438+
WP_Filesystem();
439+
$deleted = false;
440+
foreach ( $files as $file ) {
441+
if ( '.' === $file[0] || is_dir( $file ) ) {
442+
continue;
443+
}
444+
$extension_length = strlen( $language_code ) + 4;
445+
$ending = substr( $file, -$extension_length );
446+
if ( ! in_array( $file, array( $language_code . '.po', $language_code . '.mo' ) ) && ! in_array( $ending, array( '-' . $language_code . '.po', '-' . $language_code . '.mo' ) ) ) {
447+
continue;
448+
}
449+
$deleted = $wp_filesystem->delete( WP_LANG_DIR . $dir . '/' . $file );
441450
}
442-
$extension_length = strlen( $language_code ) + 4;
443-
$ending = substr( $file, -$extension_length );
444-
if ( ! in_array( $file, array( $language_code . '.po', $language_code . '.mo' ) ) && ! in_array( $ending, array( '-' . $language_code . '.po', '-' . $language_code . '.mo' ) ) ) {
445-
continue;
451+
452+
if ( $deleted ) {
453+
\WP_CLI::success( "Language uninstalled." );
454+
} else {
455+
\WP_CLI::error( "Couldn't uninstall language." );
446456
}
447-
$deleted = $wp_filesystem->delete( WP_LANG_DIR . $dir . '/' . $file );
448-
}
449457

450-
if ( $deleted ) {
451-
\WP_CLI::success( "Language uninstalled." );
452-
} else {
453-
\WP_CLI::error( "Couldn't uninstall language." );
454458
}
455459

456460
}

0 commit comments

Comments
 (0)