wp_delete_comment()
Trashes or deletes a comment.
The comment is moved to Trash instead of permanently deleted unless Trash is disabled, item is already in the Trash, or $force_delete is true.
The post comment count will be updated if the comment was approved and has a post ID available.
Hooks from the function
Return
true|false
. True on success, false on failure.
Usage
wp_delete_comment( $comment_id, $force_delete );
- $comment_id(int|WP_Comment) (required)
- Comment ID or WP_Comment object.
- $force_delete(true|false)
- Whether to bypass Trash and force deletion.
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. |