Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: application-passwords.js
/**
[0] Fix | Delete
* @output wp-admin/js/application-passwords.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
( function( $ ) {
[4] Fix | Delete
var $appPassSection = $( '#application-passwords-section' ),
[5] Fix | Delete
$newAppPassForm = $appPassSection.find( '.create-application-password' ),
[6] Fix | Delete
$newAppPassField = $newAppPassForm.find( '.input' ),
[7] Fix | Delete
$newAppPassButton = $newAppPassForm.find( '.button' ),
[8] Fix | Delete
$appPassTwrapper = $appPassSection.find( '.application-passwords-list-table-wrapper' ),
[9] Fix | Delete
$appPassTbody = $appPassSection.find( 'tbody' ),
[10] Fix | Delete
$appPassTrNoItems = $appPassTbody.find( '.no-items' ),
[11] Fix | Delete
$removeAllBtn = $( '#revoke-all-application-passwords' ),
[12] Fix | Delete
tmplNewAppPass = wp.template( 'new-application-password' ),
[13] Fix | Delete
tmplAppPassRow = wp.template( 'application-password-row' ),
[14] Fix | Delete
userId = $( '#user_id' ).val();
[15] Fix | Delete
[16] Fix | Delete
$newAppPassButton.on( 'click', function( e ) {
[17] Fix | Delete
e.preventDefault();
[18] Fix | Delete
[19] Fix | Delete
if ( $newAppPassButton.prop( 'aria-disabled' ) ) {
[20] Fix | Delete
return;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
var name = $newAppPassField.val();
[24] Fix | Delete
[25] Fix | Delete
if ( 0 === name.length ) {
[26] Fix | Delete
$newAppPassField.trigger( 'focus' );
[27] Fix | Delete
return;
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
clearNotices();
[31] Fix | Delete
$newAppPassButton.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
/**
[38] Fix | Delete
* Filters the request data used to create a new Application Password.
[39] Fix | Delete
*
[40] Fix | Delete
* @since 5.6.0
[41] Fix | Delete
*
[42] Fix | Delete
* @param {Object} request The request data.
[43] Fix | Delete
* @param {number} userId The id of the user the password is added for.
[44] Fix | Delete
*/
[45] Fix | Delete
request = wp.hooks.applyFilters( 'wp_application_passwords_new_password_request', request, userId );
[46] Fix | Delete
[47] Fix | Delete
wp.apiRequest( {
[48] Fix | Delete
path: '/wp/v2/users/' + userId + '/application-passwords?_locale=user',
[49] Fix | Delete
method: 'POST',
[50] Fix | Delete
data: request
[51] Fix | Delete
} ).always( function() {
[52] Fix | Delete
$newAppPassButton.removeProp( 'aria-disabled' ).removeClass( 'disabled' );
[53] Fix | Delete
} ).done( function( response ) {
[54] Fix | Delete
$newAppPassField.val( '' );
[55] Fix | Delete
$newAppPassButton.prop( 'disabled', false );
[56] Fix | Delete
[57] Fix | Delete
$newAppPassForm.after( tmplNewAppPass( {
[58] Fix | Delete
name: response.name,
[59] Fix | Delete
password: response.password
[60] Fix | Delete
} ) );
[61] Fix | Delete
$( '.new-application-password-notice' ).trigger( 'focus' );
[62] Fix | Delete
[63] Fix | Delete
$appPassTbody.prepend( tmplAppPassRow( response ) );
[64] Fix | Delete
[65] Fix | Delete
$appPassTwrapper.show();
[66] Fix | Delete
$appPassTrNoItems.remove();
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Fires after an application password has been successfully created.
[70] Fix | Delete
*
[71] Fix | Delete
* @since 5.6.0
[72] Fix | Delete
*
[73] Fix | Delete
* @param {Object} response The response data from the REST API.
[74] Fix | Delete
* @param {Object} request The request data used to create the password.
[75] Fix | Delete
*/
[76] Fix | Delete
wp.hooks.doAction( 'wp_application_passwords_created_password', response, request );
[77] Fix | Delete
} ).fail( handleErrorResponse );
[78] Fix | Delete
} );
[79] Fix | Delete
[80] Fix | Delete
$appPassTbody.on( 'click', '.delete', function( e ) {
[81] Fix | Delete
e.preventDefault();
[82] Fix | Delete
[83] Fix | Delete
if ( ! window.confirm( wp.i18n.__( 'Are you sure you want to revoke this password? This action cannot be undone.' ) ) ) {
[84] Fix | Delete
return;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
var $submitButton = $( this ),
[88] Fix | Delete
$tr = $submitButton.closest( 'tr' ),
[89] Fix | Delete
uuid = $tr.data( 'uuid' );
[90] Fix | Delete
[91] Fix | Delete
clearNotices();
[92] Fix | Delete
$submitButton.prop( 'disabled', true );
[93] Fix | Delete
[94] Fix | Delete
wp.apiRequest( {
[95] Fix | Delete
path: '/wp/v2/users/' + userId + '/application-passwords/' + uuid + '?_locale=user',
[96] Fix | Delete
method: 'DELETE'
[97] Fix | Delete
} ).always( function() {
[98] Fix | Delete
$submitButton.prop( 'disabled', false );
[99] Fix | Delete
} ).done( function( response ) {
[100] Fix | Delete
if ( response.deleted ) {
[101] Fix | Delete
if ( 0 === $tr.siblings().length ) {
[102] Fix | Delete
$appPassTwrapper.hide();
[103] Fix | Delete
}
[104] Fix | Delete
$tr.remove();
[105] Fix | Delete
[106] Fix | Delete
addNotice( wp.i18n.__( 'Application password revoked.' ), 'success' ).trigger( 'focus' );
[107] Fix | Delete
}
[108] Fix | Delete
} ).fail( handleErrorResponse );
[109] Fix | Delete
} );
[110] Fix | Delete
[111] Fix | Delete
$removeAllBtn.on( 'click', function( e ) {
[112] Fix | Delete
e.preventDefault();
[113] Fix | Delete
[114] Fix | Delete
if ( ! window.confirm( wp.i18n.__( 'Are you sure you want to revoke all passwords? This action cannot be undone.' ) ) ) {
[115] Fix | Delete
return;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
var $submitButton = $( this );
[119] Fix | Delete
[120] Fix | Delete
clearNotices();
[121] Fix | Delete
$submitButton.prop( 'disabled', true );
[122] Fix | Delete
[123] Fix | Delete
wp.apiRequest( {
[124] Fix | Delete
path: '/wp/v2/users/' + userId + '/application-passwords?_locale=user',
[125] Fix | Delete
method: 'DELETE'
[126] Fix | Delete
} ).always( function() {
[127] Fix | Delete
$submitButton.prop( 'disabled', false );
[128] Fix | Delete
} ).done( function( response ) {
[129] Fix | Delete
if ( response.deleted ) {
[130] Fix | Delete
$appPassTbody.children().remove();
[131] Fix | Delete
$appPassSection.children( '.new-application-password' ).remove();
[132] Fix | Delete
$appPassTwrapper.hide();
[133] Fix | Delete
[134] Fix | Delete
addNotice( wp.i18n.__( 'All application passwords revoked.' ), 'success' ).trigger( 'focus' );
[135] Fix | Delete
}
[136] Fix | Delete
} ).fail( handleErrorResponse );
[137] Fix | Delete
} );
[138] Fix | Delete
[139] Fix | Delete
$appPassSection.on( 'click', '.notice-dismiss', function( e ) {
[140] Fix | Delete
e.preventDefault();
[141] Fix | Delete
var $el = $( this ).parent();
[142] Fix | Delete
$el.removeAttr( 'role' );
[143] Fix | Delete
$el.fadeTo( 100, 0, function () {
[144] Fix | Delete
$el.slideUp( 100, function () {
[145] Fix | Delete
$el.remove();
[146] Fix | Delete
$newAppPassField.trigger( 'focus' );
[147] Fix | Delete
} );
[148] Fix | Delete
} );
[149] Fix | Delete
} );
[150] Fix | Delete
[151] Fix | Delete
// If there are no items, don't display the table yet. If there are, show it.
[152] Fix | Delete
if ( 0 === $appPassTbody.children( 'tr' ).not( $appPassTrNoItems ).length ) {
[153] Fix | Delete
$appPassTwrapper.hide();
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
/**
[157] Fix | Delete
* Handles an error response from the REST API.
[158] Fix | Delete
*
[159] Fix | Delete
* @since 5.6.0
[160] Fix | Delete
*
[161] Fix | Delete
* @param {jqXHR} xhr The XHR object from the ajax call.
[162] Fix | Delete
* @param {string} textStatus The string categorizing the ajax request's status.
[163] Fix | Delete
* @param {string} errorThrown The HTTP status error text.
[164] Fix | Delete
*/
[165] Fix | Delete
function handleErrorResponse( xhr, textStatus, errorThrown ) {
[166] Fix | Delete
var errorMessage = errorThrown;
[167] Fix | Delete
[168] Fix | Delete
if ( xhr.responseJSON && xhr.responseJSON.message ) {
[169] Fix | Delete
errorMessage = xhr.responseJSON.message;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
addNotice( errorMessage, 'error' );
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Displays a message in the Application Passwords section.
[177] Fix | Delete
*
[178] Fix | Delete
* @since 5.6.0
[179] Fix | Delete
*
[180] Fix | Delete
* @param {string} message The message to display.
[181] Fix | Delete
* @param {string} type The notice type. Either 'success' or 'error'.
[182] Fix | Delete
* @returns {jQuery} The notice element.
[183] Fix | Delete
*/
[184] Fix | Delete
function addNotice( message, type ) {
[185] Fix | Delete
var $notice = $( '<div></div>' )
[186] Fix | Delete
.attr( 'role', 'alert' )
[187] Fix | Delete
.attr( 'tabindex', '-1' )
[188] Fix | Delete
.addClass( 'is-dismissible notice notice-' + type )
[189] Fix | Delete
.append( $( '<p></p>' ).text( message ) )
[190] Fix | Delete
.append(
[191] Fix | Delete
$( '<button></button>' )
[192] Fix | Delete
.attr( 'type', 'button' )
[193] Fix | Delete
.addClass( 'notice-dismiss' )
[194] Fix | Delete
.append( $( '<span></span>' ).addClass( 'screen-reader-text' ).text( wp.i18n.__( 'Dismiss this notice.' ) ) )
[195] Fix | Delete
);
[196] Fix | Delete
[197] Fix | Delete
$newAppPassForm.after( $notice );
[198] Fix | Delete
[199] Fix | Delete
return $notice;
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
/**
[203] Fix | Delete
* Clears notice messages from the Application Passwords section.
[204] Fix | Delete
*
[205] Fix | Delete
* @since 5.6.0
[206] Fix | Delete
*/
[207] Fix | Delete
function clearNotices() {
[208] Fix | Delete
$( '.notice', $appPassSection ).remove();
[209] Fix | Delete
}
[210] Fix | Delete
}( jQuery ) );
[211] Fix | Delete
[212] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function