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
40 changes: 40 additions & 0 deletions features/theme-delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,46 @@ Feature: Delete WordPress themes
"""
And the return code should be 0

Scenario: Delete an active theme
When I run `wp theme activate p2`
Then STDOUT should not be empty

When I try `wp theme delete p2`
Then STDERR should be:
"""
Warning: Can't delete the currently active theme: p2
Error: No themes deleted.
"""

When I try `wp theme delete p2 --force`
Then STDOUT should contain:
"""
Deleted 'p2' theme.
"""

Scenario: Delete all installed themes
When I run `wp theme list --status=active --field=name --porcelain`
And save STDOUT as {ACTIVE_THEME}

When I try `wp theme delete --all`
Then STDERR should contain:
"""
Warning: Can't delete the currently active theme: {ACTIVE_THEME}
"""

When I run `wp theme delete --all --force`
Then STDOUT should be:
"""
Deleted '{ACTIVE_THEME}' theme.
Success: Deleted 1 of 1 themes.
"""

When I try the previous command again
Then STDOUT should be:
"""
Success: No themes installed.
"""

Scenario: Attempting to delete a theme that doesn't exist
When I run `wp theme delete p2`
Then STDOUT should not be empty
Expand Down
27 changes: 21 additions & 6 deletions src/Theme_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,15 @@ public function is_active( $args, $assoc_args = array() ) {
*
* ## OPTIONS
*
* <theme>...
* [<theme>...]
* : One or more themes to delete.
*
* [--all]
* : If set, all themes will be deleted except active theme.
*
* [--force]
* : To delete active theme use this.
*
* ## EXAMPLES
*
* $ wp theme delete twentytwelve
Expand All @@ -764,12 +770,21 @@ public function is_active( $args, $assoc_args = array() ) {
*
* @alias uninstall
*/
public function delete( $args ) {
public function delete( $args, $assoc_args ) {

$all = Utils\get_flag_value( $assoc_args, 'all', false );

if ( ! ( $args = $this->check_optional_args_and_all( $args, $all, 'delete' ) ) ) {
return;
}

$force = Utils\get_flag_value( $assoc_args, 'force', false );

$successes = $errors = 0;
foreach ( $this->fetcher->get_many( $args ) as $theme ) {
$theme_slug = $theme->get_stylesheet();

if ( $this->is_active_theme( $theme ) ) {
if ( $this->is_active_theme( $theme ) && ! $force ) {
WP_CLI::warning( "Can't delete the currently active theme: $theme_slug" );
$errors++;
continue;
Expand Down Expand Up @@ -870,18 +885,18 @@ private function check_optional_args_and_all( $args, $all ) {

return $args;
}

/**
* Gets the template path based on installation type.
*/
private static function get_template_path( $template ) {
$command_root = Utils\phar_safe_path( dirname( __DIR__ ) );
$template_path = "{$command_root}/templates/{$template}";

if ( ! file_exists( $template_path ) ) {
WP_CLI::error( "Couldn't find {$template}" );
}

return $template_path;
}
}