Skip to content

Commit c1fa4f5

Browse files
committed
Fix generate password button requiring 2 clicks
See https://core.trac.wordpress.org/ticket/63897
1 parent 27233a0 commit c1fa4f5

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/js/_enqueues/admin/user-profile.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,37 @@
531531
});
532532

533533
/*
534-
* We need to generate a password as soon as the Reset Password page is loaded,
534+
* On some pages, we need to generate a password as soon as the page is loaded,
535535
* to avoid double clicking the button to retrieve the first generated password.
536-
* See ticket #39638.
536+
* (This is necessary for the Reset Password page and the Add User page.)
537+
* See tickets #39638 and #63897.
537538
*/
538539
$( function() {
539-
if ( $( '.reset-pass-submit' ).length ) {
540-
$( '.reset-pass-submit button.wp-generate-pw' ).trigger( 'click' );
540+
var $generateButton = $pass1Row.find( 'button.wp-generate-pw' );
541+
if ( $generateButton.length === 0 ) {
542+
/*
543+
* Some pages do not have a button for generating a password.
544+
* (This includes the Install page, the Login page and the Writing Settings page.)
545+
*/
546+
return;
541547
}
548+
549+
if ( $generateButton[0].hasAttribute( 'aria-expanded' ) ) {
550+
/*
551+
* On some pages, the password field is initially hidden,
552+
* and the button for generating a password is also used to show the field.
553+
* (This is the case for the Edit User page and the Profile page.)
554+
* For these pages, we don't need to generate a password on page load,
555+
* because when the button is clicked to reveal the password field,
556+
* a password will be generated as a side effect.
557+
*/
558+
return;
559+
}
560+
561+
/*
562+
* We must be on a page where we need to generate a password on page load.
563+
*/
564+
$generateButton.trigger( 'click' );
542565
});
543566

544567
})(jQuery);

0 commit comments

Comments
 (0)