diff --git a/src/wp-admin/css/forms.css b/src/wp-admin/css/forms.css index 9cbace6040..ab0a1cfc6e 100644 --- a/src/wp-admin/css/forms.css +++ b/src/wp-admin/css/forms.css @@ -1132,6 +1132,18 @@ table.form-table td .updated p { border-left-color: #d64d21; } +.privacy_requests .request-results .notice { + margin: -2px 0 0; +} + +.privacy_requests .request-results .notice p { + margin: 0.5em 0; +} + +.request-results td { + padding: 0 0 1px; +} + .status-label { font-weight: 600; } diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php index 501aba3b14..7694889b44 100644 --- a/src/wp-admin/includes/user.php +++ b/src/wp-admin/includes/user.php @@ -663,7 +663,6 @@ function _wp_personal_data_handle_actions() { 'updated' ); } - } elseif ( isset( $_POST['action'] ) ) { $action = isset( $_POST['action'] ) ? sanitize_key( wp_unslash( $_POST['action'] ) ) : ''; // WPCS: input var ok, CSRF ok. @@ -760,7 +759,7 @@ function _wp_personal_data_cleanup_requests() { 'posts_per_page' => -1, 'post_status' => 'request-pending', 'fields' => 'ids', - 'date_query' => array( + 'date_query' => array( array( 'column' => 'post_modified_gmt', 'before' => $expires . ' seconds ago', @@ -1112,7 +1111,7 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table { * @return array */ protected function get_views() { - $current_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ): ''; + $current_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : ''; $statuses = _wp_privacy_statuses(); $views = array(); $admin_url = admin_url( 'tools.php?page=' . $this->request_type ); @@ -1151,7 +1150,7 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table { public function process_bulk_action() { $action = $this->current_action(); $request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array(); // WPCS: input var ok, CSRF ok. - $count = 0; + $count = 0; if ( $request_ids ) { check_admin_referer( 'bulk-privacy_requests' ); @@ -1168,6 +1167,7 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table { add_settings_error( 'bulk_action', 'bulk_action', + /* translators: %d: number of requests */ sprintf( _n( 'Deleted %d request', 'Deleted %d requests', $count ), $count ), 'updated' ); @@ -1184,6 +1184,7 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table { add_settings_error( 'bulk_action', 'bulk_action', + /* translators: %d: number of requests */ sprintf( _n( 'Re-sent %d request', 'Re-sent %d requests', $count ), $count ), 'updated' ); @@ -1213,7 +1214,7 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table { 'post_type' => $this->post_type, 'post_name__in' => array( $this->request_type ), 'posts_per_page' => $posts_per_page, - 'offset' => isset( $_REQUEST['paged'] ) ? max( 0, absint( $_REQUEST['paged'] ) - 1 ) * $posts_per_page: 0, + 'offset' => isset( $_REQUEST['paged'] ) ? max( 0, absint( $_REQUEST['paged'] ) - 1 ) * $posts_per_page : 0, 'post_status' => 'any', 's' => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '', ); @@ -1305,6 +1306,7 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table { $time_diff = current_time( 'timestamp', true ) - $timestamp; if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) { + /* translators: human readable timestamp */ return sprintf( __( '%s ago' ), human_time_diff( $timestamp ) ); } @@ -1412,21 +1414,21 @@ class WP_Privacy_Data_Export_Requests_Table extends WP_Privacy_Requests_Table { $request_id = $item->ID; $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); - $download_data_markup = '
'; - $download_data_markup .= '' . __( 'Download Personal Data' ) . '' . - '' . - '' . - ''; + $download_data_markup .= '' . + '' . + '' . + ''; $download_data_markup .= '
'; $row_actions = array( - 'download_data' => $download_data_markup, + 'download-data' => $download_data_markup, ); return sprintf( '%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) ); @@ -1452,7 +1454,7 @@ class WP_Privacy_Data_Export_Requests_Table extends WP_Privacy_Requests_Table { $request_id = $item->ID; $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); - echo '
'; ?> - - - - + + + + '; @@ -1473,9 +1475,9 @@ class WP_Privacy_Data_Export_Requests_Table extends WP_Privacy_Requests_Table { break; case 'request-completed': echo '' . esc_html__( 'Remove request' ) . ''; + 'action' => 'delete', + 'request_id' => array( $item->ID ), + ), admin_url( 'tools.php?page=export_personal_data' ) ), 'bulk-privacy_requests' ) ) . '" class="button">' . esc_html__( 'Remove request' ) . ''; break; } } @@ -1524,20 +1526,20 @@ class WP_Privacy_Data_Removal_Requests_Table extends WP_Privacy_Requests_Table { $request_id = $item->ID; $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); - $remove_data_markup = '
'; - $remove_data_markup .= '' . __( 'Force Erase Personal Data' ) . '' . - '' . - ''; + $remove_data_markup .= '' . + '' . + ''; $remove_data_markup .= '
'; $row_actions = array( - 'remove_data' => $remove_data_markup, + 'remove-data' => $remove_data_markup, ); } @@ -1564,7 +1566,7 @@ class WP_Privacy_Data_Removal_Requests_Table extends WP_Privacy_Requests_Table { $request_id = $item->ID; $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); - echo '
'; ?> - - - + + + '; @@ -1585,9 +1587,9 @@ class WP_Privacy_Data_Removal_Requests_Table extends WP_Privacy_Requests_Table { break; case 'request-completed': echo '' . esc_html__( 'Remove request' ) . ''; + ), admin_url( 'tools.php?page=remove_personal_data' ) ), 'bulk-privacy_requests' ) ) . '" class="button">' . esc_html__( 'Remove request' ) . ''; break; } } diff --git a/src/wp-admin/js/xfn.js b/src/wp-admin/js/xfn.js index 19f3da4486..d8d28bc7a2 100644 --- a/src/wp-admin/js/xfn.js +++ b/src/wp-admin/js/xfn.js @@ -25,7 +25,7 @@ jQuery( document ).ready(function( $ ) { jQuery( document ).ready( function( $ ) { var strings = window.privacyToolsL10n || {}; - function set_action_state( $action, state ) { + function setActionState( $action, state ) { $action.children().hide(); $action.children( '.' + state ).show(); } @@ -37,13 +37,14 @@ jQuery( document ).ready( function( $ ) { } function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) { + var itemList = ''; + clearResultsAfterRow( $requestRow ); - var itemList = ''; if ( additionalMessages.length ) { $.each( additionalMessages, function( index, value ) { itemList = itemList + '
  • ' + value + '
  • '; - } ); + }); itemList = ''; } @@ -55,41 +56,42 @@ jQuery( document ).ready( function( $ ) { '
    ' + '' + ''; - } ); + }); } - $( '.export_personal_data a' ).click( function( event ) { + $( '.export-personal-data-handle' ).click( function( event ) { + + var $this = $( this ), + $action = $this.parents( '.export-personal-data' ), + $requestRow = $this.parents( 'tr' ), + 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(); - var $this = $( this ); - var $action = $this.parents( '.export_personal_data' ); - var $requestRow = $this.parents( 'tr' ); - var requestID = $action.data( 'request-id' ); - var nonce = $action.data( 'nonce' ); - var exportersCount = $action.data( 'exporters-count' ); - var sendAsEmail = $action.data( 'send-as-email' ) ? true : false; - $action.blur(); clearResultsAfterRow( $requestRow ); - function on_export_done_success( zipUrl ) { - set_action_state( $action, 'export_personal_data_success' ); + function onExportDoneSuccess( zipUrl ) { + setActionState( $action, 'export-personal-data-success' ); if ( 'undefined' !== typeof zipUrl ) { window.location = zipUrl; } else if ( ! sendAsEmail ) { - on_export_failure( strings.noExportFile ); + onExportFailure( strings.noExportFile ); } } - function on_export_failure( errorMessage ) { - set_action_state( $action, 'export_personal_data_failed' ); + function onExportFailure( errorMessage ) { + setActionState( $action, 'export-personal-data-failed' ); if ( errorMessage ) { appendResultsAfterRow( $requestRow, 'notice-error', strings.exportError, [ errorMessage ] ); } } - function do_next_export( exporterIndex, pageIndex ) { + function doNextExport( exporterIndex, pageIndex ) { $.ajax( { url: window.ajaxurl, @@ -104,54 +106,59 @@ jQuery( document ).ready( function( $ ) { method: 'post' } ).done( function( response ) { + var responseData = response.data; + if ( ! response.success ) { + // e.g. invalid request ID - on_export_failure( response.data ); + onExportFailure( response.data ); return; } - var responseData = response.data; + if ( ! responseData.done ) { - setTimeout( do_next_export( exporterIndex, pageIndex + 1 ) ); + setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) ); } else { if ( exporterIndex < exportersCount ) { - setTimeout( do_next_export( exporterIndex + 1, 1 ) ); + setTimeout( doNextExport( exporterIndex + 1, 1 ) ); } else { - on_export_done_success( responseData.url ); + onExportDoneSuccess( responseData.url ); } } - } ).fail( function( jqxhr, textStatus, error ) { + }).fail( function( jqxhr, textStatus, error ) { + // e.g. Nonce failure - on_export_failure( error ); - } ); + onExportFailure( error ); + }); } // And now, let's begin - set_action_state( $action, 'export_personal_data_processing' ); - do_next_export( 1, 1 ); - } ); + setActionState( $action, 'export-personal-data-processing' ); + doNextExport( 1, 1 ); + }); + + $( '.remove-personal-data-handle' ).click( function( event ) { + + var $this = $( this ), + $action = $this.parents( '.remove-personal-data' ), + $requestRow = $this.parents( 'tr' ), + requestID = $action.data( 'request-id' ), + nonce = $action.data( 'nonce' ), + erasersCount = $action.data( 'erasers-count' ), + hasRemoved = false, + hasRetained = false, + messages = []; - $( '.remove_personal_data a' ).click( function( event ) { - event.preventDefault(); event.stopPropagation(); - var $this = $( this ); - var $action = $this.parents( '.remove_personal_data' ); - var $requestRow = $this.parents( 'tr' ); - var requestID = $action.data( 'request-id' ); - var nonce = $action.data( 'nonce' ); - var erasersCount = $action.data( 'erasers-count' ); - - var hasRemoved = false; - var hasRetained = false; - var messages = []; - $action.blur(); clearResultsAfterRow( $requestRow ); - function on_erasure_done_success() { - set_action_state( $action, 'remove_personal_data_idle' ); + function onErasureDoneSuccess() { var summaryMessage = strings.noDataFound; var classes = 'notice-success'; + + setActionState( $action, 'remove-personal-data-idle' ); + if ( false === hasRemoved ) { if ( false === hasRetained ) { summaryMessage = strings.noDataFound; @@ -170,13 +177,13 @@ jQuery( document ).ready( function( $ ) { appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, messages ); } - function on_erasure_failure() { - set_action_state( $action, 'remove_personal_data_failed' ); + function onErasureFailure() { + setActionState( $action, 'remove-personal-data-failed' ); appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] ); } - function do_next_erasure( eraserIndex, pageIndex ) { - $.ajax( { + function doNextErasure( eraserIndex, pageIndex ) { + $.ajax({ url: window.ajaxurl, data: { action: 'wp-privacy-erase-personal-data', @@ -186,12 +193,13 @@ jQuery( document ).ready( function( $ ) { security: nonce }, method: 'post' - } ).done( function( response ) { + }).done( function( response ) { + var responseData = response.data; + if ( ! response.success ) { - on_erasure_failure(); + onErasureFailure(); return; } - var responseData = response.data; if ( responseData.items_removed ) { hasRemoved = hasRemoved || responseData.items_removed; } @@ -202,27 +210,28 @@ jQuery( document ).ready( function( $ ) { messages = messages.concat( responseData.messages ); } if ( ! responseData.done ) { - setTimeout( do_next_erasure( eraserIndex, pageIndex + 1 ) ); + setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) ); } else { if ( eraserIndex < erasersCount ) { - setTimeout( do_next_erasure( eraserIndex + 1, 1 ) ); + setTimeout( doNextErasure( eraserIndex + 1, 1 ) ); } else { - on_erasure_done_success(); + onErasureDoneSuccess(); } } - } ).fail( function() { - on_erasure_failure(); - } ); + }).fail( function() { + onErasureFailure(); + }); } // And now, let's begin - set_action_state( $action, 'remove_personal_data_processing' ); + setActionState( $action, 'remove-personal-data-processing' ); - do_next_erasure( 1, 1 ); - } ); -} ); + doNextErasure( 1, 1 ); + }); +}); ( function( $ ) { + // Privacy policy page, copy button. $( document ).on( 'click', function( event ) { var $target = $( event.target ); @@ -253,4 +262,4 @@ jQuery( document ).ready( function( $ ) { } }); -} )( jQuery ); +} ( jQuery ) ); diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 8c4a2605cd..48b00f49ac 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -3078,7 +3078,7 @@ function _wp_privacy_account_request_confirmed_message( $message, $request_id ) $request = wp_get_user_request_data( $request_id ); if ( $request && in_array( $request->action_name, _wp_privacy_action_request_types(), true ) ) { - $message = '

    ' . __( 'Action has been confirmed.' ) . '

    '; + $message = '

    ' . __( 'Action has been confirmed.' ) . '

    '; $message .= __( 'The site administrator has been notified and will fulfill your request as soon as possible.' ); } @@ -3111,7 +3111,7 @@ function wp_create_user_request( $email_address = '', $action_name = '', $reques } $user = get_user_by( 'email', $email_address ); - $user_id = $user && ! is_wp_error( $user ) ? $user->ID: 0; + $user_id = $user && ! is_wp_error( $user ) ? $user->ID : 0; // Check for duplicates. $requests_query = new WP_Query( array(