Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: privacy-tools.js
/**
[0] Fix | Delete
* Interactions used by the User Privacy tools in WordPress.
[1] Fix | Delete
*
[2] Fix | Delete
* @output wp-admin/js/privacy-tools.js
[3] Fix | Delete
*/
[4] Fix | Delete
[5] Fix | Delete
// Privacy request action handling.
[6] Fix | Delete
jQuery( document ).ready( function( $ ) {
[7] Fix | Delete
var __ = wp.i18n.__,
[8] Fix | Delete
copiedNoticeTimeout;
[9] Fix | Delete
[10] Fix | Delete
function setActionState( $action, state ) {
[11] Fix | Delete
$action.children().addClass( 'hidden' );
[12] Fix | Delete
$action.children( '.' + state ).removeClass( 'hidden' );
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
function clearResultsAfterRow( $requestRow ) {
[16] Fix | Delete
$requestRow.removeClass( 'has-request-results' );
[17] Fix | Delete
[18] Fix | Delete
if ( $requestRow.next().hasClass( 'request-results' ) ) {
[19] Fix | Delete
$requestRow.next().remove();
[20] Fix | Delete
}
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) {
[24] Fix | Delete
var itemList = '',
[25] Fix | Delete
resultRowClasses = 'request-results';
[26] Fix | Delete
[27] Fix | Delete
clearResultsAfterRow( $requestRow );
[28] Fix | Delete
[29] Fix | Delete
if ( additionalMessages.length ) {
[30] Fix | Delete
$.each( additionalMessages, function( index, value ) {
[31] Fix | Delete
itemList = itemList + '<li>' + value + '</li>';
[32] Fix | Delete
});
[33] Fix | Delete
itemList = '<ul>' + itemList + '</ul>';
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
$requestRow.addClass( 'has-request-results' );
[37] Fix | Delete
[38] Fix | Delete
if ( $requestRow.hasClass( 'status-request-confirmed' ) ) {
[39] Fix | Delete
resultRowClasses = resultRowClasses + ' status-request-confirmed';
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
if ( $requestRow.hasClass( 'status-request-failed' ) ) {
[43] Fix | Delete
resultRowClasses = resultRowClasses + ' status-request-failed';
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
$requestRow.after( function() {
[47] Fix | Delete
return '<tr class="' + resultRowClasses + '"><th colspan="5">' +
[48] Fix | Delete
'<div class="notice inline notice-alt ' + classes + '">' +
[49] Fix | Delete
'<p>' + summaryMessage + '</p>' +
[50] Fix | Delete
itemList +
[51] Fix | Delete
'</div>' +
[52] Fix | Delete
'</td>' +
[53] Fix | Delete
'</tr>';
[54] Fix | Delete
});
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
$( '.export-personal-data-handle' ).on( 'click', function( event ) {
[58] Fix | Delete
var $this = $( this ),
[59] Fix | Delete
$action = $this.parents( '.export-personal-data' ),
[60] Fix | Delete
$requestRow = $this.parents( 'tr' ),
[61] Fix | Delete
$progress = $requestRow.find( '.export-progress' ),
[62] Fix | Delete
$rowActions = $this.parents( '.row-actions' ),
[63] Fix | Delete
requestID = $action.data( 'request-id' ),
[64] Fix | Delete
nonce = $action.data( 'nonce' ),
[65] Fix | Delete
exportersCount = $action.data( 'exporters-count' ),
[66] Fix | Delete
sendAsEmail = $action.data( 'send-as-email' ) ? true : false;
[67] Fix | Delete
[68] Fix | Delete
event.preventDefault();
[69] Fix | Delete
event.stopPropagation();
[70] Fix | Delete
[71] Fix | Delete
$rowActions.addClass( 'processing' );
[72] Fix | Delete
[73] Fix | Delete
$action.trigger( 'blur' );
[74] Fix | Delete
clearResultsAfterRow( $requestRow );
[75] Fix | Delete
setExportProgress( 0 );
[76] Fix | Delete
[77] Fix | Delete
function onExportDoneSuccess( zipUrl ) {
[78] Fix | Delete
var summaryMessage = __( 'This user&#8217;s personal data export link was sent.' );
[79] Fix | Delete
[80] Fix | Delete
if ( 'undefined' !== typeof zipUrl ) {
[81] Fix | Delete
summaryMessage = __( 'This user&#8217;s personal data export file was downloaded.' );
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
setActionState( $action, 'export-personal-data-success' );
[85] Fix | Delete
[86] Fix | Delete
appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
[87] Fix | Delete
[88] Fix | Delete
if ( 'undefined' !== typeof zipUrl ) {
[89] Fix | Delete
window.location = zipUrl;
[90] Fix | Delete
} else if ( ! sendAsEmail ) {
[91] Fix | Delete
onExportFailure( __( 'No personal data export file was generated.' ) );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
function onExportFailure( errorMessage ) {
[98] Fix | Delete
var summaryMessage = __( 'An error occurred while attempting to export personal data.' );
[99] Fix | Delete
[100] Fix | Delete
setActionState( $action, 'export-personal-data-failed' );
[101] Fix | Delete
[102] Fix | Delete
if ( errorMessage ) {
[103] Fix | Delete
appendResultsAfterRow( $requestRow, 'notice-error', summaryMessage, [ errorMessage ] );
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
function setExportProgress( exporterIndex ) {
[110] Fix | Delete
var progress = ( exportersCount > 0 ? exporterIndex / exportersCount : 0 ),
[111] Fix | Delete
progressString = Math.round( progress * 100 ).toString() + '%';
[112] Fix | Delete
[113] Fix | Delete
$progress.html( progressString );
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
function doNextExport( exporterIndex, pageIndex ) {
[117] Fix | Delete
$.ajax(
[118] Fix | Delete
{
[119] Fix | Delete
url: window.ajaxurl,
[120] Fix | Delete
data: {
[121] Fix | Delete
action: 'wp-privacy-export-personal-data',
[122] Fix | Delete
exporter: exporterIndex,
[123] Fix | Delete
id: requestID,
[124] Fix | Delete
page: pageIndex,
[125] Fix | Delete
security: nonce,
[126] Fix | Delete
sendAsEmail: sendAsEmail
[127] Fix | Delete
},
[128] Fix | Delete
method: 'post'
[129] Fix | Delete
}
[130] Fix | Delete
).done( function( response ) {
[131] Fix | Delete
var responseData = response.data;
[132] Fix | Delete
[133] Fix | Delete
if ( ! response.success ) {
[134] Fix | Delete
// e.g. invalid request ID.
[135] Fix | Delete
setTimeout( function() { onExportFailure( response.data ); }, 500 );
[136] Fix | Delete
return;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
if ( ! responseData.done ) {
[140] Fix | Delete
setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) );
[141] Fix | Delete
} else {
[142] Fix | Delete
setExportProgress( exporterIndex );
[143] Fix | Delete
if ( exporterIndex < exportersCount ) {
[144] Fix | Delete
setTimeout( doNextExport( exporterIndex + 1, 1 ) );
[145] Fix | Delete
} else {
[146] Fix | Delete
setTimeout( function() { onExportDoneSuccess( responseData.url ); }, 500 );
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
}).fail( function( jqxhr, textStatus, error ) {
[150] Fix | Delete
// e.g. Nonce failure.
[151] Fix | Delete
setTimeout( function() { onExportFailure( error ); }, 500 );
[152] Fix | Delete
});
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
// And now, let's begin.
[156] Fix | Delete
setActionState( $action, 'export-personal-data-processing' );
[157] Fix | Delete
doNextExport( 1, 1 );
[158] Fix | Delete
});
[159] Fix | Delete
[160] Fix | Delete
$( '.remove-personal-data-handle' ).on( 'click', function( event ) {
[161] Fix | Delete
var $this = $( this ),
[162] Fix | Delete
$action = $this.parents( '.remove-personal-data' ),
[163] Fix | Delete
$requestRow = $this.parents( 'tr' ),
[164] Fix | Delete
$progress = $requestRow.find( '.erasure-progress' ),
[165] Fix | Delete
$rowActions = $this.parents( '.row-actions' ),
[166] Fix | Delete
requestID = $action.data( 'request-id' ),
[167] Fix | Delete
nonce = $action.data( 'nonce' ),
[168] Fix | Delete
erasersCount = $action.data( 'erasers-count' ),
[169] Fix | Delete
hasRemoved = false,
[170] Fix | Delete
hasRetained = false,
[171] Fix | Delete
messages = [];
[172] Fix | Delete
[173] Fix | Delete
event.preventDefault();
[174] Fix | Delete
event.stopPropagation();
[175] Fix | Delete
[176] Fix | Delete
$rowActions.addClass( 'processing' );
[177] Fix | Delete
[178] Fix | Delete
$action.trigger( 'blur' );
[179] Fix | Delete
clearResultsAfterRow( $requestRow );
[180] Fix | Delete
setErasureProgress( 0 );
[181] Fix | Delete
[182] Fix | Delete
function onErasureDoneSuccess() {
[183] Fix | Delete
var summaryMessage = __( 'No personal data was found for this user.' ),
[184] Fix | Delete
classes = 'notice-success';
[185] Fix | Delete
[186] Fix | Delete
setActionState( $action, 'remove-personal-data-success' );
[187] Fix | Delete
[188] Fix | Delete
if ( false === hasRemoved ) {
[189] Fix | Delete
if ( false === hasRetained ) {
[190] Fix | Delete
summaryMessage = __( 'No personal data was found for this user.' );
[191] Fix | Delete
} else {
[192] Fix | Delete
summaryMessage = __( 'Personal data was found for this user but was not erased.' );
[193] Fix | Delete
classes = 'notice-warning';
[194] Fix | Delete
}
[195] Fix | Delete
} else {
[196] Fix | Delete
if ( false === hasRetained ) {
[197] Fix | Delete
summaryMessage = __( 'All of the personal data found for this user was erased.' );
[198] Fix | Delete
} else {
[199] Fix | Delete
summaryMessage = __( 'Personal data was found for this user but some of the personal data found was not erased.' );
[200] Fix | Delete
classes = 'notice-warning';
[201] Fix | Delete
}
[202] Fix | Delete
}
[203] Fix | Delete
appendResultsAfterRow( $requestRow, classes, summaryMessage, messages );
[204] Fix | Delete
[205] Fix | Delete
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
function onErasureFailure() {
[209] Fix | Delete
var summaryMessage = __( 'An error occurred while attempting to find and erase personal data.' );
[210] Fix | Delete
[211] Fix | Delete
setActionState( $action, 'remove-personal-data-failed' );
[212] Fix | Delete
[213] Fix | Delete
appendResultsAfterRow( $requestRow, 'notice-error', summaryMessage, [] );
[214] Fix | Delete
[215] Fix | Delete
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
function setErasureProgress( eraserIndex ) {
[219] Fix | Delete
var progress = ( erasersCount > 0 ? eraserIndex / erasersCount : 0 ),
[220] Fix | Delete
progressString = Math.round( progress * 100 ).toString() + '%';
[221] Fix | Delete
[222] Fix | Delete
$progress.html( progressString );
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
function doNextErasure( eraserIndex, pageIndex ) {
[226] Fix | Delete
$.ajax({
[227] Fix | Delete
url: window.ajaxurl,
[228] Fix | Delete
data: {
[229] Fix | Delete
action: 'wp-privacy-erase-personal-data',
[230] Fix | Delete
eraser: eraserIndex,
[231] Fix | Delete
id: requestID,
[232] Fix | Delete
page: pageIndex,
[233] Fix | Delete
security: nonce
[234] Fix | Delete
},
[235] Fix | Delete
method: 'post'
[236] Fix | Delete
}).done( function( response ) {
[237] Fix | Delete
var responseData = response.data;
[238] Fix | Delete
[239] Fix | Delete
if ( ! response.success ) {
[240] Fix | Delete
setTimeout( function() { onErasureFailure(); }, 500 );
[241] Fix | Delete
return;
[242] Fix | Delete
}
[243] Fix | Delete
if ( responseData.items_removed ) {
[244] Fix | Delete
hasRemoved = hasRemoved || responseData.items_removed;
[245] Fix | Delete
}
[246] Fix | Delete
if ( responseData.items_retained ) {
[247] Fix | Delete
hasRetained = hasRetained || responseData.items_retained;
[248] Fix | Delete
}
[249] Fix | Delete
if ( responseData.messages ) {
[250] Fix | Delete
messages = messages.concat( responseData.messages );
[251] Fix | Delete
}
[252] Fix | Delete
if ( ! responseData.done ) {
[253] Fix | Delete
setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) );
[254] Fix | Delete
} else {
[255] Fix | Delete
setErasureProgress( eraserIndex );
[256] Fix | Delete
if ( eraserIndex < erasersCount ) {
[257] Fix | Delete
setTimeout( doNextErasure( eraserIndex + 1, 1 ) );
[258] Fix | Delete
} else {
[259] Fix | Delete
setTimeout( function() { onErasureDoneSuccess(); }, 500 );
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
}).fail( function() {
[263] Fix | Delete
setTimeout( function() { onErasureFailure(); }, 500 );
[264] Fix | Delete
});
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
// And now, let's begin.
[268] Fix | Delete
setActionState( $action, 'remove-personal-data-processing' );
[269] Fix | Delete
[270] Fix | Delete
doNextErasure( 1, 1 );
[271] Fix | Delete
});
[272] Fix | Delete
[273] Fix | Delete
// Privacy Policy page, copy action.
[274] Fix | Delete
$( document ).on( 'click', function( event ) {
[275] Fix | Delete
var $parent,
[276] Fix | Delete
range,
[277] Fix | Delete
$target = $( event.target ),
[278] Fix | Delete
copiedNotice = $target.siblings( '.success' );
[279] Fix | Delete
[280] Fix | Delete
clearTimeout( copiedNoticeTimeout );
[281] Fix | Delete
[282] Fix | Delete
if ( $target.is( 'button.privacy-text-copy' ) ) {
[283] Fix | Delete
$parent = $target.closest( '.privacy-settings-accordion-panel' );
[284] Fix | Delete
[285] Fix | Delete
if ( $parent.length ) {
[286] Fix | Delete
try {
[287] Fix | Delete
var documentPosition = document.documentElement.scrollTop,
[288] Fix | Delete
bodyPosition = document.body.scrollTop;
[289] Fix | Delete
[290] Fix | Delete
// Setup copy.
[291] Fix | Delete
window.getSelection().removeAllRanges();
[292] Fix | Delete
[293] Fix | Delete
// Hide tutorial content to remove from copied content.
[294] Fix | Delete
range = document.createRange();
[295] Fix | Delete
$parent.addClass( 'hide-privacy-policy-tutorial' );
[296] Fix | Delete
[297] Fix | Delete
// Copy action.
[298] Fix | Delete
range.selectNodeContents( $parent[0] );
[299] Fix | Delete
window.getSelection().addRange( range );
[300] Fix | Delete
document.execCommand( 'copy' );
[301] Fix | Delete
[302] Fix | Delete
// Reset section.
[303] Fix | Delete
$parent.removeClass( 'hide-privacy-policy-tutorial' );
[304] Fix | Delete
window.getSelection().removeAllRanges();
[305] Fix | Delete
[306] Fix | Delete
// Return scroll position - see #49540.
[307] Fix | Delete
if ( documentPosition > 0 && documentPosition !== document.documentElement.scrollTop ) {
[308] Fix | Delete
document.documentElement.scrollTop = documentPosition;
[309] Fix | Delete
} else if ( bodyPosition > 0 && bodyPosition !== document.body.scrollTop ) {
[310] Fix | Delete
document.body.scrollTop = bodyPosition;
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
// Display and speak notice to indicate action complete.
[314] Fix | Delete
copiedNotice.addClass( 'visible' );
[315] Fix | Delete
wp.a11y.speak( __( 'The suggested policy text has been copied to your clipboard.' ) );
[316] Fix | Delete
[317] Fix | Delete
// Delay notice dismissal.
[318] Fix | Delete
copiedNoticeTimeout = setTimeout( function() {
[319] Fix | Delete
copiedNotice.removeClass( 'visible' );
[320] Fix | Delete
}, 3000 );
[321] Fix | Delete
} catch ( er ) {}
[322] Fix | Delete
}
[323] Fix | Delete
}
[324] Fix | Delete
});
[325] Fix | Delete
[326] Fix | Delete
// Label handling to focus the create page button on Privacy settings page.
[327] Fix | Delete
$( 'body.options-privacy-php label[for=create-page]' ).on( 'click', function( e ) {
[328] Fix | Delete
e.preventDefault();
[329] Fix | Delete
$( 'input#create-page' ).trigger( 'focus' );
[330] Fix | Delete
} );
[331] Fix | Delete
[332] Fix | Delete
// Accordion handling in various new Privacy settings pages.
[333] Fix | Delete
$( '.privacy-settings-accordion' ).on( 'click', '.privacy-settings-accordion-trigger', function() {
[334] Fix | Delete
var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) );
[335] Fix | Delete
[336] Fix | Delete
if ( isExpanded ) {
[337] Fix | Delete
$( this ).attr( 'aria-expanded', 'false' );
[338] Fix | Delete
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', true );
[339] Fix | Delete
} else {
[340] Fix | Delete
$( this ).attr( 'aria-expanded', 'true' );
[341] Fix | Delete
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', false );
[342] Fix | Delete
}
[343] Fix | Delete
} );
[344] Fix | Delete
});
[345] Fix | Delete
[346] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function