Make WordPress Core

Opened 8 years ago

Last modified 6 years ago

#39927 new enhancement

Add support for CSS class and attributes in wp_login_form input fields

Reported by: subrataemfluence's profile 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 8 years ago.

Download all attachments as: .zip

Change History (7)

#1 @subrataemfluence
8 years ago

  • Keywords needs-patch added

#2 @subrataemfluence
8 years ago

  • Keywords has-patch added; needs-patch removed

#3 @subrataemfluence
7 years 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 years ago

#42053 was marked as a duplicate.

#5 @SergeyBiryukov
6 years ago

#47001 was marked as a duplicate.

#6 @SergeyBiryukov
6 years ago

Just noting that adding a placeholder attribute was discussed in #24324 and #40462 and decided against.

Note: See TracTickets for help on using tickets.