2019-05-26 16:50:53 -04:00
|
|
|
/**
|
|
|
|
* Interactions used by the User Privacy tools in WordPress.
|
|
|
|
*
|
|
|
|
* @output wp-admin/js/privacy-tools.js
|
|
|
|
*/
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Privacy request action handling.
|
2019-05-26 16:50:53 -04:00
|
|
|
jQuery( document ).ready( function( $ ) {
|
2020-07-02 07:11:06 -04:00
|
|
|
var __ = wp.i18n.__,
|
2020-06-30 09:56:03 -04:00
|
|
|
copiedNoticeTimeout;
|
2019-05-26 16:50:53 -04:00
|
|
|
|
|
|
|
function setActionState( $action, state ) {
|
2019-06-04 19:40:55 -04:00
|
|
|
$action.children().addClass( 'hidden' );
|
|
|
|
$action.children( '.' + state ).removeClass( 'hidden' );
|
2019-05-26 16:50:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function clearResultsAfterRow( $requestRow ) {
|
|
|
|
$requestRow.removeClass( 'has-request-results' );
|
|
|
|
|
|
|
|
if ( $requestRow.next().hasClass( 'request-results' ) ) {
|
|
|
|
$requestRow.next().remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) {
|
|
|
|
var itemList = '',
|
|
|
|
resultRowClasses = 'request-results';
|
|
|
|
|
|
|
|
clearResultsAfterRow( $requestRow );
|
|
|
|
|
|
|
|
if ( additionalMessages.length ) {
|
|
|
|
$.each( additionalMessages, function( index, value ) {
|
|
|
|
itemList = itemList + '<li>' + value + '</li>';
|
|
|
|
});
|
|
|
|
itemList = '<ul>' + itemList + '</ul>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$requestRow.addClass( 'has-request-results' );
|
|
|
|
|
|
|
|
if ( $requestRow.hasClass( 'status-request-confirmed' ) ) {
|
|
|
|
resultRowClasses = resultRowClasses + ' status-request-confirmed';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $requestRow.hasClass( 'status-request-failed' ) ) {
|
|
|
|
resultRowClasses = resultRowClasses + ' status-request-failed';
|
|
|
|
}
|
|
|
|
|
|
|
|
$requestRow.after( function() {
|
|
|
|
return '<tr class="' + resultRowClasses + '"><th colspan="5">' +
|
|
|
|
'<div class="notice inline notice-alt ' + classes + '">' +
|
|
|
|
'<p>' + summaryMessage + '</p>' +
|
|
|
|
itemList +
|
|
|
|
'</div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-22 07:32:03 -05:00
|
|
|
$( '.export-personal-data-handle' ).on( 'click', function( event ) {
|
2019-05-26 16:50:53 -04:00
|
|
|
var $this = $( this ),
|
|
|
|
$action = $this.parents( '.export-personal-data' ),
|
|
|
|
$requestRow = $this.parents( 'tr' ),
|
2020-02-10 16:38:08 -05:00
|
|
|
$progress = $requestRow.find( '.export-progress' ),
|
2020-02-29 18:45:07 -05:00
|
|
|
$rowActions = $this.parents( '.row-actions' ),
|
2019-05-26 16:50:53 -04:00
|
|
|
requestID = $action.data( 'request-id' ),
|
|
|
|
nonce = $action.data( 'nonce' ),
|
|
|
|
exportersCount = $action.data( 'exporters-count' ),
|
|
|
|
sendAsEmail = $action.data( 'send-as-email' ) ? true : false;
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2020-02-29 18:45:07 -05:00
|
|
|
$rowActions.addClass( 'processing' );
|
|
|
|
|
2021-02-16 15:25:03 -05:00
|
|
|
$action.trigger( 'blur' );
|
2019-05-26 16:50:53 -04:00
|
|
|
clearResultsAfterRow( $requestRow );
|
2020-02-10 15:19:05 -05:00
|
|
|
setExportProgress( 0 );
|
2019-05-26 16:50:53 -04:00
|
|
|
|
|
|
|
function onExportDoneSuccess( zipUrl ) {
|
2020-10-23 15:33:07 -04:00
|
|
|
var summaryMessage = __( 'This user’s personal data export link was sent.' );
|
|
|
|
|
|
|
|
if ( 'undefined' !== typeof zipUrl ) {
|
|
|
|
summaryMessage = __( 'This user’s personal data export file was downloaded.' );
|
|
|
|
}
|
2019-10-06 02:56:02 -04:00
|
|
|
|
2019-05-26 16:50:53 -04:00
|
|
|
setActionState( $action, 'export-personal-data-success' );
|
2019-10-06 02:56:02 -04:00
|
|
|
|
|
|
|
appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
|
2020-02-10 15:19:05 -05:00
|
|
|
|
2019-05-26 16:50:53 -04:00
|
|
|
if ( 'undefined' !== typeof zipUrl ) {
|
|
|
|
window.location = zipUrl;
|
|
|
|
} else if ( ! sendAsEmail ) {
|
2020-07-02 07:11:06 -04:00
|
|
|
onExportFailure( __( 'No personal data export file was generated.' ) );
|
2019-05-26 16:50:53 -04:00
|
|
|
}
|
2020-02-29 18:45:07 -05:00
|
|
|
|
2020-06-30 09:56:03 -04:00
|
|
|
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
2019-05-26 16:50:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function onExportFailure( errorMessage ) {
|
2020-07-02 07:11:06 -04:00
|
|
|
var summaryMessage = __( 'An error occurred while attempting to export personal data.' );
|
|
|
|
|
2019-05-26 16:50:53 -04:00
|
|
|
setActionState( $action, 'export-personal-data-failed' );
|
2020-07-02 07:11:06 -04:00
|
|
|
|
2019-05-26 16:50:53 -04:00
|
|
|
if ( errorMessage ) {
|
2020-07-02 07:11:06 -04:00
|
|
|
appendResultsAfterRow( $requestRow, 'notice-error', summaryMessage, [ errorMessage ] );
|
2019-05-26 16:50:53 -04:00
|
|
|
}
|
2020-02-29 18:45:07 -05:00
|
|
|
|
2020-06-30 09:56:03 -04:00
|
|
|
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
2019-05-26 16:50:53 -04:00
|
|
|
}
|
|
|
|
|
2020-02-10 15:19:05 -05:00
|
|
|
function setExportProgress( exporterIndex ) {
|
2020-06-30 09:56:03 -04:00
|
|
|
var progress = ( exportersCount > 0 ? exporterIndex / exportersCount : 0 ),
|
|
|
|
progressString = Math.round( progress * 100 ).toString() + '%';
|
|
|
|
|
2020-02-10 15:19:05 -05:00
|
|
|
$progress.html( progressString );
|
|
|
|
}
|
|
|
|
|
2019-05-26 16:50:53 -04:00
|
|
|
function doNextExport( exporterIndex, pageIndex ) {
|
|
|
|
$.ajax(
|
|
|
|
{
|
|
|
|
url: window.ajaxurl,
|
|
|
|
data: {
|
|
|
|
action: 'wp-privacy-export-personal-data',
|
|
|
|
exporter: exporterIndex,
|
|
|
|
id: requestID,
|
|
|
|
page: pageIndex,
|
|
|
|
security: nonce,
|
|
|
|
sendAsEmail: sendAsEmail
|
|
|
|
},
|
|
|
|
method: 'post'
|
|
|
|
}
|
|
|
|
).done( function( response ) {
|
|
|
|
var responseData = response.data;
|
|
|
|
|
|
|
|
if ( ! response.success ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// e.g. invalid request ID.
|
2020-06-30 09:56:03 -04:00
|
|
|
setTimeout( function() { onExportFailure( response.data ); }, 500 );
|
2019-05-26 16:50:53 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! responseData.done ) {
|
|
|
|
setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) );
|
|
|
|
} else {
|
2020-02-29 18:45:07 -05:00
|
|
|
setExportProgress( exporterIndex );
|
2019-05-26 16:50:53 -04:00
|
|
|
if ( exporterIndex < exportersCount ) {
|
|
|
|
setTimeout( doNextExport( exporterIndex + 1, 1 ) );
|
|
|
|
} else {
|
2020-06-30 09:56:03 -04:00
|
|
|
setTimeout( function() { onExportDoneSuccess( responseData.url ); }, 500 );
|
2019-05-26 16:50:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail( function( jqxhr, textStatus, error ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// e.g. Nonce failure.
|
2020-06-30 09:56:03 -04:00
|
|
|
setTimeout( function() { onExportFailure( error ); }, 500 );
|
2019-05-26 16:50:53 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// And now, let's begin.
|
2019-05-26 16:50:53 -04:00
|
|
|
setActionState( $action, 'export-personal-data-processing' );
|
|
|
|
doNextExport( 1, 1 );
|
|
|
|
});
|
|
|
|
|
2021-01-22 07:32:03 -05:00
|
|
|
$( '.remove-personal-data-handle' ).on( 'click', function( event ) {
|
2019-05-26 16:50:53 -04:00
|
|
|
var $this = $( this ),
|
|
|
|
$action = $this.parents( '.remove-personal-data' ),
|
|
|
|
$requestRow = $this.parents( 'tr' ),
|
2020-02-10 16:38:08 -05:00
|
|
|
$progress = $requestRow.find( '.erasure-progress' ),
|
2020-02-29 18:45:07 -05:00
|
|
|
$rowActions = $this.parents( '.row-actions' ),
|
2019-05-26 16:50:53 -04:00
|
|
|
requestID = $action.data( 'request-id' ),
|
|
|
|
nonce = $action.data( 'nonce' ),
|
|
|
|
erasersCount = $action.data( 'erasers-count' ),
|
|
|
|
hasRemoved = false,
|
|
|
|
hasRetained = false,
|
|
|
|
messages = [];
|
|
|
|
|
2020-02-29 18:45:07 -05:00
|
|
|
event.preventDefault();
|
2019-05-26 16:50:53 -04:00
|
|
|
event.stopPropagation();
|
|
|
|
|
2020-02-29 18:45:07 -05:00
|
|
|
$rowActions.addClass( 'processing' );
|
|
|
|
|
2021-02-16 15:25:03 -05:00
|
|
|
$action.trigger( 'blur' );
|
2019-05-26 16:50:53 -04:00
|
|
|
clearResultsAfterRow( $requestRow );
|
2020-02-10 15:19:05 -05:00
|
|
|
setErasureProgress( 0 );
|
2019-05-26 16:50:53 -04:00
|
|
|
|
|
|
|
function onErasureDoneSuccess() {
|
2020-07-02 07:11:06 -04:00
|
|
|
var summaryMessage = __( 'No personal data was found for this user.' ),
|
2020-06-30 09:56:03 -04:00
|
|
|
classes = 'notice-success';
|
2019-05-26 16:50:53 -04:00
|
|
|
|
2019-09-23 15:13:58 -04:00
|
|
|
setActionState( $action, 'remove-personal-data-success' );
|
2019-05-26 16:50:53 -04:00
|
|
|
|
|
|
|
if ( false === hasRemoved ) {
|
|
|
|
if ( false === hasRetained ) {
|
2020-07-02 07:11:06 -04:00
|
|
|
summaryMessage = __( 'No personal data was found for this user.' );
|
2019-05-26 16:50:53 -04:00
|
|
|
} else {
|
2020-07-02 07:11:06 -04:00
|
|
|
summaryMessage = __( 'Personal data was found for this user but was not erased.' );
|
2019-05-26 16:50:53 -04:00
|
|
|
classes = 'notice-warning';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( false === hasRetained ) {
|
2020-07-02 07:11:06 -04:00
|
|
|
summaryMessage = __( 'All of the personal data found for this user was erased.' );
|
2019-05-26 16:50:53 -04:00
|
|
|
} else {
|
2020-07-02 07:11:06 -04:00
|
|
|
summaryMessage = __( 'Personal data was found for this user but some of the personal data found was not erased.' );
|
2019-05-26 16:50:53 -04:00
|
|
|
classes = 'notice-warning';
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 02:56:02 -04:00
|
|
|
appendResultsAfterRow( $requestRow, classes, summaryMessage, messages );
|
2020-02-29 18:45:07 -05:00
|
|
|
|
2020-06-30 09:56:03 -04:00
|
|
|
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
2019-05-26 16:50:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function onErasureFailure() {
|
2020-07-02 07:11:06 -04:00
|
|
|
var summaryMessage = __( 'An error occurred while attempting to find and erase personal data.' );
|
|
|
|
|
2019-05-26 16:50:53 -04:00
|
|
|
setActionState( $action, 'remove-personal-data-failed' );
|
2020-07-02 07:11:06 -04:00
|
|
|
|
|
|
|
appendResultsAfterRow( $requestRow, 'notice-error', summaryMessage, [] );
|
2020-02-29 18:45:07 -05:00
|
|
|
|
2020-06-30 09:56:03 -04:00
|
|
|
setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 );
|
2019-05-26 16:50:53 -04:00
|
|
|
}
|
|
|
|
|
2020-02-10 15:19:05 -05:00
|
|
|
function setErasureProgress( eraserIndex ) {
|
2020-06-30 09:56:03 -04:00
|
|
|
var progress = ( erasersCount > 0 ? eraserIndex / erasersCount : 0 ),
|
|
|
|
progressString = Math.round( progress * 100 ).toString() + '%';
|
|
|
|
|
2020-02-10 15:19:05 -05:00
|
|
|
$progress.html( progressString );
|
|
|
|
}
|
|
|
|
|
2019-05-26 16:50:53 -04:00
|
|
|
function doNextErasure( eraserIndex, pageIndex ) {
|
|
|
|
$.ajax({
|
|
|
|
url: window.ajaxurl,
|
|
|
|
data: {
|
|
|
|
action: 'wp-privacy-erase-personal-data',
|
|
|
|
eraser: eraserIndex,
|
|
|
|
id: requestID,
|
|
|
|
page: pageIndex,
|
|
|
|
security: nonce
|
|
|
|
},
|
|
|
|
method: 'post'
|
|
|
|
}).done( function( response ) {
|
|
|
|
var responseData = response.data;
|
|
|
|
|
|
|
|
if ( ! response.success ) {
|
2020-06-30 09:56:03 -04:00
|
|
|
setTimeout( function() { onErasureFailure(); }, 500 );
|
2019-05-26 16:50:53 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( responseData.items_removed ) {
|
|
|
|
hasRemoved = hasRemoved || responseData.items_removed;
|
|
|
|
}
|
|
|
|
if ( responseData.items_retained ) {
|
|
|
|
hasRetained = hasRetained || responseData.items_retained;
|
|
|
|
}
|
|
|
|
if ( responseData.messages ) {
|
|
|
|
messages = messages.concat( responseData.messages );
|
|
|
|
}
|
|
|
|
if ( ! responseData.done ) {
|
|
|
|
setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) );
|
|
|
|
} else {
|
2020-02-29 18:45:07 -05:00
|
|
|
setErasureProgress( eraserIndex );
|
2019-05-26 16:50:53 -04:00
|
|
|
if ( eraserIndex < erasersCount ) {
|
|
|
|
setTimeout( doNextErasure( eraserIndex + 1, 1 ) );
|
|
|
|
} else {
|
2020-06-30 09:56:03 -04:00
|
|
|
setTimeout( function() { onErasureDoneSuccess(); }, 500 );
|
2019-05-26 16:50:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail( function() {
|
2020-06-30 09:56:03 -04:00
|
|
|
setTimeout( function() { onErasureFailure(); }, 500 );
|
2019-05-26 16:50:53 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// And now, let's begin.
|
2019-05-26 16:50:53 -04:00
|
|
|
setActionState( $action, 'remove-personal-data-processing' );
|
|
|
|
|
|
|
|
doNextErasure( 1, 1 );
|
|
|
|
});
|
|
|
|
|
2020-04-12 10:26:11 -04:00
|
|
|
// Privacy Policy page, copy action.
|
2019-05-26 16:50:53 -04:00
|
|
|
$( document ).on( 'click', function( event ) {
|
2020-04-12 10:26:11 -04:00
|
|
|
var $parent,
|
|
|
|
range,
|
|
|
|
$target = $( event.target ),
|
|
|
|
copiedNotice = $target.siblings( '.success' );
|
2019-05-26 16:50:53 -04:00
|
|
|
|
2020-06-30 09:56:03 -04:00
|
|
|
clearTimeout( copiedNoticeTimeout );
|
|
|
|
|
2019-05-26 16:50:53 -04:00
|
|
|
if ( $target.is( 'button.privacy-text-copy' ) ) {
|
2021-02-02 15:14:03 -05:00
|
|
|
$parent = $target.closest( '.privacy-settings-accordion-panel' );
|
2019-05-26 16:50:53 -04:00
|
|
|
|
2021-02-02 15:14:03 -05:00
|
|
|
if ( $parent.length ) {
|
2019-05-26 16:50:53 -04:00
|
|
|
try {
|
2020-03-03 12:51:05 -05:00
|
|
|
var documentPosition = document.documentElement.scrollTop,
|
|
|
|
bodyPosition = document.body.scrollTop;
|
|
|
|
|
2020-04-12 10:26:11 -04:00
|
|
|
// Setup copy.
|
2019-05-26 16:50:53 -04:00
|
|
|
window.getSelection().removeAllRanges();
|
2020-04-12 10:26:11 -04:00
|
|
|
|
|
|
|
// Hide tutorial content to remove from copied content.
|
2019-05-26 16:50:53 -04:00
|
|
|
range = document.createRange();
|
2021-02-02 15:14:03 -05:00
|
|
|
$parent.addClass( 'hide-privacy-policy-tutorial' );
|
2019-05-26 16:50:53 -04:00
|
|
|
|
2020-04-12 10:26:11 -04:00
|
|
|
// Copy action.
|
2021-02-02 15:14:03 -05:00
|
|
|
range.selectNodeContents( $parent[0] );
|
2019-05-26 16:50:53 -04:00
|
|
|
window.getSelection().addRange( range );
|
|
|
|
document.execCommand( 'copy' );
|
|
|
|
|
2020-04-12 10:26:11 -04:00
|
|
|
// Reset section.
|
2021-02-02 15:14:03 -05:00
|
|
|
$parent.removeClass( 'hide-privacy-policy-tutorial' );
|
2019-05-26 16:50:53 -04:00
|
|
|
window.getSelection().removeAllRanges();
|
2020-03-03 12:51:05 -05:00
|
|
|
|
2020-04-12 10:26:11 -04:00
|
|
|
// Return scroll position - see #49540.
|
2020-03-03 12:51:05 -05:00
|
|
|
if ( documentPosition > 0 && documentPosition !== document.documentElement.scrollTop ) {
|
|
|
|
document.documentElement.scrollTop = documentPosition;
|
|
|
|
} else if ( bodyPosition > 0 && bodyPosition !== document.body.scrollTop ) {
|
|
|
|
document.body.scrollTop = bodyPosition;
|
|
|
|
}
|
2020-04-12 10:26:11 -04:00
|
|
|
|
|
|
|
// Display and speak notice to indicate action complete.
|
|
|
|
copiedNotice.addClass( 'visible' );
|
2021-02-02 15:14:03 -05:00
|
|
|
wp.a11y.speak( __( 'The suggested policy text has been copied to your clipboard.' ) );
|
2020-04-12 10:26:11 -04:00
|
|
|
|
|
|
|
// Delay notice dismissal.
|
2020-06-30 09:56:03 -04:00
|
|
|
copiedNoticeTimeout = setTimeout( function() {
|
|
|
|
copiedNotice.removeClass( 'visible' );
|
|
|
|
}, 3000 );
|
2019-05-26 16:50:53 -04:00
|
|
|
} catch ( er ) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-02-02 15:14:03 -05:00
|
|
|
|
|
|
|
// Label handling to focus the create page button on Privacy settings page.
|
|
|
|
$( 'body.options-privacy-php label[for=create-page]' ).on( 'click', function( e ) {
|
|
|
|
e.preventDefault();
|
2021-02-23 14:45:04 -05:00
|
|
|
$( 'input#create-page' ).trigger( 'focus' );
|
2021-02-02 15:14:03 -05:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Accordion handling in various new Privacy settings pages.
|
|
|
|
$( '.privacy-settings-accordion' ).on( 'click', '.privacy-settings-accordion-trigger', function() {
|
|
|
|
var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) );
|
|
|
|
|
|
|
|
if ( isExpanded ) {
|
|
|
|
$( this ).attr( 'aria-expanded', 'false' );
|
|
|
|
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', true );
|
|
|
|
} else {
|
|
|
|
$( this ).attr( 'aria-expanded', 'true' );
|
|
|
|
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', false );
|
|
|
|
}
|
|
|
|
} );
|
2019-05-26 16:50:53 -04:00
|
|
|
});
|