diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 30e9a414b5..087a11993d 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -164,6 +164,8 @@ if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_po add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 ); } +add_action( 'wp_ajax_nopriv_generate-password', 'wp_ajax_nopriv_generate_password' ); + add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 ); $action = ( isset( $_REQUEST['action'] ) ) ? $_REQUEST['action'] : ''; diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 06c09f6e92..6f91c3a7ea 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -12,8 +12,7 @@ // /** - * Ajax handler for the Heartbeat API in - * the no-privilege context. + * Ajax handler for the Heartbeat API in the no-privilege context. * * Runs when the user is not logged in. * @@ -3976,6 +3975,15 @@ function wp_ajax_generate_password() { wp_send_json_success( wp_generate_password( 24 ) ); } +/** + * Ajax handler for generating a password in the no-privilege context. + * + * @since 5.7.0 + */ +function wp_ajax_nopriv_generate_password() { + wp_send_json_success( wp_generate_password( 24 ) ); +} + /** * Ajax handler for saving the user's WordPress.org username. * diff --git a/wp-admin/js/user-profile.js b/wp-admin/js/user-profile.js index c8f8d03261..dfec0fdba2 100644 --- a/wp-admin/js/user-profile.js +++ b/wp-admin/js/user-profile.js @@ -157,7 +157,7 @@ var $generateButton, $cancelButton; - $pass1Row = $( '.user-pass1-wrap, .user-pass-wrap' ); + $pass1Row = $( '.user-pass1-wrap, .user-pass-wrap, .reset-pass-submit' ); // Hide the confirm password field when JavaScript support is enabled. $('.user-pass2-wrap').hide(); @@ -461,4 +461,15 @@ } } ); + /* + * We need to generate a password as soon as the Reset Password page is loaded, + * to avoid double clicking the button to retrieve the first generated password. + * See ticket #39638. + */ + $( document ).ready( function() { + if ( $( '.reset-pass-submit' ).length ) { + $( '.reset-pass-submit button.wp-generate-pw' ).trigger( 'click' ); + } + }); + })(jQuery); diff --git a/wp-admin/js/user-profile.min.js b/wp-admin/js/user-profile.min.js index a43f6ab9e1..521356f36b 100644 --- a/wp-admin/js/user-profile.min.js +++ b/wp-admin/js/user-profile.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -!function(r){var e,a,n,t,i,o,d,l,p,c,u=!1,h=wp.i18n.__;function f(){"function"==typeof zxcvbn?(!a.val()||c.hasClass("is-open")?(a.val(a.data("pw")),a.trigger("pwupdate")):b(),g(),1!==parseInt(o.data("start-masked"),10)?a.attr("type","text"):o.trigger("click"),r("#pw-weak-text-label").text(h("Confirm use of weak password"))):setTimeout(f,50)}function w(s){o.attr({"aria-label":h(s?"Show password":"Hide password")}).find(".text").text(h(s?"Show":"Hide")).end().find(".dashicons").removeClass(s?"dashicons-hidden":"dashicons-visibility").addClass(s?"dashicons-visibility":"dashicons-hidden")}function m(s,e,a){var n=r("
");n.addClass("notice inline"),n.addClass("notice-"+(e?"success":"error")),n.text(r(r.parseHTML(a)).text()).wrapInner("

"),s.prop("disabled",e),s.siblings(".notice").remove(),s.before(n)}function v(){var s;e=r(".user-pass1-wrap, .user-pass-wrap"),r(".user-pass2-wrap").hide(),l=r("#submit, #wp-submit").on("click",function(){u=!1}),d=l.add(" #createusersub"),t=r(".pw-weak"),(i=t.find(".pw-checkbox")).on("change",function(){d.prop("disabled",!i.prop("checked"))}),(a=r("#pass1")).length?(p=a.val(),1===parseInt(a.data("reveal"),10)&&f(),a.on("input pwupdate",function(){a.val()!==p&&(p=a.val(),a.removeClass("short bad good strong"),g())})):a=r("#user_pass"),n=r("#pass2").on("input",function(){0]*>/gi,""),n[s].length&&-1===r.inArray(e,a)&&(a.push(e),r("

'+s.message+"

")}).fail(function(s){e.siblings(".notice").remove(),e.before('

'+s.message+"

")}),s.preventDefault()}),window.generatePassword=f,r(window).on("beforeunload",function(){if(!0===u)return h("Your new password has not been saved.")})}(jQuery); \ No newline at end of file +!function(o){var e,a,t,n,i,r,d,p,l,c,u=!1,h=wp.i18n.__;function f(){"function"==typeof zxcvbn?(!a.val()||c.hasClass("is-open")?(a.val(a.data("pw")),a.trigger("pwupdate")):b(),g(),1!==parseInt(r.data("start-masked"),10)?a.attr("type","text"):r.trigger("click"),o("#pw-weak-text-label").text(h("Confirm use of weak password"))):setTimeout(f,50)}function w(s){r.attr({"aria-label":h(s?"Show password":"Hide password")}).find(".text").text(h(s?"Show":"Hide")).end().find(".dashicons").removeClass(s?"dashicons-hidden":"dashicons-visibility").addClass(s?"dashicons-visibility":"dashicons-hidden")}function m(s,e,a){var t=o("
");t.addClass("notice inline"),t.addClass("notice-"+(e?"success":"error")),t.text(o(o.parseHTML(a)).text()).wrapInner("

"),s.prop("disabled",e),s.siblings(".notice").remove(),s.before(t)}function v(){var s;e=o(".user-pass1-wrap, .user-pass-wrap, .reset-pass-submit"),o(".user-pass2-wrap").hide(),p=o("#submit, #wp-submit").on("click",function(){u=!1}),d=p.add(" #createusersub"),n=o(".pw-weak"),(i=n.find(".pw-checkbox")).on("change",function(){d.prop("disabled",!i.prop("checked"))}),(a=o("#pass1")).length?(l=a.val(),1===parseInt(a.data("reveal"),10)&&f(),a.on("input pwupdate",function(){a.val()!==l&&(l=a.val(),a.removeClass("short bad good strong"),g())})):a=o("#user_pass"),t=o("#pass2").on("input",function(){0]*>/gi,""),t[s].length&&-1===o.inArray(e,a)&&(a.push(e),o("

'+s.message+"

")}).fail(function(s){e.siblings(".notice").remove(),e.before('

'+s.message+"

")}),s.preventDefault()}),window.generatePassword=f,o(window).on("beforeunload",function(){if(!0===u)return h("Your new password has not been saved.")}),o(document).ready(function(){o(".reset-pass-submit").length&&o(".reset-pass-submit button.wp-generate-pw").trigger("click")})}(jQuery); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index 76ccea18fb..9c39501714 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7-alpha-50152'; +$wp_version = '5.7-alpha-50153'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-login.php b/wp-login.php index 128e3b254c..301424f687 100644 --- a/wp-login.php +++ b/wp-login.php @@ -852,7 +852,7 @@ switch ( $action ) { wp_enqueue_script( 'utils' ); wp_enqueue_script( 'user-profile' ); - login_header( __( 'Reset Password' ), '

' . __( 'Enter your new password below.' ) . '

', $errors ); + login_header( __( 'Reset Password' ), '

' . __( 'Enter your new password below or generate one.' ) . '

', $errors ); ?>
@@ -898,8 +898,9 @@ switch ( $action ) { ?> -

- +

+ +