Skip to content

Commit f648866

Browse files
authored
Update comments.php
1 parent 2ed7539 commit f648866

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

comments.php

+16-8
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,35 @@
4545

4646
<?php
4747

48-
// prevent duplicate filter registration
49-
remove_filter( 'comment_form_default_fields', 'custom_comment_fields' );
48+
// add custom fields to comment form
5049
add_filter( 'comment_form_default_fields', 'custom_comment_fields', 10, 1 );
5150

5251
function custom_comment_fields( $fields ) {
52+
// get commenter details
5353
$commenter = wp_get_current_commenter();
54+
55+
// check if name and email are required
5456
$req = get_option( 'require_name_email' );
5557
$aria_req = $req ? " aria-required='true'" : '';
5658
$required = $req ? '<span class="required">*</span>' : '';
5759

5860
// set author field
59-
$fields['author'] = sprintf( '<p class="comment-form-author"><label for="comment-author">%s</label> %s<input id="comment-author" name="author" type="text" value="%s" size="30"%s /></p>',
60-
esc_html__( 'Name', 'hovercraft' ), $required, esc_attr( $commenter['comment_author'] ), $aria_req );
61+
$fields['author'] = sprintf(
62+
'<p class="comment-form-author"><label for="comment-author">%s</label> %s<input id="comment-author" name="author" type="text" value="%s" size="30"%s></p>',
63+
esc_html__( 'Name', 'hovercraft' ), $required, esc_attr( $commenter['comment_author'] ), $aria_req
64+
);
6165

6266
// set email field
63-
$fields['email'] = sprintf( '<p class="comment-form-email"><label for="comment-email">%s</label> %s<input id="comment-email" name="email" type="email" value="%s" size="30"%s /></p>',
64-
esc_html__( 'Email', 'hovercraft' ), $required, esc_attr( $commenter['comment_author_email'] ), $aria_req );
67+
$fields['email'] = sprintf(
68+
'<p class="comment-form-email"><label for="comment-email">%s</label> %s<input id="comment-email" name="email" type="email" value="%s" size="30"%s></p>',
69+
esc_html__( 'Email', 'hovercraft' ), $required, esc_attr( $commenter['comment_author_email'] ), $aria_req
70+
);
6571

6672
// set url field
67-
$fields['url'] = sprintf( '<p class="comment-form-url"><label for="comment-url">%s</label><input id="comment-url" name="url" type="url" value="%s" size="30" /></p>',
68-
esc_html__( 'Website', 'hovercraft' ), esc_attr( $commenter['comment_author_url'] ) );
73+
$fields['url'] = sprintf(
74+
'<p class="comment-form-url"><label for="comment-url">%s</label><input id="comment-url" name="url" type="url" value="%s" size="30"></p>',
75+
esc_html__( 'Website', 'hovercraft' ), esc_attr( $commenter['comment_author_url'] )
76+
);
6977

7078
return $fields;
7179
}

0 commit comments

Comments
 (0)