这个default comment form fields 定义如下:
$fields = array(
\'author\' =>
\'<p class="comment-form-author"><label for="author">\' . __( \'Name\', \'domainreference\' ) . \'</label> \' .
( $req ? \'<span class="required">*</span>\' : \'\' ) .
\'<input id="author" name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) .
\'" size="30"\' . $aria_req . \' /></p>\',
\'email\' =>
\'<p class="comment-form-email"><label for="email">\' . __( \'Email\', \'domainreference\' ) . \'</label> \' .
( $req ? \'<span class="required">*</span>\' : \'\' ) .
\'<input id="email" name="email" type="text" value="\' . esc_attr( $commenter[\'comment_author_email\'] ) .
\'" size="30"\' . $aria_req . \' /></p>\',
\'url\' =>
\'<p class="comment-form-url"><label for="url">\' . __( \'Website\', \'domainreference\' ) . \'</label>\' .
\'<input id="url" name="url" type="text" value="\' . esc_attr( $commenter[\'comment_author_url\'] ) .
\'" size="30" /></p>\',
);
并通过过滤器:
\'fields\' => apply_filters( \'comment_form_default_fields\', $fields )
因此,要修改它们,只需添加一个过滤器:
function wpse126157_comment_form_fields( $fields ) {
// Your code here
// Return something
return $fields;
}
add_filter( \'comment_form_default_fields\', \'comment_form_default_fields\' );
请注意法典中的重要信息:
注意:若要在自定义回调函数中使用上述代码中的变量,必须首先使用以下命令在回调函数中设置这些变量:
$commenter = wp_get_current_commenter();
$req = get_option( \'require_name_email\' );
$aria_req = ( $req ? " aria-required=\'true\'" : \'\' );
因此,您可以相应地修改回调:
function wpse126157_comment_form_fields( $fields ) {
// Include these if you intend to use them
$commenter = wp_get_current_commenter();
$req = get_option( \'require_name_email\' );
$aria_req = ( $req ? " aria-required=\'true\'" : \'\' );
// Your code here
// Return something
return $fields;
}
add_filter( \'comment_form_default_fields\', \'comment_form_default_fields\' );