comment_id_fields
云策文档标注
概述
comment_id_fields 是一个 WordPress 过滤器,用于修改评论表单中隐藏的 ID 字段的 HTML 输出。它允许开发者自定义这些字段的格式或内容。
关键要点
- 这是一个过滤器钩子,用于过滤返回的评论 ID 字段的 HTML 字符串。
- 接受三个参数:$comment_id_fields(HTML 格式的隐藏 ID 字段元素)、$post_id(文章 ID)和 $reply_to_id(被回复评论的 ID)。
- 常用于 get_comment_id_fields() 函数中,以控制评论回复表单的隐藏输入字段。
代码示例
add_filter( 'comment_id_fields', 'custom_comment_id_fields', 10, 3 );
function custom_comment_id_fields( $comment_id_fields, $post_id, $reply_to_id ) {
// 自定义逻辑,例如添加额外的属性或修改 HTML
$comment_id_fields .= '<input type="hidden" name="custom_field" value="example" />';
return $comment_id_fields;
}
原文内容
Filters the returned comment ID fields.
Parameters
$comment_id_fieldsstring-
The HTML-formatted hidden ID field comment elements.
$post_idint-
The post ID.
$reply_to_idint-
The ID of the comment being replied to.
Source
return apply_filters( 'comment_id_fields', $comment_id_fields, $post_id, $reply_to_id );
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |