Make WordPress Core

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's profile ka2 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8
Component: Login and Registration Keywords: has-patch close
Focuses: javascript Cc:


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">
 * 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 = '';
} catch(e){}
}, 200);

<?php } ?>
if(typeof wpOnload=='function')wpOnload();
<?php if ( $interim_login ) { ?>
try {
	var i, links = document.getElementsByTagName('a');
	for ( i in links ) {
		if ( links[i].href )
			links[i].target = '_blank';
} catch(e){}
<?php } ?>

I think that it is best to apply the filter as described above.

I hope you will consider this.

Attachments (1)

wp-login.php.patch (974 bytes) - added by ka2 7 years ago.

Download all attachments as: .zip

Change History (5)

7 years ago

#1 @swissspidy
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

Introduced in #40301.

Makes sense to me. @afercia What do you think?

#2 @afercia
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.

#3 @swissspidy
7 years ago

  • Keywords close added
  • Milestone changed from 4.8.1 to Awaiting Review

Ah, I see. Well I guess that makes this one a candidate for close unless someone has a good argument against it.

#4 @SergeyBiryukov
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.