-
Notifications
You must be signed in to change notification settings - Fork 95
feat: add --all flag to comment delete command #546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| $comments = $query->query( | ||
| array( | ||
| 'fields' => 'ids', | ||
| 'number' => 0, // Get all comments |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 )There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ...
There was a problem hiding this comment.
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.
Resolves #538
Contributed as part of WordCamp Canada 2025 Contributor Day. #WCEH