#2391 closed enhancement (fixed)
Autofocus on login page
Reported by: | szepe.viktor | Owned by: | pento |
---|---|---|---|
Milestone: | Priority: | normal | |
Component: | Login & Authentication | Keywords: | |
Cc: |
Description
Would it be possible to add autofocus on the wp.org login page?
https://login.wordpress.org/
Thank you.
Change History (4)
#1
@
8 years ago
- Component changed from General to Login & Authentication
- Keywords needs-patch added
#2
follow-up:
↓ 4
@
8 years ago
- Keywords needs-patch removed
- Owner set to pento
- Status changed from new to assigned
I'm not entirely sure why wp_attempt_focus()
uses a setTimeout()
, and I don't know if @azaozz would remember why he added it 8 years ago.
In the mean time, I'll reuse the relevant bits of wp_attempt_focus()
- it redirects to wp-login.php
, so we don't need to do all the username/password/error handling that the full version does.
#4
in reply to:
↑ 2
@
8 years ago
Replying to pento:
I don't know if @azaozz would remember why he added it 8 years ago.
I wish I could :) Looks like some (old?) browsers needed a bit of time to autofill the user_login field before we try to select the text. Don't think it needs the try/catch any more, but doesn't hurt.
Note: See
TracTickets for help on using
tickets.
In WordPress core,
wp-login.php
file has a wp_attempt_focus() function to handle this.On https://login.wordpress.org/, the login.php template uses the wp_login_form() function, which doesn't have autofocus functionality. It falls back to regular login form though (which does have autofocus) in case of an error, e.g. if you enter an empty username or password.
A quick fix would be to copy
wp_attempt_focus()
tologin.php
template. It might also be a worthy enhancement forwp_login_form()
function in core.There's also an
autofocus
HTML attribute, but core only uses it inwp-admin/includes/theme-install.php
, see [WP21143]. I guess the JS option is more flexible, because it focuses different fields (user_login
vs.user_pass
), depending on previous input.