Ticket #43929: 43929.4.diff
File 43929.4.diff, 16.4 KB (added by , 6 years ago) |
---|
-
src/wp-admin/includes/user.php
760 760 'posts_per_page' => -1, 761 761 'post_status' => 'request-pending', 762 762 'fields' => 'ids', 763 'date_query' => array(763 'date_query' => array( 764 764 array( 765 765 'column' => 'post_modified_gmt', 766 766 'before' => $expires . ' seconds ago', … … 1151 1151 public function process_bulk_action() { 1152 1152 $action = $this->current_action(); 1153 1153 $request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array(); // WPCS: input var ok, CSRF ok. 1154 $count = 0;1154 $count = 0; 1155 1155 1156 1156 if ( $request_ids ) { 1157 1157 check_admin_referer( 'bulk-privacy_requests' ); … … 1168 1168 add_settings_error( 1169 1169 'bulk_action', 1170 1170 'bulk_action', 1171 /* translators: %d: number of requests */ 1171 1172 sprintf( _n( 'Deleted %d request', 'Deleted %d requests', $count ), $count ), 1172 1173 'updated' 1173 1174 ); … … 1184 1185 add_settings_error( 1185 1186 'bulk_action', 1186 1187 'bulk_action', 1188 /* translators: %d: number of requests */ 1187 1189 sprintf( _n( 'Re-sent %d request', 'Re-sent %d requests', $count ), $count ), 1188 1190 'updated' 1189 1191 ); … … 1305 1307 $time_diff = current_time( 'timestamp', true ) - $timestamp; 1306 1308 1307 1309 if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) { 1310 /* translators: human readable timestamp */ 1308 1311 return sprintf( __( '%s ago' ), human_time_diff( $timestamp ) ); 1309 1312 } 1310 1313 … … 1412 1415 $request_id = $item->ID; 1413 1416 $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); 1414 1417 1415 $download_data_markup = '<div class="export _personal_data" ' .1418 $download_data_markup = '<div class="export-personal-data" ' . 1416 1419 'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' . 1417 1420 'data-request-id="' . esc_attr( $request_id ) . '" ' . 1418 1421 'data-nonce="' . esc_attr( $nonce ) . 1419 1422 '">'; 1420 1423 1421 $download_data_markup .= '<span class="export _personal_data_idle"><a href="#" >' . __( 'Download Personal Data' ) . '</a></span>' .1422 '<span style="display:none" class="export _personal_data_processing" >' . __( 'Downloading Data...' ) . '</span>' .1423 '<span style="display:none" class="export _personal_data_success"><a href="#" >' . __( 'Download Personal Data Again' ) . '</a></span>' .1424 '<span style="display:none" class="export _personal_data_failed">' . __( 'Download has failed.' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';1424 $download_data_markup .= '<span class="export-personal-data-idle"><button type="button" class="button-link export-personal-data-handle">' . __( 'Download Personal Data' ) . '</button></span>' . 1425 '<span style="display:none" class="export-personal-data-processing" >' . __( 'Downloading Data...' ) . '</span>' . 1426 '<span style="display:none" class="export-personal-data-success"><button type="button" class="button-link export-personal-data-handle">' . __( 'Download Personal Data Again' ) . '</button></span>' . 1427 '<span style="display:none" class="export-personal-data-failed">' . __( 'Download has failed.' ) . ' <button type="button" class="button-link">' . __( 'Retry' ) . '</button></span>'; 1425 1428 1426 1429 $download_data_markup .= '</div>'; 1427 1430 1428 1431 $row_actions = array( 1429 'download _data' => $download_data_markup,1432 'download-data' => $download_data_markup, 1430 1433 ); 1431 1434 1432 1435 return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) ); … … 1452 1455 $request_id = $item->ID; 1453 1456 $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); 1454 1457 1455 echo '<div class="export _personal_data" ' .1458 echo '<div class="export-personal-data" ' . 1456 1459 'data-send-as-email="1" ' . 1457 1460 'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' . 1458 1461 'data-request-id="' . esc_attr( $request_id ) . '" ' . … … 1460 1463 '">'; 1461 1464 1462 1465 ?> 1463 <span class="export _personal_data_idle"><a class="button" href="#" ><?php _e( 'Send Export Link' ); ?></a></span>1464 <span style="display:none" class="export _personal_data_processing button updating-message" ><?php _e( 'Sending Email...' ); ?></span>1465 <span style="display:none" class="export _personal_data_success success-message" ><?php _e( 'Email sent.' ); ?></span>1466 <span style="display:none" class="export _personal_data_failed"><?php _e( 'Email could not be sent.' ); ?> <a class="button" href="#" ><?php _e( 'Retry' ); ?></a></span>1466 <span class="export-personal-data-idle"><button type="button" class="button export-personal-data-handle"><?php _e( 'Email Data' ); ?></button></span> 1467 <span style="display:none" class="export-personal-data-processing button updating-message" ><?php _e( 'Sending Email...' ); ?></span> 1468 <span style="display:none" class="export-personal-data-success success-message" ><?php _e( 'Email sent.' ); ?></span> 1469 <span style="display:none" class="export-personal-data-failed"><?php _e( 'Email could not be sent.' ); ?> <button type="button" class="button export-personal-data-handle"><?php _e( 'Retry' ); ?></button></span> 1467 1470 <?php 1468 1471 1469 1472 echo '</div>'; … … 1473 1476 break; 1474 1477 case 'request-completed': 1475 1478 echo '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 1476 'action' => 'delete',1479 'action' => 'delete', 1477 1480 'request_id' => array( $item->ID ) 1478 1481 ), admin_url( 'tools.php?page=export_personal_data' ) ), 'bulk-privacy_requests' ) ) . '">' . esc_html__( 'Remove request' ) . '</a>'; 1479 1482 break; … … 1524 1527 $request_id = $item->ID; 1525 1528 $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); 1526 1529 1527 $remove_data_markup = '<div class="remove _personal_data force_remove_personal_data" ' .1530 $remove_data_markup = '<div class="remove-personal-data force-remove-personal-data" ' . 1528 1531 'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' . 1529 1532 'data-request-id="' . esc_attr( $request_id ) . '" ' . 1530 1533 'data-nonce="' . esc_attr( $nonce ) . 1531 1534 '">'; 1532 1535 1533 $remove_data_markup .= '<span class="remove _personal_data_idle"><a href="#" >' . __( 'Force Erase Personal Data' ) . '</a></span>' .1534 '<span style="display:none" class="remove _personal_data_processing" >' . __( 'Erasing Data...' ) . '</span>' .1535 '<span style="display:none" class="remove_personal_data_failed">' . __( 'Force Erase has failed.' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';1536 $remove_data_markup .= '<span class="remove-personal-data-idle"><button type="button" class="button-link remove-personal-data-handle">' . __( 'Force Remove Personal Data' ) . '</button></span>' . 1537 '<span style="display:none" class="remove-personal-data-processing" >' . __( 'Erasing Data...' ) . '</span>' . 1538 '<span style="display:none" class="remove-personal-data-failed">' . __( 'Force Erase has failed.' ) . ' <button type="button" class="button-link remove-personal-data-handle">' . __( 'Retry' ) . '</button></span>'; 1536 1539 1537 1540 $remove_data_markup .= '</div>'; 1538 1541 1539 1542 $row_actions = array( 1540 'remove _data' => $remove_data_markup,1543 'remove-data' => $remove_data_markup, 1541 1544 ); 1542 1545 } 1543 1546 … … 1564 1567 $request_id = $item->ID; 1565 1568 $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); 1566 1569 1567 echo '<div class="remove _personal_data" ' .1570 echo '<div class="remove-personal-data" ' . 1568 1571 'data-force-erase="1" ' . 1569 1572 'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' . 1570 1573 'data-request-id="' . esc_attr( $request_id ) . '" ' . … … 1572 1575 '">'; 1573 1576 1574 1577 ?> 1575 <span class="remove _personal_data_idle"><a class="button" href="#" ><?php _e( 'Erase Personal Data' ); ?></a></span>1576 <span style="display:none" class="remove _personal_data_processing button updating-message" ><?php _e( 'Erasing Data...' ); ?></span>1577 <span style="display:none" class="remove _personal_data_failed"><?php _e( 'Erasing Data has failed.' ); ?> <a class="button" href="#" ><?php _e( 'Retry' ); ?></a></span>1578 <span class="remove-personal-data-idle"><button type="button" class="button remove-personal-data-handle"><?php _e( 'Erase Personal Data' ); ?></button></span> 1579 <span style="display:none" class="remove-personal-data-processing button updating-message" ><?php _e( 'Erasing Data...' ); ?></span> 1580 <span style="display:none" class="remove-personal-data-failed"><?php _e( 'Erasing Data has failed.' ); ?> <button type="button" class="button remove-personal-data-handle"><?php _e( 'Retry' ); ?></button></span> 1578 1581 <?php 1579 1582 1580 1583 echo '</div>'; … … 1585 1588 break; 1586 1589 case 'request-completed': 1587 1590 echo '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 1588 'action' => 'delete',1591 'action' => 'delete', 1589 1592 'request_id' => array( $item->ID ), 1590 1593 ), admin_url( 'tools.php?page=remove_personal_data' ) ), 'bulk-privacy_requests' ) ) . '">' . esc_html__( 'Remove request' ) . '</a>'; 1591 1594 break; -
src/wp-admin/js/xfn.js
25 25 jQuery( document ).ready( function( $ ) { 26 26 var strings = window.privacyToolsL10n || {}; 27 27 28 function set _action_state( $action, state ) {28 function setActionState( $action, state ) { 29 29 $action.children().hide(); 30 30 $action.children( '.' + state ).show(); 31 31 } … … 37 37 } 38 38 39 39 function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) { 40 var itemList = ''; 41 40 42 clearResultsAfterRow( $requestRow ); 41 43 42 var itemList = '';43 44 if ( additionalMessages.length ) { 44 45 $.each( additionalMessages, function( index, value ) { 45 46 itemList = itemList + '<li>' + value + '</li>'; 46 } 47 }); 47 48 itemList = '<ul>' + itemList + '</ul>'; 48 49 } 49 50 … … 55 56 '</div>' + 56 57 '</td>' + 57 58 '</tr>'; 58 } 59 }); 59 60 } 60 61 61 $( '.export_personal_data a' ).click( function( event ) { 62 $( '.export-personal-data-handle' ).click( function( event ) { 63 64 var $this = $( this ), 65 $action = $this.parents( '.export-personal-data' ), 66 $requestRow = $this.parents( 'tr' ), 67 requestID = $action.data( 'request-id' ), 68 nonce = $action.data( 'nonce' ), 69 exportersCount = $action.data( 'exporters-count' ), 70 sendAsEmail = $action.data( 'send-as-email' ) ? true : false; 71 62 72 event.preventDefault(); 63 73 event.stopPropagation(); 64 74 65 var $this = $( this );66 var $action = $this.parents( '.export_personal_data' );67 var $requestRow = $this.parents( 'tr' );68 var requestID = $action.data( 'request-id' );69 var nonce = $action.data( 'nonce' );70 var exportersCount = $action.data( 'exporters-count' );71 var sendAsEmail = $action.data( 'send-as-email' ) ? true : false;72 73 75 $action.blur(); 74 76 clearResultsAfterRow( $requestRow ); 75 77 76 function on _export_done_success( zipUrl ) {77 set _action_state( $action, 'export_personal_data_success' );78 function onExportDoneSuccess( zipUrl ) { 79 setActionState( $action, 'export-personal-data-success' ); 78 80 if ( 'undefined' !== typeof zipUrl ) { 79 81 window.location = zipUrl; 80 82 } else if ( ! sendAsEmail ) { 81 on _export_failure( strings.noExportFile );83 onExportFailure( strings.noExportFile ); 82 84 } 83 85 } 84 86 85 function on _export_failure( errorMessage ) {86 set _action_state( $action, 'export_personal_data_failed' );87 function onExportFailure( errorMessage ) { 88 setActionState( $action, 'export-personal-data-failed' ); 87 89 if ( errorMessage ) { 88 90 appendResultsAfterRow( $requestRow, 'notice-error', strings.exportError, [ errorMessage ] ); 89 91 } 90 92 } 91 93 92 function do _next_export( exporterIndex, pageIndex ) {94 function doNextExport( exporterIndex, pageIndex ) { 93 95 $.ajax( 94 96 { 95 97 url: window.ajaxurl, … … 104 106 method: 'post' 105 107 } 106 108 ).done( function( response ) { 109 var responseData = response.data; 110 107 111 if ( ! response.success ) { 112 108 113 // e.g. invalid request ID 109 on _export_failure( response.data );114 onExportFailure( response.data ); 110 115 return; 111 116 } 112 var responseData = response.data; 117 113 118 if ( ! responseData.done ) { 114 setTimeout( do _next_export( exporterIndex, pageIndex + 1 ) );119 setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) ); 115 120 } else { 116 121 if ( exporterIndex < exportersCount ) { 117 setTimeout( do _next_export( exporterIndex + 1, 1 ) );122 setTimeout( doNextExport( exporterIndex + 1, 1 ) ); 118 123 } else { 119 on _export_done_success( responseData.url );124 onExportDoneSuccess( responseData.url ); 120 125 } 121 126 } 122 } ).fail( function( jqxhr, textStatus, error ) { 127 }).fail( function( jqxhr, textStatus, error ) { 128 123 129 // e.g. Nonce failure 124 on _export_failure( error );125 } 130 onExportFailure( error ); 131 }); 126 132 } 127 133 128 134 // And now, let's begin 129 set _action_state( $action, 'export_personal_data_processing' );130 do _next_export( 1, 1 );131 } 135 setActionState( $action, 'export-personal-data-processing' ); 136 doNextExport( 1, 1 ); 137 }); 132 138 133 $( '.remove_personal_data a' ).click( function( event ) { 134 event.preventDefault(); 135 event.stopPropagation(); 139 $( '.remove-personal-data-handle' ).click( function( event ) { 136 140 137 var $this = $( this ); 138 var $action = $this.parents( '.remove_personal_data' ); 139 var $requestRow = $this.parents( 'tr' ); 140 var requestID = $action.data( 'request-id' ); 141 var nonce = $action.data( 'nonce' ); 142 var erasersCount = $action.data( 'erasers-count' ); 141 var $this = $( this ), 142 $action = $this.parents( '.remove-personal-data' ), 143 $requestRow = $this.parents( 'tr' ), 144 requestID = $action.data( 'request-id' ), 145 nonce = $action.data( 'nonce' ), 146 erasersCount = $action.data( 'erasers-count' ), 147 hasRemoved = false, 148 hasRetained = false, 149 messages = []; 143 150 144 var hasRemoved = false; 145 var hasRetained = false; 146 var messages = []; 151 event.stopPropagation(); 147 152 148 153 $action.blur(); 149 154 clearResultsAfterRow( $requestRow ); 150 155 151 function on_erasure_done_success() { 152 set_action_state( $action, 'remove_personal_data_idle' ); 156 function onErasureDoneSuccess() { 153 157 var summaryMessage = strings.noDataFound; 154 158 var classes = 'notice-success'; 159 160 setActionState( $action, 'remove-personal-data-idle' ); 161 155 162 if ( false === hasRemoved ) { 156 163 if ( false === hasRetained ) { 157 164 summaryMessage = strings.noDataFound; … … 170 177 appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, messages ); 171 178 } 172 179 173 function on _erasure_failure() {174 set _action_state( $action, 'remove_personal_data_failed' );180 function onErasureFailure() { 181 setActionState( $action, 'remove-personal-data-failed' ); 175 182 appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] ); 176 183 } 177 184 178 function do _next_erasure( eraserIndex, pageIndex ) {179 $.ajax( 185 function doNextErasure( eraserIndex, pageIndex ) { 186 $.ajax({ 180 187 url: window.ajaxurl, 181 188 data: { 182 189 action: 'wp-privacy-erase-personal-data', … … 186 193 security: nonce 187 194 }, 188 195 method: 'post' 189 } ).done( function( response ) { 196 }).done( function( response ) { 197 var responseData = response.data; 198 190 199 if ( ! response.success ) { 191 on _erasure_failure();200 onErasureFailure(); 192 201 return; 193 202 } 194 var responseData = response.data;195 203 if ( responseData.items_removed ) { 196 204 hasRemoved = hasRemoved || responseData.items_removed; 197 205 } … … 202 210 messages = messages.concat( responseData.messages ); 203 211 } 204 212 if ( ! responseData.done ) { 205 setTimeout( do _next_erasure( eraserIndex, pageIndex + 1 ) );213 setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) ); 206 214 } else { 207 215 if ( eraserIndex < erasersCount ) { 208 setTimeout( do _next_erasure( eraserIndex + 1, 1 ) );216 setTimeout( doNextErasure( eraserIndex + 1, 1 ) ); 209 217 } else { 210 on_erasure_done_success();218 onErasureDoneSuccess(); 211 219 } 212 220 } 213 } 214 on_erasure_failure();215 } 221 }).fail( function() { 222 onErasureFailure(); 223 }); 216 224 } 217 225 218 226 // And now, let's begin 219 set_action_state( $action, 'remove_personal_data_processing' );227 setActionState( $action, 'remove-personal-data-processing' ); 220 228 221 do_next_erasure( 1, 1 );222 } 229 doNextErasure( 1, 1 ); 230 }); 223 231 } ); 224 232 225 233 ( function( $ ) {