LogoLogo
Simple Comment EditingComment Edit ProDLX PluginsMediaRon
Comment Edit Core
Comment Edit Core
  • Welcome to Comment Edit Core
  • Getting Started
    • Installation
    • Finding the Plugin Settings
    • Configuration
    • Mailchimp Integration
  • Developers
    • Actions
    • Filters
    • Styling
    • JavaScript Hooks and Events
    • JavaScript Integration Example: Displaying a Warning With a Low Timer
    • How to Force Delete Comments
  • Quick Links
    • Get Support
    • Buy Comment Edit Pro
    • Brand Assets
    • MediaRon Home
    • Contact Form
Powered by GitBook
On this page
  • Force Deleting Comments Through Code
  • Force Deleting Spam Comment
  • Force Deleting Edited Comments
  • Force Deletion Without Code
  1. Developers

How to Force Delete Comments

By default, WordPress moves deleted comments to the trash

PreviousJavaScript Integration Example: Displaying a Warning With a Low Timer

Last updated 6 months ago

When you delete a comment, whether from the frontend or admin dashboard, it is moved to the trash.

However, there's a way through code to force delete a comment anytime it's deleted.

Force Deleting Comments Through Code

You'd place the following in a or code snippet.

<?php
/**
 * Maybe delete a comment permanently if admin setting is on.
 *
 * @param int        $comment_id The comment ID.
 * @param WP_Comment $comment    The comment object.
 */
function dlx_maybe_force_delete_comment( $comment, $comment_id ) {
	wp_delete_comment( $comment_id, true );
	return $comment;
}
add_filter( 'trashed_comment', 'dlx_maybe_force_delete_comment', 10, 2 );

Force Deleting Spam Comment

To force delete comments marked as spam, you'd modify the above for the spammed_comment filter.

<?php
/**
 * Maybe delete a comment permanently if admin setting is on.
 *
 * @param int        $comment_id The comment ID.
 * @param WP_Comment $comment    The comment object.
 */
function dlx_maybe_force_delete_comment( $comment, $comment_id ) {
	wp_delete_comment( $comment_id, true );
	return $comment;
}
add_filter( 'trashed_comment', 'dlx_maybe_force_delete_comment', 10, 2 );
add_filter( 'spammed_comment', 'dlx_maybe_force_delete_comment', 10, 2 );

Force Deleting Edited Comments

If comment deletion is enabled in Comment Edit Core, you can force delete a comment by adding the following:

add_filter( 'sce_force_delete', '__return_true' );

Force Deletion Without Code

, a premium plugin that compliments Comment Edit Core, has options for force deletion.

mu-plugin
Comment Edit Pro
LogoComment Management Made Easy with Comment Edit ProDLX Plugins
Visit Comment Edit Pro
Comment Edit Pro Deletion Options