From c1fa4f54455128a03e603d98e0e317256b8c7c70 Mon Sep 17 00:00:00 2001 From: siliconforks Date: Sat, 30 Aug 2025 11:04:52 -0300 Subject: [PATCH 1/2] Fix generate password button requiring 2 clicks See https://core.trac.wordpress.org/ticket/63897 --- src/js/_enqueues/admin/user-profile.js | 31 ++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/js/_enqueues/admin/user-profile.js b/src/js/_enqueues/admin/user-profile.js index ce680ef4c4298..dcecd2425c959 100644 --- a/src/js/_enqueues/admin/user-profile.js +++ b/src/js/_enqueues/admin/user-profile.js @@ -531,14 +531,37 @@ }); /* - * We need to generate a password as soon as the Reset Password page is loaded, + * On some pages, we need to generate a password as soon as the page is loaded, * to avoid double clicking the button to retrieve the first generated password. - * See ticket #39638. + * (This is necessary for the Reset Password page and the Add User page.) + * See tickets #39638 and #63897. */ $( function() { - if ( $( '.reset-pass-submit' ).length ) { - $( '.reset-pass-submit button.wp-generate-pw' ).trigger( 'click' ); + var $generateButton = $pass1Row.find( 'button.wp-generate-pw' ); + if ( $generateButton.length === 0 ) { + /* + * Some pages do not have a button for generating a password. + * (This includes the Install page, the Login page and the Writing Settings page.) + */ + return; } + + if ( $generateButton[0].hasAttribute( 'aria-expanded' ) ) { + /* + * On some pages, the password field is initially hidden, + * and the button for generating a password is also used to show the field. + * (This is the case for the Edit User page and the Profile page.) + * For these pages, we don't need to generate a password on page load, + * because when the button is clicked to reveal the password field, + * a password will be generated as a side effect. + */ + return; + } + + /* + * We must be on a page where we need to generate a password on page load. + */ + $generateButton.trigger( 'click' ); }); })(jQuery); From bdf8ffa3616b52bbd2eaa4af2771f578ccda42ca Mon Sep 17 00:00:00 2001 From: siliconforks Date: Sun, 31 Aug 2025 01:37:27 -0300 Subject: [PATCH 2/2] Update comment Co-authored-by: Mukesh Panchal --- src/js/_enqueues/admin/user-profile.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/js/_enqueues/admin/user-profile.js b/src/js/_enqueues/admin/user-profile.js index dcecd2425c959..8042737fb6dbb 100644 --- a/src/js/_enqueues/admin/user-profile.js +++ b/src/js/_enqueues/admin/user-profile.js @@ -558,9 +558,7 @@ return; } - /* - * We must be on a page where we need to generate a password on page load. - */ + // We must be on a page where we need to generate a password on page load. $generateButton.trigger( 'click' ); });