WordPress函数wp_insert_comment()在数据库中插入评论。
wp_insert_comment( array $commentdata ): int|false
函数参数
$commentdata
数据类型:array (必须)
用于插入新评论的参数数组。
comment_agent
数据类型:string
提交评论时评论作者的HTTP用户代理。默认为空。
comment_approved
数据类型:int|string
评论是否已获得批准。默认值:1。
comment_author
数据类型:string
评论作者的姓名。默认为空。
comment_author_email
数据类型:string
评论作者的电子邮件地址。默认为空。
comment_author_IP
数据类型:string
评论作者的IP地址。默认为空。
comment_author_url
数据类型:string
评论作者的URL地址。默认为空。
comment_content
数据类型:string
评论的内容。默认为空。
comment_date
数据类型:string
提交评论的日期。默认为当前时间。
comment_date_gmt
数据类型:string
评论日期的gmt时区。默认为网站后台设置的时区。
comment_karma
数据类型:int
用于评论的”评分”或”权重”系统。默认值:0。
comment_parent
数据类型:int
评论的父级ID。默认值:0。
comment_post_ID
数据类型:int
与评论相关的文章的ID。默认值:0。
comment_type
数据类型:string
评论类型。默认值:comment。
comment_meta
数据类型:array
可选。要存储在新评论的commentmeta中的键/值对数组。
user_id
数据类型:int
提交评论的用户的ID。默认值:0。
函数返回值
int|false
成功返回新评论的ID,失败返回false。
函数使用示例
$commentdata = array(
'comment_author' => '背字根',
'comment_author_email' => 'beizigen@qq.com',
'comment_author_url' => 'https://www.beizigen.com/',
'comment_content' => '这是一条评论',
'comment_parent' => 0,
'user_id' => 0,
'comment_author_IP' => '127.0.0.1',
'comment_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36',
'comment_date' => current_time('mysql'),
'comment_date_gmt' => current_time('mysql', 1),
'comment_approved' => 1,
);
wp_insert_comment( $commentdata );
扩展阅读
wp_insert_comment()函数位于:wp-includes/comment.php
相关函数:
- wp_cache_delete_multiple()
- get_gmt_from_date()
- clean_comment_cache()
- wp_update_comment_count()
- add_comment_meta()
- get_comment()
- wp_new_comment()
原创文章,作者:,如若转载,请注明出处:https://ce.771633.xyz/4431.html