web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

wordpress如何利用wp_delete_comment删除评论

453 ℃
     

wordpress如何利用wp_delete_comment删除评论,下面web建站小编给大家简单介绍一下具体代码!

wp_delete_comment源码:

function wp_delete_comment( $comment_id, $force_delete = false ) {
  global $wpdb;
  
  $comment = get_comment( $comment_id );
  if ( ! $comment ) {
    return false;
  }
  
  if ( ! $force_delete && EMPTY_TRASH_DAYS && ! in_array(
 wp_get_comment_status( $comment ), array( 'trash', 'spam' ), true ) ) {
    return wp_trash_comment( $comment_id );
  }
  
  do_action( 'delete_comment', $comment->comment_ID, $comment );
  
  $children = $wpdb->get_col( $wpdb->prepare(
 "SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID ) );
  if ( ! empty( $children ) ) {
    $wpdb->update( $wpdb->comments, array(
 'comment_parent' => $comment->comment_parent ), array( 'comment_parent' => $comment->comment_ID ) );
    clean_comment_cache( $children );
  }
  
  $meta_ids = $wpdb->get_col( $wpdb->prepare(
 "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) );
  foreach ( $meta_ids as $mid ) {
    delete_metadata_by_mid( 'comment', $mid );
  }
  
  if ( ! $wpdb->delete( $wpdb->comments, array(
 'comment_ID' => $comment->comment_ID ) ) ) {
    return false;
  }
  
  do_action( 'deleted_comment', $comment->comment_ID, $comment );
  
  $post_id = $comment->comment_post_ID;
  if ( $post_id && 1 == $comment->comment_approved ) {
    wp_update_comment_count( $post_id );
  }
  
  clean_comment_cache( $comment->comment_ID );
  do_action( 'wp_set_comment_status', $comment->comment_ID, 'delete' );
  wp_transition_comment_status(
 'delete', $comment->comment_approved, $comment );
  return true;
}

wp_delete_comment调用:

wp_delete_comment(27, true); //删除id=27

WordPress如何判断当前文章是否是密码保护文章

WordPress版本如何使用str_starts_with和str_ends_with函数

WordPress如何显示当前文章的评论个数

wordpress如何显示下个评论链接

wordpress教程如何输出用于回复评论的隐藏输入html

标签: wordpress函数, wordpress删除评论, wp_delete_comment

上面是“wordpress如何利用wp_delete_comment删除评论”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_3731.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > wordpress
本文共计1415个字,预计阅读时长10分钟
生活小工具,收录了80多款小工具
上一篇: 介绍几款带有中国风古韵的免费可商用中文字体
下一篇: 推荐9款支持 Vue3 免费开源的前端 UI 组件库
x 打工人ai神器