更好的WordPress主题

WordPress 插入评论函数 wp_insert_comment() 的使用方法和参数介绍

摘要:

WordPress wp_insert_comment() 插入文章评论的函数,使用简单,直接插入数据库,值得一提的是,不经过 wp_new_comment() 各种判断的弯弯绕。

wp_insert_comment() 的使用方法

$args= array(
    // 参数设置
);
$comment_id = wp_insert_comment($args);
// 新增评论成功则返回新评论ID,失败则返回false

wp_insert_comment() 的参数

@type string     $comment_agent        The HTTP user agent of the `$comment_author` when
                                       the comment was submitted. Default empty.
@type int|string $comment_approved     Whether the comment has been approved. Default 1.
@type string     $comment_author       The name of the author of the comment. Default empty.
@type string     $comment_author_email The email address of the `$comment_author`. Default empty.
@type string     $comment_author_IP    The IP address of the `$comment_author`. Default empty.
@type string     $comment_author_url   The URL address of the `$comment_author`. Default empty.
@type string     $comment_content      The content of the comment. Default empty.
@type string     $comment_date         The date the comment was submitted. To set the date
                                       manually, `$comment_date_gmt` must also be specified.
                                       Default is the current time.
@type string     $comment_date_gmt     The date the comment was submitted in the GMT timezone.
                                       Default is `$comment_date` in the site's GMT timezone.
@type int        $comment_karma        The karma of the comment. Default 0.
@type int        $comment_parent       ID of this comment's parent, if any. Default 0.
@type int        $comment_post_ID      ID of the post that relates to the comment, if any.
                                       Default 0.
@type string     $comment_type         Comment type. Default empty.
@type array      $comment_meta         Optional. Array of key/value pairs to be stored in commentmeta for the
                                       new comment.
@type int        $user_id              ID of the user who submitted the comment. Default 0.

本文属原创,转载请注明原文:https://themebetter.com/wp_insert_comment.html

感觉很棒!可以赞赏支持我们~

赞赏支持
分享到:

低至¥89元/年 限时抢

阿里云服务器专享1折起 | 限时抢各种代金券

立即抢购

评论 (0)

登录后评论
注:有关主题的售前售后请 提交工单

建站!你有充足的理由选择我们

世界上超过30%的网站是由WordPress搭建,而我们是国内最靠谱的WordPress开发商
QQ咨询 在线咨询