Comments: Add contextual autocomplete attributes to comment form fields.

For accessibility, input fields should identify their "purpose".  The HTML5 attribute `autocomplete` allows for various user data to be quickly autofilled while adding context for some assistive technologies.

This commit adds the appropriate autofill purposes for an author's name, email, and website URL in the comment form template.

Props juliemoynat, bhrugesh96, sabernhardt.
Fixes #55779.

git-svn-id: https://develop.svn.wordpress.org/trunk@53576 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
David Baumwald 2022-06-24 21:24:18 +00:00
parent ac64f38b66
commit 2fa1194a75

View File

@ -2371,7 +2371,7 @@ function comment_form( $args = array(), $post_id = null ) {
( $req ? $required_indicator : '' )
),
sprintf(
'<input id="author" name="author" type="text" value="%s" size="30" maxlength="245"%s />',
'<input id="author" name="author" type="text" value="%s" size="30" maxlength="245" autocomplete="name"%s />',
esc_attr( $commenter['comment_author'] ),
( $req ? $required_attribute : '' )
)
@ -2384,7 +2384,7 @@ function comment_form( $args = array(), $post_id = null ) {
( $req ? $required_indicator : '' )
),
sprintf(
'<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes"%s />',
'<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes" autocomplete="email"%s />',
( $html5 ? 'type="email"' : 'type="text"' ),
esc_attr( $commenter['comment_author_email'] ),
( $req ? $required_attribute : '' )
@ -2397,7 +2397,7 @@ function comment_form( $args = array(), $post_id = null ) {
__( 'Website' )
),
sprintf(
'<input id="url" name="url" %s value="%s" size="30" maxlength="200" />',
'<input id="url" name="url" %s value="%s" size="30" maxlength="200" autocomplete="url" />',
( $html5 ? 'type="url"' : 'type="text"' ),
esc_attr( $commenter['comment_author_url'] )
)