From b4e84e9075547a8186c1f9413f460a40c57d8a04 Mon Sep 17 00:00:00 2001 From: Dhrupo Date: Fri, 6 Nov 2026 23:25:36 +0600 Subject: [PATCH] Report failure on post term remove when no term was removed --- features/post-term.feature | 21 +++++++++++++++++++++ src/WP_CLI/CommandWithTerms.php | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/features/post-term.feature b/features/post-term.feature index 67993d256..7fcb39612 100644 --- a/features/post-term.feature +++ b/features/post-term.feature @@ -201,6 +201,27 @@ Feature: Manage post term | term_id | name | slug | | 3 | 4 | 4 | + Scenario: Remove a term that is not assigned to the post + Given a WP install + + When I run `wp post term add 1 post_tag apple` + And I run `wp term create post_tag banana` + Then STDOUT should not be empty + + When I try `wp post term remove 1 post_tag banana` + Then STDERR should be: + """ + Error: Failed to remove term. + """ + And STDOUT should be empty + And the return code should be 1 + + When I run `wp post term list 1 post_tag --field=slug` + Then STDOUT should be: + """ + apple + """ + Scenario: Remove all terms from post Given a WP install diff --git a/src/WP_CLI/CommandWithTerms.php b/src/WP_CLI/CommandWithTerms.php index a70347233..07f521638 100644 --- a/src/WP_CLI/CommandWithTerms.php +++ b/src/WP_CLI/CommandWithTerms.php @@ -211,7 +211,7 @@ public function remove( $args, $assoc_args ) { $label = count( $terms ) > 1 ? 'terms' : 'term'; - if ( is_wp_error( $result ) ) { + if ( ! $result || is_wp_error( $result ) ) { WP_CLI::error( "Failed to remove {$label}." ); }