diff --git a/src/js/_enqueues/admin/auth-app.js b/src/js/_enqueues/admin/auth-app.js index 808bb0754b..3152ed3c5c 100644 --- a/src/js/_enqueues/admin/auth-app.js +++ b/src/js/_enqueues/admin/auth-app.js @@ -16,7 +16,8 @@ }; $approveBtn.click( function( e ) { - var name = $appNameField.val(); + var name = $appNameField.val(), + appId = $( 'input[name="app_id"]', $form ).val(); e.preventDefault(); @@ -32,6 +33,10 @@ name: name }; + if ( appId.length > 0 ) { + request.app_id = appId; + } + /** * Filters the request data used to Authorize an Application Password request. * diff --git a/src/wp-admin/authorize-application.php b/src/wp-admin/authorize-application.php index 88804b7d74..b9cc0c0aac 100644 --- a/src/wp-admin/authorize-application.php +++ b/src/wp-admin/authorize-application.php @@ -18,6 +18,7 @@ if ( isset( $_POST['action'] ) && 'authorize_application_password' === $_POST['a $success_url = $_POST['success_url']; $reject_url = $_POST['reject_url']; $app_name = $_POST['app_name']; + $app_id = $_POST['app_id']; $redirect = ''; if ( isset( $_POST['reject'] ) ) { @@ -27,7 +28,13 @@ if ( isset( $_POST['action'] ) && 'authorize_application_password' === $_POST['a $redirect = admin_url(); } } elseif ( isset( $_POST['approve'] ) ) { - $created = WP_Application_Passwords::create_new_application_password( get_current_user_id(), array( 'name' => $app_name ) ); + $created = WP_Application_Passwords::create_new_application_password( + get_current_user_id(), + array( + 'name' => $app_name, + 'app_id' => $app_id, + ) + ); if ( is_wp_error( $created ) ) { $error = $created; @@ -56,6 +63,7 @@ if ( isset( $_POST['action'] ) && 'authorize_application_password' === $_POST['a $title = __( 'Authorize Application' ); $app_name = ! empty( $_REQUEST['app_name'] ) ? $_REQUEST['app_name'] : ''; +$app_id = ! empty( $_REQUEST['app_id'] ) ? $_REQUEST['app_id'] : ''; $success_url = ! empty( $_REQUEST['success_url'] ) ? $_REQUEST['success_url'] : null; if ( ! empty( $_REQUEST['reject_url'] ) ) { @@ -68,7 +76,7 @@ if ( ! empty( $_REQUEST['reject_url'] ) ) { $user = wp_get_current_user(); -$request = compact( 'app_name', 'success_url', 'reject_url' ); +$request = compact( 'app_name', 'app_id', 'success_url', 'reject_url' ); $is_valid = wp_is_authorize_application_password_request_valid( $request, $user ); if ( is_wp_error( $is_valid ) ) { @@ -183,6 +191,7 @@ require_once ABSPATH . 'wp-admin/admin-header.php';