WordPress删除评论函数:wp_delete_comment
WordPress函数wp_delete_comment()用于删除评论。一般情况下,wp_delete_comment()函数会将评论移入回收站,而不是永久删除。如果已禁用回收站,或评论本身已在回收站中,或参数$force_delete为true,则评论将被永久删除。
如果评论被批准并且有附属的文章ID,则该文章评论计数将被更新。
wp_delete_comment( int|WP_Comment $comment_id, bool $force_delete = false ): bool
函数参数
$comment_id
数据类型:int|WP_Comment (必须)
评论ID或WP_Comment对象。
$force_delete
数据类型:bool (可选)
是否绕过回收站并强制删除。
函数返回值
成功返回true,失败返回false。
函数使用示例
$id = 456;
$done = wp_delete_comment( $id, true );
if( $done ){
echo "评论 {$id} 已删除!";
}
扩展阅读
wp_delete_comment()函数位于:wp-includes/comment.php
相关函数:
- clean_comment_cache()
- wp_update_comment_count()
- wp_get_comment_status()
- wp_transition_comment_status()
- wp_trash_comment()
- get_comment()
- wp_ajax_delete_comment()

