Skip to content

Commit e9c9c59

Browse files
committed
Login: Explicitly associate errors with input fields.
Add an `aria-describedby` relationship between login email/password input fields and displayed login error messages. Props patrickgroot, rollybueno, afercia. Fixes #54483. git-svn-id: https://develop.svn.wordpress.org/trunk@53707 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ab2cd6f commit e9c9c59

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/wp-login.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function login_header( $title = 'Log In', $message = '', $wp_error = null ) {
261261
*
262262
* @param string $messages Login messages.
263263
*/
264-
echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n";
264+
echo '<p class="message" id="login-message">' . apply_filters( 'login_messages', $messages ) . "</p>\n";
265265
}
266266
}
267267
} // End of login_header().
@@ -1388,10 +1388,15 @@ function wp_login_viewport_meta() {
13881388

13891389
$rememberme = ! empty( $_POST['rememberme'] );
13901390

1391-
if ( $errors->has_errors() ) {
1392-
$aria_describedby_error = ' aria-describedby="login_error"';
1393-
} else {
1394-
$aria_describedby_error = '';
1391+
$aria_describedby = '';
1392+
$has_errors = $errors->has_errors();
1393+
1394+
if ( $has_errors ) {
1395+
$aria_describedby = ' aria-describedby="login_error"';
1396+
}
1397+
1398+
if ( $has_errors && 'message' === $errors->get_error_data() ) {
1399+
$aria_describedby = ' aria-describedby="login-message"';
13951400
}
13961401

13971402
wp_enqueue_script( 'user-profile' );
@@ -1400,13 +1405,13 @@ function wp_login_viewport_meta() {
14001405
<form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
14011406
<p>
14021407
<label for="user_login"><?php _e( 'Username or Email Address' ); ?></label>
1403-
<input type="text" name="log" id="user_login"<?php echo $aria_describedby_error; ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" autocomplete="username" />
1408+
<input type="text" name="log" id="user_login"<?php echo $aria_describedby; ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" autocomplete="username" />
14041409
</p>
14051410

14061411
<div class="user-pass-wrap">
14071412
<label for="user_pass"><?php _e( 'Password' ); ?></label>
14081413
<div class="wp-pwd">
1409-
<input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error; ?> class="input password-input" value="" size="20" autocomplete="current-password" />
1414+
<input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby; ?> class="input password-input" value="" size="20" autocomplete="current-password" />
14101415
<button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Show password' ); ?>">
14111416
<span class="dashicons dashicons-visibility" aria-hidden="true"></span>
14121417
</button>

0 commit comments

Comments
 (0)