WordPress.org

Make WordPress Core

Ticket #29955: 29955.login-errors.patch

File 29955.login-errors.patch, 2.6 KB (added by afercia, 6 years ago)

let screen readers automatically announce login errors

  • src/wp-includes/user.php

     
    134134        $user = get_user_by('login', $username);
    135135
    136136        if ( !$user )
    137                 return new WP_Error( 'invalid_username', sprintf( __( '<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password</a>?' ), wp_lostpassword_url() ) );
     137                return new WP_Error( 'invalid_username', sprintf( __( '<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password?</a>' ), wp_lostpassword_url() ) );
    138138
    139139        /**
    140140         * Filter whether the given user can be authenticated with the provided $password.
     
    150150                return $user;
    151151
    152152        if ( !wp_check_password($password, $user->user_pass, $user->ID) )
    153                 return new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password</a>?' ),
     153                return new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password?</a>' ),
    154154                $username, wp_lostpassword_url() ) );
    155155
    156156        return $user;
  • src/wp-login.php

     
    870870        if ( isset($_POST['log']) )
    871871                $user_login = ( 'incorrect_password' == $errors->get_error_code() || 'empty_password' == $errors->get_error_code() ) ? esc_attr(wp_unslash($_POST['log'])) : '';
    872872        $rememberme = ! empty( $_POST['rememberme'] );
     873
     874        ! empty( $errors->errors ) ? $aria_describedby_error = ' aria-describedby="login_error"' : $aria_describedby_error = '';
    873875?>
    874876
    875877<form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
    876878        <p>
    877879                <label for="user_login"><?php _e('Username') ?><br />
    878                 <input type="text" name="log" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
     880                <input type="text" name="log" id="user_login"<?php echo $aria_describedby_error ?> class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
    879881        </p>
    880882        <p>
    881883                <label for="user_pass"><?php _e('Password') ?><br />
    882                 <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
     884                <input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error ?> class="input" value="" size="20" /></label>
    883885        </p>
    884886        <?php
    885887        /**