+1 @toscho ‘s comment. This will break nested comment / conversation in comment. You should disable nested comments in the Settings.
Try this code. Note that this is not tested
add_action( 'delete_user', 'my_delete_user');
function my_delete_user($user_id) {
$user = get_user_by('id', $user_id);
// delete comment with that user email
$comments = get_comments('author_email=".$user->user_email);
foreach($comments as $comment) :
wp_delete_comment($comment->$comment_id, true);
endforeach;
// delete comment with that user id
$comments = get_comments("user_id='.$user_id);
foreach($comments as $comment) :
wp_delete_comment($comment->$comment_id, true);
endforeach;
}
Related Posts:
- Allow the comment author to delete their own comments
- Let user delete comment on front end only
- Deleting users do not deletes coments
- delete user not working
- Commenting in user profile page?
- Getting Post Comments for post ID using WP_Query() and a Custom Loop?
- Show content only if member left a comment
- What are the current recommended best-practices for comments.php?
- Post comment as different user than logged in
- Threaded comments – deleting parent comment leads to orphan comments
- Does WordPress Allow Blank/Empty Comment Submissions In WordPress?
- Can I change what fields are displayed in the Comments form?
- Is it possible to move a comment that should be a reply to another comment?
- I have tried using Plugins to remove 72K comments with no success
- Get most active users sort by comment count
- WordPress comments email notification for authors
- List User Comments on User Profile BuddyPress [closed]
- Hold comments for moderation only if user is not logged in
- Display WordPress commenter nice name
- Check if someone recently commented in one of my posts
- Highlighting the current users comment
- Display the number of unseen comments on a page since the user last visit
- Change order of comment fields
- How to auto empty comment trash after X days
- All users/comments suspected as bot? [closed]
- Display Custom comments field number
- Commenting in user profile page?
- if user role is then echo text
- Anonymize comments after one year
- How can I get list of emails of users who commented on a post?
- Best way to tell if a comment is from a user?
- Custom comment field not showing when logged-in
- Adding comments section to website integrated WordPress instance
- get_comment_author_link not working properly
- My posts show 2 comment forms
- Problem in getting user comments permalinks
- Disallowed Tag Present in AMP WordPress ()
- wp list all users who haven’t commented on a post
- Delete comments function
- I want to limit registered user to 1 comment per post in WordPress
- I have tried using Plugins to remove 72K comments with no success
- selectively disable akismet
- How to display comments by logged in user and responses?
- Passing user meta through comment form
- Semi-Private Comments + page comments -> is it possible?
- Would switching to InnoDB from MyISAM improve performance of comments table?
- Using filter to add additional fields to comment_form()
- Comments waiting but no comments found
- Programmatically block commenting by restricting view of comment form
- Disqus over the default commenting engine, what are some pros and cons?
- How To Remove The “Click here to cancel reply” Link From The WordPress Comment Form
- Plugin from WordPress.com for comment notification…available? [closed]
- How to add text to comment form #content textarea?
- Why are my comments closed?
- Block comments from search engine indexing
- Set user loggin status?
- Create a “Reject” action for comments?
- Changing “submitted on date” of comments
- Filter custom comment type from Manage Comments & Dash Widgets
- Add Div to Comment Form
- How to add a strip of visual editor on top of comments textarea
- Threaded comments not working
- Customizing comments pagination for bootstrap
- User’s total comment count excluding comments on their own posts
- How to allow logged in users to post anonymously
- Error While Sending Comment
- comment_reply_link not work with me
- How to allow duplicate comments AND without comment text
- How do I automatically insert some text in the comment textbox on submit?
- I cannot view the comments
- In wp_list_comments comment dates won’t work?
- how to SELECT for the current post id?
- Replying to comments
- Custom comment link
- unsetting required fields in the comment reply form
- Problem code and show comments
- Highlight comments made by registered users of the site
- Simple spam check for valid domain in commenter’s email address
- Allowing WordPress.org/com accounts on a self-hosted install
- How to remove the “comments” bit that appears next to or below the posts
- Post comments don’t show
- Update post “A” on comment submition on post “B”
- Automatically reject a comment if website field contains anything
- Pre- Approved Comment Capability
- Comment form not working
- Comments page id wp_list_comments
- spacebar is not working in input and textarea
- wp-editor-area textarea disapear on cancel-comment-reply-link click
- Conditionally process comments while ignoring replies
- Required Field for Comment parent only?
- Permalink structure as code in back-end?
- User registration add user ID?
- Can I use WP comments for custom tables?
- How to fix vanilla comments extra iframe space
- writing a plugin, how to disable the comment form altogether?
- What filter or action to replace comments or add new comment system
- Function to get a list of all comments on 1 post [closed]
- Auto delete WordPress comments
- Get approved comments or comments that the author is me
- Show/Hide comments