App Passwords: Correct authorize app action names and signatures.

When App Passwords was introduced, the `wp_authorize_application_password_form` and `wp_application_passwords_approve_app_request_success` hook were mistakenly duplicated and incorrectly documented. This commit corrects the hook names and ensures the correct parameters are passed.

Props johnbillion, engahmeds3ed.
Fixes #52013.

Built from https://develop.svn.wordpress.org/trunk@49920


git-svn-id: http://core.svn.wordpress.org/trunk@49619 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
TimothyBlynJacobs 2021-01-02 22:21:04 +00:00
parent fa88bbfc79
commit 6d3109dd2a
4 changed files with 13 additions and 5 deletions

View File

@ -200,15 +200,19 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
<?php
/**
* Fires in the Authorize Application Password new password section.
* Fires in the Authorize Application Password new password section in the no-JS version.
*
* In most cases, this should be used in combination with the {@see 'wp_application_passwords_approve_app_request_success'}
* action to ensure that both the JS and no-JS variants are handled.
*
* @since 5.6.0
* @since 5.6.1 Corrected action name and signature.
*
* @param string $new_password The newly generated application password.
* @param array $request The array of request data. All arguments are optional and may be empty.
* @param WP_User $user The user authorizing the application.
*/
do_action( 'wp_authorize_application_password_form', $request, $user );
do_action( 'wp_authorize_application_password_form_approved_no_js', $new_password, $request, $user );
?>
<?php else : ?>
<form action="<?php echo esc_url( admin_url( 'authorize-application.php' ) ); ?>" method="post" class="form-wrap">

View File

@ -62,6 +62,9 @@
/**
* Fires when an Authorize Application Password request has been successfully approved.
*
* In most cases, this should be used in combination with the {@see 'wp_authorize_application_password_form_approved_no_js'}
* action to ensure that both the JS and no-JS variants are handled.
*
* @since 5.6.0
*
* @param {Object} response The response from the REST API.
@ -126,13 +129,14 @@
* Fires when an Authorize Application Password request encountered an error when trying to approve the request.
*
* @since 5.6.0
* @since 5.6.1 Corrected action name and signature.
*
* @param {Object|null} error The error from the REST API. May be null if the server did not send proper JSON.
* @param {string} textStatus The status of the request.
* @param {string} errorThrown The error message associated with the response status code.
* @param {jqXHR} jqXHR The underlying jqXHR object that made the request.
*/
wp.hooks.doAction( 'wp_application_passwords_approve_app_request_success', error, textStatus, jqXHR );
wp.hooks.doAction( 'wp_application_passwords_approve_app_request_error', error, textStatus, errorThrown, jqXHR );
} );
} );

View File

@ -1,2 +1,2 @@
/*! This file is auto-generated */
!function(r,l){var o=r("#app_name"),i=r("#approve"),e=r("#reject"),d=o.closest("form"),p={userLogin:l.user_login,successUrl:l.success,rejectUrl:l.reject};i.click(function(e){var n=o.val(),a=r('input[name="app_id"]',d).val();if(e.preventDefault(),!i.prop("aria-disabled"))if(0!==n.length){i.prop("aria-disabled",!0).addClass("disabled");var s={name:n};0<a.length&&(s.app_id=a),s=wp.hooks.applyFilters("wp_application_passwords_approve_app_request",s,p),wp.apiRequest({path:"/wp/v2/users/me/application-passwords?_locale=user",method:"POST",data:s}).done(function(e,a,s){wp.hooks.doAction("wp_application_passwords_approve_app_request_success",e,a,s);var o,p,t,i=l.success;i?(o=i+(-1===i.indexOf("?")?"?":"&")+"site_url="+encodeURIComponent(l.site_url)+"&user_login="+encodeURIComponent(l.user_login)+"&password="+encodeURIComponent(e.password),window.location=o):(p=wp.i18n.sprintf('<label for="new-application-password-value">'+wp.i18n.__("Your new password for %s is:")+"</label>","<strong></strong>")+' <input id="new-application-password-value" type="text" class="code" readonly="readonly" value="" />',t=r("<div></div>").attr("role","alert").attr("tabindex",-1).addClass("notice notice-success notice-alt").append(r("<p></p>").addClass("application-password-display").html(p)).append("<p>"+wp.i18n.__("Be sure to save this in a safe location. You will not be able to retrieve it.")+"</p>"),r("strong",t).text(n),r("input",t).val(e.password),d.replaceWith(t),t.focus())}).fail(function(e,a,s){var o=s,p=null;e.responseJSON&&(p=e.responseJSON).message&&(o=p.message);var t=r("<div></div>").attr("role","alert").addClass("notice notice-error").append(r("<p></p>").text(o));r("h1").after(t),i.removeProp("aria-disabled",!1).removeClass("disabled"),wp.hooks.doAction("wp_application_passwords_approve_app_request_success",p,a,e)})}else o.focus()}),e.click(function(e){e.preventDefault(),wp.hooks.doAction("wp_application_passwords_reject_app",p),window.location=l.reject}),d.on("submit",function(e){e.preventDefault()})}(jQuery,authApp);
!function(n,l){var o=n("#app_name"),r=n("#approve"),e=n("#reject"),d=o.closest("form"),p={userLogin:l.user_login,successUrl:l.success,rejectUrl:l.reject};r.click(function(e){var i=o.val(),a=n('input[name="app_id"]',d).val();if(e.preventDefault(),!r.prop("aria-disabled"))if(0!==i.length){r.prop("aria-disabled",!0).addClass("disabled");var s={name:i};0<a.length&&(s.app_id=a),s=wp.hooks.applyFilters("wp_application_passwords_approve_app_request",s,p),wp.apiRequest({path:"/wp/v2/users/me/application-passwords?_locale=user",method:"POST",data:s}).done(function(e,a,s){wp.hooks.doAction("wp_application_passwords_approve_app_request_success",e,a,s);var o,p,t,r=l.success;r?(o=r+(-1===r.indexOf("?")?"?":"&")+"site_url="+encodeURIComponent(l.site_url)+"&user_login="+encodeURIComponent(l.user_login)+"&password="+encodeURIComponent(e.password),window.location=o):(p=wp.i18n.sprintf('<label for="new-application-password-value">'+wp.i18n.__("Your new password for %s is:")+"</label>","<strong></strong>")+' <input id="new-application-password-value" type="text" class="code" readonly="readonly" value="" />',t=n("<div></div>").attr("role","alert").attr("tabindex",-1).addClass("notice notice-success notice-alt").append(n("<p></p>").addClass("application-password-display").html(p)).append("<p>"+wp.i18n.__("Be sure to save this in a safe location. You will not be able to retrieve it.")+"</p>"),n("strong",t).text(i),n("input",t).val(e.password),d.replaceWith(t),t.focus())}).fail(function(e,a,s){var o=s,p=null;e.responseJSON&&(p=e.responseJSON).message&&(o=p.message);var t=n("<div></div>").attr("role","alert").addClass("notice notice-error").append(n("<p></p>").text(o));n("h1").after(t),r.removeProp("aria-disabled",!1).removeClass("disabled"),wp.hooks.doAction("wp_application_passwords_approve_app_request_error",p,a,s,e)})}else o.focus()}),e.click(function(e){e.preventDefault(),wp.hooks.doAction("wp_application_passwords_reject_app",p),window.location=l.reject}),d.on("submit",function(e){e.preventDefault()})}(jQuery,authApp);

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.7-alpha-49919';
$wp_version = '5.7-alpha-49920';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.