WordPress.org

Make WordPress Core

Opened 9 months ago

Last modified 7 weeks ago

#39927 new enhancement

Add support for CSS class and attributes in wp_login_form input fields

Reported by: subrataemfluence Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.2
Component: Login and Registration Keywords: has-patch
Focuses: template Cc:

Description

I think adding support for class and a few useful attributes like placeholder and required for default login form (wp_login_form).

In wp-includes/general-templates.php (line 402), if we can pass $args like this it would be nice:

$args = array(
  ...
  'placeholder_username' => __('Your login Id'),
  'placeholder_password' => __('Your password (case sensitive)'),
  'username_required' => true,
  'password_required' => true,
  'username_css_class' => 'form_control,
  'password_css_class' => 'form-control
  'username_remove_size' => true,
  'password_remove_size' => true
);

This will have the following benefits:

1) We can use HTML5 native client side validation
2) We can tell WordPress to use custom class name (if none is supplied, default would be used)
3) Placeholder will help removing labels and save space
4) Size attribute if set to true will not be used. This is useful if I don't need it at all.

Based on the above values the <form> element also could be modified like this:

$form = '<form ...>
   <input type="text" <?php if($args["username_required"] == true) echo "required" ... ?>
</form>';

if($args['echo']){
   echo $form;
} else {
   return $form;
}

Attachments (1)

39927.patch (4.0 KB) - added by subrataemfluence 9 months ago.

Download all attachments as: .zip

Change History (5)

#1 @subrataemfluence
9 months ago

  • Keywords needs-patch added

#2 @subrataemfluence
9 months ago

  • Keywords has-patch added; needs-patch removed

#3 @subrataemfluence
7 weeks ago

Corrected unterminated strings for username_css_class and password_css_class keys.

$args = array(
  ...
  'placeholder_username' => __('Your login Id'),
  'placeholder_password' => __('Your password (case sensitive)'),
  'username_required' => true,
  'password_required' => true,
  'username_css_class' => 'form_control',
  'password_css_class' => 'form-control'
  'username_remove_size' => true,
  'password_remove_size' => true
);

#4 @subrataemfluence
7 weeks ago

#42053 was marked as a duplicate.

Note: See TracTickets for help on using tickets.