Skip to content

Conversation

@shawnhooper
Copy link
Contributor

@shawnhooper shawnhooper commented Oct 15, 2025

Resolves #538

Contributed as part of WordCamp Canada 2025 Contributor Day. #WCEH

@shawnhooper shawnhooper marked this pull request as ready for review October 15, 2025 20:35
@shawnhooper shawnhooper requested a review from a team as a code owner October 15, 2025 20:35
@codecov
Copy link

codecov bot commented Oct 15, 2025

Codecov Report

❌ Patch coverage is 97.95918% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Comment_Command.php 97.95% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

$comments = $query->query(
array(
'fields' => 'ids',
'number' => 0, // Get all comments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like it could be very slow on a large site

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I didn't like the looping either, but I wanted it to still trigger the delete_comment and deleted_comment hooks.

Do you have any suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which makes sense I suppose, there is usually a lot attached to these filters. And wp_delete_comment itself does a lot as well, such as moving up children, deleting comment meta, and updating comment count. Plus, only this way can we adhere to the --force flag as well.

So yeah... there might be no way around it. Maybe it would be worth adding a warning to the docblock to indicate this might be slow if there are lots of comments.

We should probably use wp_defer_comment_counting() to defer updating comment counts, otherwise it will be done after every single deletion.

Something like:

$defer_count = wp_defer_comment_counting();

wp_defer_comment_counting( true );

// delete all comments

wp_defer_comment_counting( $defer_count )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swissspidy Ok. I've added in the support for wp_defer_comment_counting. This got a little more complex, since the call to the parent::_delete() function exited WP-CLI after a single delete.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shawnhooper That's amazing, thanks a lot for diving straight in!

I see you're battling with the Behat tests. Tip: If you are expecting an error output in a test, you need to use When I try ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swissspidy Yep, that did it! Thanks, was really banging my head against my desk. Thinking it was STDOUT vs STDERR issues, etc.

@swissspidy swissspidy requested a review from a team October 21, 2025 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an --all flag to wp comment delete

2 participants