allow_empty_comment
云策文档标注
概述
allow_empty_comment 是一个 WordPress 过滤器,用于控制是否允许提交空评论。它影响评论提交时的验证逻辑,默认情况下不允许空评论。
关键要点
- 过滤器名称:allow_empty_comment
- 参数:$allow_empty_comment(布尔值,是否允许空评论,默认 false)和 $commentdata(数组,包含评论数据)
- 用途:在 wp_insert_comment() 等函数中调用,用于自定义空评论的允许状态
- 相关函数:WP_REST_Comments_Controller::check_is_comment_content_allowed(), wp_handle_comment_submission(), wp_xmlrpc_server::wp_newComment()
- 引入版本:5.1.0
代码示例
// Enable empty comment.
add_filter( 'allow_empty_comment', '__return_true' );
原文内容
Filters whether an empty comment should be allowed.
Parameters
$allow_empty_commentbool-
Whether to allow empty comments. Default false.
$commentdataarray-
Array of comment data to be sent to wp_insert_comment() .
More Arguments from wp_insert_comment( … $commentdata )
Array of arguments for inserting a new comment.
comment_agentstringThe HTTP user agent of the$comment_authorwhen the comment was submitted. Default empty.comment_approvedint|stringWhether the comment has been approved. Default 1.comment_authorstringThe name of the author of the comment. Default empty.comment_author_emailstringThe email address of the$comment_author. Default empty.comment_author_IPstringThe IP address of the$comment_author. Default empty.comment_author_urlstringThe URL address of the$comment_author. Default empty.comment_contentstringThe content of the comment. Default empty.comment_datestringThe date the comment was submitted. To set the date manually,$comment_date_gmtmust also be specified.
Default is the current time.comment_date_gmtstringThe date the comment was submitted in the GMT timezone.
Default is$comment_datein the site’s GMT timezone.comment_karmaintThe karma of the comment. Default 0.comment_parentintID of this comment’s parent, if any. Default 0.comment_post_IDintID of the post that relates to the comment, if any.
Default 0.comment_typestringComment type. Default'comment'.comment_metaarrayOptional. Array of key/value pairs to be stored in commentmeta for the new comment.user_idintID of the user who submitted the comment. Default 0.
Source
$allow_empty_comment = apply_filters( 'allow_empty_comment', false, $commentdata );
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |
Skip to note 2 content
rabmalin
// Enable empty comment. add_filter( 'allow_empty_comment', '__return_true' );