Opened 7 years ago
Closed 7 years ago
#41190 closed enhancement (wontfix)
Don't print wp_attempt_focus() code when enable_login_autofocus is disabled
Reported by: | ka2 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.8 |
Component: | Login and Registration | Keywords: | has-patch close |
Focuses: | javascript | Cc: |
Description
Currently, when autofocus at login is turned OFF as below, only the function calling part of "wp_attempt_focus()" is not outputted.
Add_filter( 'enable_login_autofocus', function(){ return false; } );
However, for them who do not need autofocus, the definition part of the "wp_attempt_focus()" function should also be unnecessary. So, please do not output the function definition part.
<script type="text/javascript"> <?php /** * Filters whether to print the call to `wp_attempt_focus()` on the login screen. * * @since 4.8.0 * * @param bool $print Whether to print the function call. Default true. */ if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) { ?> function wp_attempt_focus(){ setTimeout( function(){ try{ <?php if ( $user_login ) { ?> d = document.getElementById('user_pass'); d.value = ''; <?php } else { ?> d = document.getElementById('user_login'); <?php if ( 'invalid_username' == $errors->get_error_code() ) { ?> if( d.value != '' ) d.value = ''; <?php } }?> d.focus(); d.select(); } catch(e){} }, 200); } wp_attempt_focus(); <?php } ?> if(typeof wpOnload=='function')wpOnload(); <?php if ( $interim_login ) { ?> (function(){ try { var i, links = document.getElementsByTagName('a'); for ( i in links ) { if ( links[i].href ) links[i].target = '_blank'; } } catch(e){} }()); <?php } ?> </script>
I think that it is best to apply the filter as described above.
I hope you will consider this.
Attachments (1)
Change History (5)
#1
@
7 years ago
- Focuses performance removed
- Keywords has-patch added
- Milestone changed from Awaiting Review to 4.8.1
- Summary changed from I hope to include the function definition part in the output to be disabled using "enable_login_autofocus" filter. to Don't print wp_attempt_focus() code when enable_login_autofocus is disabled
- Type changed from feature request to enhancement
- Version changed from trunk to 4.8
#2
@
7 years ago
@swissspidy although it would be cleaner, there are other places where that function gets called. As noted in the original ticket:
Worth noting the auto-focus will still work on other wp-login.php views like, for example, the lost password one. It probably makes sense to still have auto-focus where the users task is so specific.
That's the reason why the filter disables only the call.
Introduced in #40301.
Makes sense to me. @afercia What do you think?