wp_delete_comment()
Deletes or trashes a comment by the specified ID.
If the trash is disabled, the comment will be permanently deleted, the second parameter ($force_delete) becomes unnecessary.
Uses wp_trash_comment() if the trash is enabled and the second parameter is not true.
Hooks from the function
Returns
true|false. true - on successful deletion and false - failed to delete.
Usage
wp_delete_comment( $comment_id, $force_delete );
- $comment_id(integer) (required)
- ID of the comment to be deleted.
- $force_delete(boolean)
- Force deletion. If you need to delete the comment without sending it to the trash, set to true.
Default: false
Examples
#1 Deleting a comment in WordPress
Delete comment 457 and display the message "comment 457 deleted!" if successful:
$id = 457;
$done = wp_delete_comment( $id, true ); // skip trash
if( $done ){
echo "Comment {$id} deleted!";
} #2 Move the comment to the trash (but not delete it completely)
Put comment 457 in the trash (assuming the trash is enabled):
$id = 457;
$done = wp_delete_comment( $id );
if( $done ){
echo "Comment {$id} placed in cart!";
}
Notes
- Global. wpdb. $wpdb WordPress database abstraction object.
Changelog
| Since 2.0.0 | Introduced. |