comment_form_submit_button
云策文档标注
概述
comment_form_submit_button 是一个 WordPress 过滤器,用于自定义评论表单的提交按钮的 HTML 标记。它允许开发者修改按钮的显示内容,例如添加额外的 HTML 元素或样式。
关键要点
- 这是一个过滤器 Hook,用于过滤评论表单的提交按钮 HTML。
- 接受两个参数:$submit_button(提交按钮的 HTML 字符串)和 $args(传递给 comment_form() 的参数数组)。
- 开发者可以通过此 Hook 自定义提交按钮的标记,例如添加前后包装元素。
- 与 comment_form() 函数紧密相关,用于输出完整的评论表单。
代码示例
// 定义 comment_form_submit_button 回调函数
function filter_comment_form_submit_button( $submit_button, $args ) {
// 在此处进行过滤操作...
$submit_before = '';
$submit_after = '';
return $submit_before . $submit_button . $submit_after;
};
// 添加过滤器
add_filter( 'comment_form_submit_button', 'filter_comment_form_submit_button', 10, 2 );
原文内容
Filters the submit button for the comment form to display.
Parameters
$submit_buttonstring-
HTML markup for the submit button.
$argsarray-
Arguments passed to comment_form() .
More Arguments from comment_form( … $args )
Default arguments and form fields to override.
fieldsarrayDefault comment fields, filterable by default via the ‘comment_form_default_fields’ hook.authorstringComment author field HTML.emailstringComment author email field HTML.urlstringComment author URL field HTML.cookiesstringComment cookie opt-in field HTML.comment_fieldstringThe comment textarea field HTML.must_log_instringHTML element for a ‘must be logged in to comment’ message.logged_in_asstringThe HTML for the ‘logged in as [user]’ message, the Edit profile link, and the Log out link.comment_notes_beforestringHTML element for a message displayed before the comment fields if the user is not logged in.
Default ‘Your email address will not be published.’.comment_notes_afterstringHTML element for a message displayed after the textarea field.actionstringThe comment form element action attribute. Default'/wp-comments-post.php'.novalidateboolWhether the novalidate attribute is added to the comment form. Default false.id_formstringThe comment form element id attribute. Default'commentform'.id_submitstringThe comment submit element id attribute. Default'submit'.class_containerstringThe comment form container class attribute. Default'comment-respond'.class_formstringThe comment form element class attribute. Default'comment-form'.class_submitstringThe comment submit element class attribute. Default'submit'.name_submitstringThe comment submit element name attribute. Default'submit'.title_replystringThe translatable'reply'button label. Default ‘Leave a Reply’.title_reply_tostringThe translatable'reply-to'button label. Default ‘Leave a Reply to %s’, where %s is the author of the comment being replied to.title_reply_beforestringHTML displayed before the comment form title.
Default:<h3 id="reply-title" class="comment-reply-title">.title_reply_afterstringHTML displayed after the comment form title.
Default:<code></h3>.cancel_reply_beforestringHTML displayed before the cancel reply link.cancel_reply_afterstringHTML displayed after the cancel reply link.cancel_reply_linkstringThe translatable ‘cancel reply’ button label. Default ‘Cancel reply’.label_submitstringThe translatable'submit'button label. Default ‘Post a comment’.submit_buttonstringHTML format for the Submit button.
Default:<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />.submit_fieldstringHTML format for the markup surrounding the Submit button and comment hidden fields. Default:<p class="form-submit">%1$s %2$s</p>, where %1$s is the submit button markup and %2$s is the comment hidden fields.formatstringThe comment form format. Default'xhtml'. Accepts'xhtml','html5'.
Source
$submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );Changelog
Version Description 4.2.0 Introduced. User Contributed Notes
You must log in before being able to contribute a note or feedback.
Skip to note 2 content
Prasad Nevase
Example: Following example shows how you can use this filter to change submit button markup of comment form.
// define the comment_form_submit_button callback function filter_comment_form_submit_button( $submit_button, $args ) { // make filter magic happen here... $submit_before = '<div class="form-group">'; $submit_after = '</div>'; return $submit_before . $submit_button . $submit_after; }; // add the filter add_filter( 'comment_form_submit_button', 'filter_comment_form_submit_button', 10, 2 );