From d57711fbe2c0b58742096119e3c84772fe0ecbdf Mon Sep 17 00:00:00 2001 From: scribu Date: Tue, 14 Jan 2014 20:59:16 +0200 Subject: [PATCH] make 'wp term delete' accept multiple args --- features/term.feature | 2 +- php/commands/term.php | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/features/term.feature b/features/term.feature index c2b6e8ef..454455c6 100644 --- a/features/term.feature +++ b/features/term.feature @@ -45,7 +45,7 @@ Feature: Manage WordPress terms "test-delete" """ - When I run `wp term delete {TERM_ID} post_tag` + When I run `wp term delete post_tag {TERM_ID}` Then STDOUT should contain: """ Deleted post_tag {TERM_ID}. diff --git a/php/commands/term.php b/php/commands/term.php index 5bdaeb5a..52a8723d 100644 --- a/php/commands/term.php +++ b/php/commands/term.php @@ -205,28 +205,31 @@ class Term_Command extends WP_CLI_Command { * * ## OPTIONS * - * - * : ID for the term to delete. - * * * : Taxonomy of the term to delete. * + * ... + * : One or more IDs of terms to delete. + * * ## EXAMPLES * - * wp term delete 15 category + * # delete all post tags + * wp term list post_tag --field=ID | xargs wp term delete post_tag */ public function delete( $args ) { + $taxonomy = array_shift( $args ); - list( $term_id, $taxonomy ) = $args; - - $ret = wp_delete_term( $term_id, $taxonomy ); + foreach ( $args as $term_id ) { + $ret = wp_delete_term( $term_id, $taxonomy ); - if ( is_wp_error( $ret ) ) - WP_CLI::error( $ret->get_error_message() ); - else if ( $ret ) - WP_CLI::success( sprintf( "Deleted %s %d.", $taxonomy, $term_id ) ); - else - WP_CLI::error( "Term doesn't exist." ); + if ( is_wp_error( $ret ) ) { + WP_CLI::warning( $ret ); + } else if ( $ret ) { + WP_CLI::success( sprintf( "Deleted %s %d.", $taxonomy, $term_id ) ); + } else { + WP_CLI::warning( sprintf( "%s %d doesn't exist.", $taxonomy, $term_id ) ); + } + } } /** -- 2.11.0