Login and Registration: Add `required` attribute to username and password fields in `wp_login_form()`.

These attributes are needed to indicate that both fields are required. This changeset doesn't add the attribute by default but allows extenders to enable it by passing `true` to the `$required_username` and `$required_password` to `wp_login_form()` arguments array.

Props alesflex, sabernhardt, joedolson, rcreators, rajinsharwar.
Fixes #60062.



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


git-svn-id: http://core.svn.wordpress.org/trunk@57831 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
audrasjb 2024-06-11 06:24:18 +00:00
parent 41e21c4ecf
commit 20630accce
2 changed files with 47 additions and 36 deletions

View File

@ -491,6 +491,7 @@ function wp_registration_url() {
* The login form HTML is echoed by default. Pass a false value for `$echo` to return it instead. * The login form HTML is echoed by default. Pass a false value for `$echo` to return it instead.
* *
* @since 3.0.0 * @since 3.0.0
* @since 6.6.0 Added `required_username` and `required_password` arguments.
* *
* @param array $args { * @param array $args {
* Optional. Array of options to control the form output. Default empty array. * Optional. Array of options to control the form output. Default empty array.
@ -512,6 +513,10 @@ function wp_registration_url() {
* @type string $value_username Default value for the username field. Default empty. * @type string $value_username Default value for the username field. Default empty.
* @type bool $value_remember Whether the "Remember Me" checkbox should be checked by default. * @type bool $value_remember Whether the "Remember Me" checkbox should be checked by default.
* Default false (unchecked). * Default false (unchecked).
* @type bool $required_username Whether the username field has the 'required' attribute.
* Default false.
* @type bool $required_password Whether the password field has the 'required' attribute.
* Default false.
* *
* } * }
* @return void|string Void if 'echo' argument is true, login form HTML if 'echo' is false. * @return void|string Void if 'echo' argument is true, login form HTML if 'echo' is false.
@ -534,6 +539,10 @@ function wp_login_form( $args = array() ) {
'value_username' => '', 'value_username' => '',
// Set 'value_remember' to true to default the "Remember me" checkbox to checked. // Set 'value_remember' to true to default the "Remember me" checkbox to checked.
'value_remember' => false, 'value_remember' => false,
// Set 'required_username' to true to add the required attribute to username field.
'required_username' => false,
// Set 'required_password' to true to add the required attribute to password field.
'required_password' => false,
); );
/** /**
@ -594,19 +603,21 @@ function wp_login_form( $args = array() ) {
sprintf( sprintf(
'<p class="login-username"> '<p class="login-username">
<label for="%1$s">%2$s</label> <label for="%1$s">%2$s</label>
<input type="text" name="log" id="%1$s" autocomplete="username" class="input" value="%3$s" size="20" /> <input type="text" name="log" id="%1$s" autocomplete="username" class="input" value="%3$s" size="20"%4$s />
</p>', </p>',
esc_attr( $args['id_username'] ), esc_attr( $args['id_username'] ),
esc_html( $args['label_username'] ), esc_html( $args['label_username'] ),
esc_attr( $args['value_username'] ) esc_attr( $args['value_username'] ),
( $args['required_username'] ? ' required="required"' : '' )
) . ) .
sprintf( sprintf(
'<p class="login-password"> '<p class="login-password">
<label for="%1$s">%2$s</label> <label for="%1$s">%2$s</label>
<input type="password" name="pwd" id="%1$s" autocomplete="current-password" spellcheck="false" class="input" value="" size="20" /> <input type="password" name="pwd" id="%1$s" autocomplete="current-password" spellcheck="false" class="input" value="" size="20"%3$s />
</p>', </p>',
esc_attr( $args['id_password'] ), esc_attr( $args['id_password'] ),
esc_html( $args['label_password'] ) esc_html( $args['label_password'] ),
( $args['required_password'] ? ' required="required"' : '' )
) . ) .
$login_form_middle . $login_form_middle .
( $args['remember'] ? ( $args['remember'] ?

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.6-beta1-58381'; $wp_version = '6.6-beta1-58382';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.