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

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy requested a review from a team October 21, 2025 03:16
* : One or more IDs of comments to delete.
*
* [--all]
* : If set, all comments will be deleted.
Copy link
Member

Choose a reason for hiding this comment

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

Should we warn that this might be slow?

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 Just a warning in the comment like this? Or do we need a warning on the prompt?

@mrsdizzie
Copy link
Member

Sorry I'm late to this but in relation to the linked issue this PR is meant to fix -- when there are tens/hundreds of thousands of these it isn't just 'slow' it can be many, many hours. I don't think the current method is really a solution for that particular problem. The correct method for dealing with spam like that is what is in the linked issue, doing:

truncate wp_comments; truncate wp_commentmeta;

Which takes a few seconds at most.

That issue is asking for a wp comment command that would do that in one step.

Obviously that doesn't delete the comments normally, doesn't fire hooks, etc... so it does feel like that is different than an --all flag on the current command which would imply doing the normal wp comment delete on everything (and the PR here is a very reasonable addition).

Really there is just a fundamental difference between "I want to delete all comments the normal WordPress way" and "My site got tens of thousands of spam comments and I want to remove everything". Unclear if it is possible to incorporate the later into this command in a way that makes sense (--truncate-all), but its what the linked issue is asking for.

@shawnhooper
Copy link
Contributor Author

@mrsdizzie Absolutely agreed that this could get very slow. @swissspidy and I had a discussion about that (see #546 (comment)) with my argument being all --all should consistant with the delete command and process all the action hooks.

I propose two possible solutions:

  1. A separate wp comment truncate command
  2. A --skip-hooks flag on the delete command, that if present with --all would execute the truncate commands for speed.

@mrsdizzie
Copy link
Member

I propose two possible solutions:

  1. A separate wp comment truncate command
  2. A --skip-hooks flag on the delete command, that if present with --all would execute the truncate commands for speed.

It needs to be separate from delete, because it will not delete anything in the existing sense. Perhaps wp comment reset or wp comment empty (similar to wp site empty) that would do the following:

truncate wp_comments; truncate wp_commentmeta;
wp comment recount $(wp post list --post_type=page,post --format=ids) // equivalent of this

With an appropriate description of what it does and when you'd want to use that.

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

3 participants