Skip to content

Commit 4b1fd3c

Browse files
swissspidyclaude
andcommitted
Include spam and trashed comments in comment delete --all
WP_Comment_Query only returns approved and pending comments by default, so spam and trashed comments were left behind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5pwpi2xQfDA6mUYkkx
1 parent a09db7e commit 4b1fd3c

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎features/comment.feature‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,45 @@ Feature: Manage WordPress comments
551551
0
552552
"""
553553

554+
Scenario: Delete all comments with --all flag includes spam and trashed comments
555+
Given a WP install
556+
And I run `wp comment create --comment_post_ID=1 --comment_content='Spam comment' --comment_approved=spam --porcelain`
557+
And save STDOUT as {SPAM_ID}
558+
And I run `wp comment create --comment_post_ID=1 --comment_content='Trashed comment' --comment_approved=trash --porcelain`
559+
And save STDOUT as {TRASH_ID}
560+
And I run `wp comment create --comment_post_ID=1 --comment_content='Pending comment' --comment_approved=0 --porcelain`
561+
And save STDOUT as {PENDING_ID}
562+
563+
When I run `wp comment delete --all --force`
564+
Then STDOUT should contain:
565+
"""
566+
Success: Deleted comment {SPAM_ID}.
567+
"""
568+
And STDOUT should contain:
569+
"""
570+
Success: Deleted comment {TRASH_ID}.
571+
"""
572+
And STDOUT should contain:
573+
"""
574+
Success: Deleted comment {PENDING_ID}.
575+
"""
576+
And STDOUT should contain:
577+
"""
578+
Success: Deleted 4 comments.
579+
"""
580+
581+
When I run `wp comment list --status=spam --format=count`
582+
Then STDOUT should be:
583+
"""
584+
0
585+
"""
586+
587+
When I run `wp comment list --status=trash --format=count`
588+
Then STDOUT should be:
589+
"""
590+
0
591+
"""
592+
554593
Scenario: Delete all comments when no comments exist
555594
Given a WP install
556595
And I run `wp comment delete $(wp comment list --field=ID) --force`

‎src/Comment_Command.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ private function query_comments_in_chunks( $query_args, $need_url ) {
674674
* Success: Deleted 2 comments.
675675
*/
676676
public function delete( $args, $assoc_args ) {
677-
$all = Utils\get_flag_value( $assoc_args, 'all', false );
677+
$all = (bool) Utils\get_flag_value( $assoc_args, 'all', false );
678678

679679
// Check if comment IDs or --all is passed.
680680
$args = $this->check_optional_args_and_all( $args, $all, 'delete' );
@@ -1047,6 +1047,7 @@ private function get_all_comment_ids(): array {
10471047
array(
10481048
'fields' => 'ids',
10491049
'number' => 0, // Get all comments
1050+
'status' => 'any', // Include spam and trashed comments.
10501051
)
10511052
);
10521053

0 commit comments

Comments
 (0)