/** * @output wp-admin/js/auth-app.js */ /* global authApp */ ( function( $, authApp ) { var $appNameField = $( '#app_name' ), $approveBtn = $( '#approve' ), $rejectBtn = $( '#reject' ), $form = $appNameField.closest( 'form' ), context = { userLogin: authApp.user_login, successUrl: authApp.success, rejectUrl: authApp.reject }; $approveBtn.on( 'click', function( e ) { var name = $appNameField.val(), appId = $( 'input[name="app_id"]', $form ).val(); e.preventDefault(); if ( $approveBtn.prop( 'aria-disabled' ) ) { return; } if ( 0 === name.length ) { $appNameField.trigger( 'focus' ); return; } $approveBtn.prop( 'aria-disabled', true ).addClass( 'disabled' ); var request = { name: name }; if ( appId.length > 0 ) { request.app_id = appId; } /** * Filters the request data used to Authorize an Application Password request. * * @since 5.6.0 * * @param {Object} request The request data. * @param {Object} context Context about the Application Password request. * @param {string} context.userLogin The user's login username. * @param {string} context.successUrl The URL the user will be redirected to after approving the request. * @param {string} context.rejectUrl The URL the user will be redirected to after rejecting the request. */ request = wp.hooks.applyFilters( 'wp_application_passwords_approve_app_request', request, context ); wp.apiRequest( { path: '/wp/v2/users/me/application-passwords?_locale=user', method: 'POST', data: request } ).done( function( response, textStatus, jqXHR ) { /** * 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. * @param {string} response.password The newly created password. * @param {string} textStatus The status of the request. * @param {jqXHR} jqXHR The underlying jqXHR object that made the request. */ wp.hooks.doAction( 'wp_application_passwords_approve_app_request_success', response, textStatus, jqXHR ); var raw = authApp.success, url, message, $notice; if ( raw ) { url = raw + ( -1 === raw.indexOf( '?' ) ? '?' : '&' ) + 'site_url=' + encodeURIComponent( authApp.site_url ) + '&user_login=' + encodeURIComponent( authApp.user_login ) + '&password=' + encodeURIComponent( response.password ); window.location = url; } else { message = wp.i18n.sprintf( /* translators: %s: Application name. */ '<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="" />'; $notice = $( '<div></div>' ) .attr( 'role', 'alert' ) .attr( 'tabindex', -1 ) .addClass( 'notice notice-success notice-alt' ) .append( $( '<p></p>' ).addClass( 'application-password-display' ).html( message ) ) .append( '<p>' + wp.i18n.__( 'Be sure to save this in a safe location. You will not be able to retrieve it.' ) + '</p>' ); // We're using .text() to write the variables to avoid any chance of XSS. $( 'strong', $notice ).text( response.name ); $( 'input', $notice ).val( response.password ); $form.replaceWith( $notice ); $notice.trigger( 'focus' ); } } ).fail( function( jqXHR, textStatus, errorThrown ) { var errorMessage = errorThrown, error = null; if ( jqXHR.responseJSON ) { error = jqXHR.responseJSON; if ( error.message ) { errorMessage = error.message; } } var $notice = $( '<div></div>' ) .attr( 'role', 'alert' ) .addClass( 'notice notice-error' ) .append( $( '<p></p>' ).text( errorMessage ) ); $( 'h1' ).after( $notice ); $approveBtn.removeProp( 'aria-disabled', false ).removeClass( 'disabled' ); /** * 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_error', error, textStatus, errorThrown, jqXHR ); } ); } ); $rejectBtn.on( 'click', function( e ) { e.preventDefault(); /** * Fires when an Authorize Application Password request has been rejected by the user. * * @since 5.6.0 * * @param {Object} context Context about the Application Password request. * @param {string} context.userLogin The user's login username. * @param {string} context.successUrl The URL the user will be redirected to after approving the request. * @param {string} context.rejectUrl The URL the user will be redirected to after rejecting the request. */ wp.hooks.doAction( 'wp_application_passwords_reject_app', context ); // @todo: Make a better way to do this so it feels like less of a semi-open redirect. window.location = authApp.reject; } ); $form.on( 'submit', function( e ) { e.preventDefault(); } ); }( jQuery, authApp ) );
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
widgets | Folder | 0755 |
|
|
accordion.js | File | 2.86 KB | 0644 |
|
accordion.min.js | File | 758 B | 0644 |
|
application-passwords.js | File | 6.24 KB | 0644 |
|
application-passwords.min.js | File | 2.95 KB | 0644 |
|
auth-app.js | File | 5.66 KB | 0644 |
|
auth-app.min.js | File | 2.04 KB | 0644 |
|
code-editor.js | File | 11.32 KB | 0644 |
|
code-editor.min.js | File | 3.01 KB | 0644 |
|
color-picker.js | File | 9.54 KB | 0644 |
|
color-picker.min.js | File | 3.4 KB | 0644 |
|
comment.js | File | 2.85 KB | 0644 |
|
comment.min.js | File | 1.28 KB | 0644 |
|
common.js | File | 60.79 KB | 0644 |
|
common.min.js | File | 22.95 KB | 0644 |
|
custom-background.js | File | 3.35 KB | 0644 |
|
custom-background.min.js | File | 1.18 KB | 0644 |
|
custom-header.js | File | 1.98 KB | 0644 |
|
customize-controls.js | File | 287.18 KB | 0644 |
|
customize-controls.min.js | File | 108.98 KB | 0644 |
|
customize-nav-menus.js | File | 109.7 KB | 0644 |
|
customize-nav-menus.min.js | File | 46.2 KB | 0644 |
|
customize-widgets.js | File | 70.05 KB | 0644 |
|
customize-widgets.min.js | File | 27.41 KB | 0644 |
|
dashboard.js | File | 26.92 KB | 0644 |
|
dashboard.min.js | File | 8.59 KB | 0644 |
|
edit-comments.js | File | 36.67 KB | 0644 |
|
edit-comments.min.js | File | 15.01 KB | 0644 |
|
editor-expand.js | File | 41.61 KB | 0644 |
|
editor-expand.min.js | File | 13.14 KB | 0644 |
|
editor.js | File | 43.98 KB | 0644 |
|
editor.min.js | File | 12.76 KB | 0644 |
|
farbtastic.js | File | 7.67 KB | 0644 |
|
gallery.js | File | 5.41 KB | 0644 |
|
gallery.min.js | File | 3.65 KB | 0644 |
|
image-edit.js | File | 39.98 KB | 0644 |
|
image-edit.min.js | File | 15.15 KB | 0644 |
|
inline-edit-post.js | File | 20.17 KB | 0644 |
|
inline-edit-post.min.js | File | 9.41 KB | 0644 |
|
inline-edit-tax.js | File | 7.61 KB | 0644 |
|
inline-edit-tax.min.js | File | 2.93 KB | 0644 |
|
iris.min.js | File | 23.09 KB | 0644 |
|
language-chooser.js | File | 890 B | 0644 |
|
language-chooser.min.js | File | 423 B | 0644 |
|
link.js | File | 3.89 KB | 0644 |
|
link.min.js | File | 1.7 KB | 0644 |
|
media-gallery.js | File | 1.27 KB | 0644 |
|
media-gallery.min.js | File | 611 B | 0644 |
|
media-upload.js | File | 3.38 KB | 0644 |
|
media-upload.min.js | File | 1.13 KB | 0644 |
|
media.js | File | 6.61 KB | 0644 |
|
media.min.js | File | 2.38 KB | 0644 |
|
nav-menu.js | File | 58.73 KB | 0644 |
|
nav-menu.min.js | File | 29.17 KB | 0644 |
|
password-strength-meter.js | File | 4.14 KB | 0644 |
|
password-strength-meter.min.js | File | 1.1 KB | 0644 |
|
password-toggle.js | File | 1.31 KB | 0644 |
|
password-toggle.min.js | File | 847 B | 0644 |
|
plugin-install.js | File | 6.92 KB | 0644 |
|
plugin-install.min.js | File | 2.35 KB | 0644 |
|
post.js | File | 38.64 KB | 0644 |
|
post.min.js | File | 18.38 KB | 0644 |
|
postbox.js | File | 18.4 KB | 0644 |
|
postbox.min.js | File | 6.55 KB | 0644 |
|
privacy-tools.js | File | 10.67 KB | 0644 |
|
privacy-tools.min.js | File | 5.03 KB | 0644 |
|
revisions.js | File | 33.92 KB | 0644 |
|
revisions.min.js | File | 17.97 KB | 0644 |
|
set-post-thumbnail.js | File | 876 B | 0644 |
|
set-post-thumbnail.min.js | File | 620 B | 0644 |
|
site-health.js | File | 13.15 KB | 0644 |
|
site-health.min.js | File | 6.13 KB | 0644 |
|
site-icon.js | File | 6.1 KB | 0644 |
|
site-icon.min.js | File | 2.2 KB | 0644 |
|
svg-painter.js | File | 3.2 KB | 0644 |
|
svg-painter.min.js | File | 1.53 KB | 0644 |
|
tags-box.js | File | 10.88 KB | 0644 |
|
tags-box.min.js | File | 3 KB | 0644 |
|
tags-suggest.js | File | 5.64 KB | 0644 |
|
tags-suggest.min.js | File | 2.22 KB | 0644 |
|
tags.js | File | 4.77 KB | 0644 |
|
tags.min.js | File | 1.96 KB | 0644 |
|
theme-plugin-editor.js | File | 24.79 KB | 0644 |
|
theme-plugin-editor.min.js | File | 11.46 KB | 0644 |
|
theme.js | File | 54.65 KB | 0644 |
|
theme.min.js | File | 26.4 KB | 0644 |
|
updates.js | File | 109.29 KB | 0644 |
|
updates.min.js | File | 47.23 KB | 0644 |
|
user-profile.js | File | 15 KB | 0644 |
|
user-profile.min.js | File | 6.7 KB | 0644 |
|
user-suggest.js | File | 2.25 KB | 0644 |
|
user-suggest.min.js | File | 676 B | 0644 |
|
widgets.js | File | 22.56 KB | 0644 |
|
widgets.min.js | File | 12.31 KB | 0644 |
|
word-count.js | File | 7.52 KB | 0644 |
|
word-count.min.js | File | 1.49 KB | 0644 |
|
xfn.js | File | 740 B | 0644 |
|
xfn.min.js | File | 458 B | 0644 |
|