From e9c9c59681be8cd9af9b93c66889db4ceb4ad9fd Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Fri, 15 Jul 2022 23:38:46 +0000 Subject: [PATCH] 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 --- src/wp-login.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/wp-login.php b/src/wp-login.php index de528842e0..076b866df3 100644 --- a/src/wp-login.php +++ b/src/wp-login.php @@ -261,7 +261,7 @@ function login_header( $title = 'Log In', $message = '', $wp_error = null ) { * * @param string $messages Login messages. */ - echo '

' . apply_filters( 'login_messages', $messages ) . "

\n"; + echo '

' . apply_filters( 'login_messages', $messages ) . "

\n"; } } } // End of login_header(). @@ -1388,10 +1388,15 @@ switch ( $action ) { $rememberme = ! empty( $_POST['rememberme'] ); - if ( $errors->has_errors() ) { - $aria_describedby_error = ' aria-describedby="login_error"'; - } else { - $aria_describedby_error = ''; + $aria_describedby = ''; + $has_errors = $errors->has_errors(); + + if ( $has_errors ) { + $aria_describedby = ' aria-describedby="login_error"'; + } + + if ( $has_errors && 'message' === $errors->get_error_data() ) { + $aria_describedby = ' aria-describedby="login-message"'; } wp_enqueue_script( 'user-profile' ); @@ -1400,13 +1405,13 @@ switch ( $action ) {

- class="input" value="" size="20" autocapitalize="off" autocomplete="username" /> + class="input" value="" size="20" autocapitalize="off" autocomplete="username" />

- class="input password-input" value="" size="20" autocomplete="current-password" /> + class="input password-input" value="" size="20" autocomplete="current-password" />