首页 > CMS教程 > WordPress    日期:2026-06-09 / 浏览

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()

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章