Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: auth-app.js
/**
[0] Fix | Delete
* @output wp-admin/js/auth-app.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/* global authApp */
[4] Fix | Delete
[5] Fix | Delete
( function( $, authApp ) {
[6] Fix | Delete
var $appNameField = $( '#app_name' ),
[7] Fix | Delete
$approveBtn = $( '#approve' ),
[8] Fix | Delete
$rejectBtn = $( '#reject' ),
[9] Fix | Delete
$form = $appNameField.closest( 'form' ),
[10] Fix | Delete
context = {
[11] Fix | Delete
userLogin: authApp.user_login,
[12] Fix | Delete
successUrl: authApp.success,
[13] Fix | Delete
rejectUrl: authApp.reject
[14] Fix | Delete
};
[15] Fix | Delete
[16] Fix | Delete
$approveBtn.on( 'click', function( e ) {
[17] Fix | Delete
var name = $appNameField.val(),
[18] Fix | Delete
appId = $( 'input[name="app_id"]', $form ).val();
[19] Fix | Delete
[20] Fix | Delete
e.preventDefault();
[21] Fix | Delete
[22] Fix | Delete
if ( $approveBtn.prop( 'aria-disabled' ) ) {
[23] Fix | Delete
return;
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
if ( 0 === name.length ) {
[27] Fix | Delete
$appNameField.trigger( 'focus' );
[28] Fix | Delete
return;
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
$approveBtn.prop( 'aria-disabled', true ).addClass( 'disabled' );
[32] Fix | Delete
[33] Fix | Delete
var request = {
[34] Fix | Delete
name: name
[35] Fix | Delete
};
[36] Fix | Delete
[37] Fix | Delete
if ( appId.length > 0 ) {
[38] Fix | Delete
request.app_id = appId;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Filters the request data used to Authorize an Application Password request.
[43] Fix | Delete
*
[44] Fix | Delete
* @since 5.6.0
[45] Fix | Delete
*
[46] Fix | Delete
* @param {Object} request The request data.
[47] Fix | Delete
* @param {Object} context Context about the Application Password request.
[48] Fix | Delete
* @param {string} context.userLogin The user's login username.
[49] Fix | Delete
* @param {string} context.successUrl The URL the user will be redirected to after approving the request.
[50] Fix | Delete
* @param {string} context.rejectUrl The URL the user will be redirected to after rejecting the request.
[51] Fix | Delete
*/
[52] Fix | Delete
request = wp.hooks.applyFilters( 'wp_application_passwords_approve_app_request', request, context );
[53] Fix | Delete
[54] Fix | Delete
wp.apiRequest( {
[55] Fix | Delete
path: '/wp/v2/users/me/application-passwords?_locale=user',
[56] Fix | Delete
method: 'POST',
[57] Fix | Delete
data: request
[58] Fix | Delete
} ).done( function( response, textStatus, jqXHR ) {
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* Fires when an Authorize Application Password request has been successfully approved.
[62] Fix | Delete
*
[63] Fix | Delete
* In most cases, this should be used in combination with the {@see 'wp_authorize_application_password_form_approved_no_js'}
[64] Fix | Delete
* action to ensure that both the JS and no-JS variants are handled.
[65] Fix | Delete
*
[66] Fix | Delete
* @since 5.6.0
[67] Fix | Delete
*
[68] Fix | Delete
* @param {Object} response The response from the REST API.
[69] Fix | Delete
* @param {string} response.password The newly created password.
[70] Fix | Delete
* @param {string} textStatus The status of the request.
[71] Fix | Delete
* @param {jqXHR} jqXHR The underlying jqXHR object that made the request.
[72] Fix | Delete
*/
[73] Fix | Delete
wp.hooks.doAction( 'wp_application_passwords_approve_app_request_success', response, textStatus, jqXHR );
[74] Fix | Delete
[75] Fix | Delete
var raw = authApp.success,
[76] Fix | Delete
url, message, $notice;
[77] Fix | Delete
[78] Fix | Delete
if ( raw ) {
[79] Fix | Delete
url = raw + ( -1 === raw.indexOf( '?' ) ? '?' : '&' ) +
[80] Fix | Delete
'site_url=' + encodeURIComponent( authApp.site_url ) +
[81] Fix | Delete
'&user_login=' + encodeURIComponent( authApp.user_login ) +
[82] Fix | Delete
'&password=' + encodeURIComponent( response.password );
[83] Fix | Delete
[84] Fix | Delete
window.location = url;
[85] Fix | Delete
} else {
[86] Fix | Delete
message = wp.i18n.sprintf(
[87] Fix | Delete
/* translators: %s: Application name. */
[88] Fix | Delete
'<label for="new-application-password-value">' + wp.i18n.__( 'Your new password for %s is:' ) + '</label>',
[89] Fix | Delete
'<strong></strong>'
[90] Fix | Delete
) + ' <input id="new-application-password-value" type="text" class="code" readonly="readonly" value="" />';
[91] Fix | Delete
$notice = $( '<div></div>' )
[92] Fix | Delete
.attr( 'role', 'alert' )
[93] Fix | Delete
.attr( 'tabindex', -1 )
[94] Fix | Delete
.addClass( 'notice notice-success notice-alt' )
[95] Fix | Delete
.append( $( '<p></p>' ).addClass( 'application-password-display' ).html( message ) )
[96] Fix | Delete
.append( '<p>' + wp.i18n.__( 'Be sure to save this in a safe location. You will not be able to retrieve it.' ) + '</p>' );
[97] Fix | Delete
[98] Fix | Delete
// We're using .text() to write the variables to avoid any chance of XSS.
[99] Fix | Delete
$( 'strong', $notice ).text( response.name );
[100] Fix | Delete
$( 'input', $notice ).val( response.password );
[101] Fix | Delete
[102] Fix | Delete
$form.replaceWith( $notice );
[103] Fix | Delete
$notice.trigger( 'focus' );
[104] Fix | Delete
}
[105] Fix | Delete
} ).fail( function( jqXHR, textStatus, errorThrown ) {
[106] Fix | Delete
var errorMessage = errorThrown,
[107] Fix | Delete
error = null;
[108] Fix | Delete
[109] Fix | Delete
if ( jqXHR.responseJSON ) {
[110] Fix | Delete
error = jqXHR.responseJSON;
[111] Fix | Delete
[112] Fix | Delete
if ( error.message ) {
[113] Fix | Delete
errorMessage = error.message;
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
var $notice = $( '<div></div>' )
[118] Fix | Delete
.attr( 'role', 'alert' )
[119] Fix | Delete
.addClass( 'notice notice-error' )
[120] Fix | Delete
.append( $( '<p></p>' ).text( errorMessage ) );
[121] Fix | Delete
[122] Fix | Delete
$( 'h1' ).after( $notice );
[123] Fix | Delete
[124] Fix | Delete
$approveBtn.removeProp( 'aria-disabled', false ).removeClass( 'disabled' );
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* Fires when an Authorize Application Password request encountered an error when trying to approve the request.
[128] Fix | Delete
*
[129] Fix | Delete
* @since 5.6.0
[130] Fix | Delete
* @since 5.6.1 Corrected action name and signature.
[131] Fix | Delete
*
[132] Fix | Delete
* @param {Object|null} error The error from the REST API. May be null if the server did not send proper JSON.
[133] Fix | Delete
* @param {string} textStatus The status of the request.
[134] Fix | Delete
* @param {string} errorThrown The error message associated with the response status code.
[135] Fix | Delete
* @param {jqXHR} jqXHR The underlying jqXHR object that made the request.
[136] Fix | Delete
*/
[137] Fix | Delete
wp.hooks.doAction( 'wp_application_passwords_approve_app_request_error', error, textStatus, errorThrown, jqXHR );
[138] Fix | Delete
} );
[139] Fix | Delete
} );
[140] Fix | Delete
[141] Fix | Delete
$rejectBtn.on( 'click', function( e ) {
[142] Fix | Delete
e.preventDefault();
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Fires when an Authorize Application Password request has been rejected by the user.
[146] Fix | Delete
*
[147] Fix | Delete
* @since 5.6.0
[148] Fix | Delete
*
[149] Fix | Delete
* @param {Object} context Context about the Application Password request.
[150] Fix | Delete
* @param {string} context.userLogin The user's login username.
[151] Fix | Delete
* @param {string} context.successUrl The URL the user will be redirected to after approving the request.
[152] Fix | Delete
* @param {string} context.rejectUrl The URL the user will be redirected to after rejecting the request.
[153] Fix | Delete
*/
[154] Fix | Delete
wp.hooks.doAction( 'wp_application_passwords_reject_app', context );
[155] Fix | Delete
[156] Fix | Delete
// @todo: Make a better way to do this so it feels like less of a semi-open redirect.
[157] Fix | Delete
window.location = authApp.reject;
[158] Fix | Delete
} );
[159] Fix | Delete
[160] Fix | Delete
$form.on( 'submit', function( e ) {
[161] Fix | Delete
e.preventDefault();
[162] Fix | Delete
} );
[163] Fix | Delete
}( jQuery, authApp ) );
[164] Fix | Delete
[165] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function