Accessibility: Login: Display error messages when both the username and password fields are empty.

For accessibility and usability, if an input error is detected, the item that is in error needs to be identified and the error needs to be described to the user in text (WCAG Success Criterion 3.3.1). The login form displays an error when the username field is empty or when the password field is empty. It omits to do so when both fields are empty.

This change restores the login form behavior to the one that used to work in WordPress 2.3 (!) and displays the related error messages also when both fields are empty.

Props birgire, audrasjb.
See #8938, #5405, #3708.
Fixes #42985.

Built from https://develop.svn.wordpress.org/trunk@44918


git-svn-id: http://core.svn.wordpress.org/trunk@44749 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrea Fercia 2019-03-16 15:22:53 +00:00
parent fff2440ba5
commit 31e34400a5
3 changed files with 5 additions and 5 deletions

View File

@ -95,10 +95,6 @@ function wp_signon( $credentials = array(), $secure_cookie = '' ) {
$user = wp_authenticate( $credentials['user_login'], $credentials['user_password'] );
if ( is_wp_error( $user ) ) {
if ( $user->get_error_codes() == array( 'empty_username', 'empty_password' ) ) {
$user = new WP_Error( '', '' );
}
return $user;
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.2-alpha-44917';
$wp_version = '5.2-alpha-44918';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -1007,6 +1007,10 @@ switch ( $action ) {
$errors = new WP_Error();
}
if ( empty( $_POST ) && $errors->get_error_codes() === array( 'empty_username', 'empty_password' ) ) {
$errors = new WP_Error( '', '' );
}
if ( $interim_login ) {
if ( ! $errors->has_errors() ) {
$errors->add( 'expired', __( 'Your session has expired. Please log in to continue where you left off.' ), 'message' );