Privacy: improve `wp_privacy_erase_personal_data()`, return boolean values.

Props ericdaams.
See #43602.
Built from https://develop.svn.wordpress.org/trunk@43061


git-svn-id: http://core.svn.wordpress.org/trunk@42890 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2018-05-01 19:27:22 +00:00
parent f376b6b0c9
commit 2f321e234e
5 changed files with 39 additions and 33 deletions

View File

@ -4564,8 +4564,8 @@ function wp_ajax_wp_privacy_erase_personal_data() {
* Array of personal data exporters.
*
* @type string $callback Callable eraser that accepts an email address and
* a page and returns an array with the number of items
* removed, the number of items retained and any messages
* a page and returns an array with boolean values for
* whether items were removed or retained and any messages
* from the eraser, as well as if additional pages are
* available.
* @type string $exporter_friendly_name Translated user facing friendly name for the eraser.
@ -4632,22 +4632,22 @@ function wp_ajax_wp_privacy_erase_personal_data() {
);
}
if ( ! array_key_exists( 'num_items_removed', $response ) ) {
if ( ! array_key_exists( 'items_removed', $response ) ) {
wp_send_json_error(
sprintf(
/* translators: %1$s: eraser friendly name, %2$d: array index */
__( 'Expected num_items_removed key in response array from %1$s eraser (index %2$d).' ),
__( 'Expected items_removed key in response array from %1$s eraser (index %2$d).' ),
esc_html( $eraser_friendly_name ),
$eraser_index
)
);
}
if ( ! array_key_exists( 'num_items_retained', $response ) ) {
if ( ! array_key_exists( 'items_retained', $response ) ) {
wp_send_json_error(
sprintf(
/* translators: %1$s: eraser friendly name, %2$d: array index */
__( 'Expected num_items_retained key in response array from %1$s eraser (index %2$d).' ),
__( 'Expected items_retained key in response array from %1$s eraser (index %2$d).' ),
esc_html( $eraser_friendly_name ),
$eraser_index
)
@ -4689,10 +4689,10 @@ function wp_ajax_wp_privacy_erase_personal_data() {
} else {
// No erasers, so we're done.
$response = array(
'num_items_removed' => 0,
'num_items_retained' => 0,
'messages' => array(),
'done' => true,
'items_removed' => false,
'items_retained' => false,
'messages' => array(),
'done' => true,
);
}

View File

@ -141,8 +141,8 @@ jQuery( document ).ready( function( $ ) {
var nonce = $action.data( 'nonce' );
var erasersCount = $action.data( 'erasers-count' );
var removedCount = 0;
var retainedCount = 0;
var hasRemoved = false;
var hasRetained = false;
var messages = [];
$action.blur();
@ -152,15 +152,15 @@ jQuery( document ).ready( function( $ ) {
set_action_state( $action, 'remove_personal_data_idle' );
var summaryMessage = strings.noDataFound;
var classes = 'notice-success';
if ( 0 === removedCount ) {
if ( 0 === retainedCount ) {
if ( false === hasRemoved ) {
if ( false === hasRetained ) {
summaryMessage = strings.noDataFound;
} else {
summaryMessage = strings.noneRemoved;
classes = 'notice-warning';
}
} else {
if ( 0 === retainedCount ) {
if ( false === hasRetained ) {
summaryMessage = strings.foundAndRemoved;
} else {
summaryMessage = strings.someNotRemoved;
@ -192,11 +192,11 @@ jQuery( document ).ready( function( $ ) {
return;
}
var responseData = response.data;
if ( responseData.num_items_removed ) {
removedCount += responseData.num_items_removed;
if ( responseData.items_removed ) {
hasRemoved = hasRemoved || responseData.items_removed;
}
if ( responseData.num_items_retained ) {
retainedCount += responseData.num_items_removed;
if ( responseData.items_retained ) {
hasRetained = hasRetained || responseData.items_retained;
}
if ( responseData.messages ) {
messages = messages.concat( responseData.messages );

View File

@ -1 +1 @@
jQuery(document).ready(function(a){a("#link_rel").prop("readonly",!0),a("#linkxfndiv input").bind("click keyup",function(){var b=a("#me").is(":checked"),c="";a("input.valinp").each(function(){b?a(this).prop("disabled",!0).parent().addClass("disabled"):(a(this).removeAttr("disabled").parent().removeClass("disabled"),a(this).is(":checked")&&""!==a(this).val()&&(c+=a(this).val()+" "))}),a("#link_rel").val(b?"me":c.substr(0,c.length-1))})}),jQuery(document).ready(function(a){function b(a,b){a.children().hide(),a.children("."+b).show()}function c(a){a.next().hasClass("request-results")&&a.next().remove()}function d(b,d,e,f){c(b);var g="";f.length&&(a.each(f,function(a,b){g=g+"<li>"+b+"</li>"}),g="<ul>"+g+"</ul>"),b.after(function(){return'<tr class="request-results"><td colspan="5"><div class="notice inline notice-alt '+d+'"><p>'+e+"</p>"+g+"</div></td></tr>"})}var e=window.privacyToolsL10n||{};a(".export_personal_data a").click(function(f){function g(a){b(k,"export_personal_data_success"),"undefined"!=typeof a?window.location=a:p||h(e.noExportFile)}function h(a){b(k,"export_personal_data_failed"),a&&d(l,"notice-error",e.exportError,[a])}function i(b,c){a.ajax({url:window.ajaxurl,data:{action:"wp-privacy-export-personal-data",exporter:b,id:m,page:c,security:n,sendAsEmail:p},method:"post"}).done(function(a){if(!a.success)return void h(a.data);var d=a.data;d.done?b<o?setTimeout(i(b+1,1)):g(d.url):setTimeout(i(b,c+1))}).fail(function(a,b,c){h(c)})}f.preventDefault(),f.stopPropagation();var j=a(this),k=j.parents(".export_personal_data"),l=j.parents("tr"),m=k.data("request-id"),n=k.data("nonce"),o=k.data("exporters-count"),p=!!k.data("send-as-email");k.blur(),c(l),b(k,"export_personal_data_processing"),i(1,1)}),a(".remove_personal_data a").click(function(f){function g(){b(k,"remove_personal_data_idle");var a=e.noDataFound,c="notice-success";0===p?0===q?a=e.noDataFound:(a=e.noneRemoved,c="notice-warning"):0===q?a=e.foundAndRemoved:(a=e.someNotRemoved,c="notice-warning"),d(l,"notice-success",a,[])}function h(){b(k,"remove_personal_data_failed"),d(l,"notice-error",e.removalError,[])}function i(b,c){a.ajax({url:window.ajaxurl,data:{action:"wp-privacy-erase-personal-data",eraser:b,id:m,page:c,security:n},method:"post"}).done(function(a){if(!a.success)return void h();var d=a.data;d.num_items_removed&&(p+=d.num_items_removed),d.num_items_retained&&(q+=d.num_items_removed),d.messages&&(r=r.concat(d.messages)),d.done?b<o?setTimeout(i(b+1,1)):g():setTimeout(i(b,c+1))}).fail(function(){h()})}f.preventDefault(),f.stopPropagation();var j=a(this),k=j.parents(".remove_personal_data"),l=j.parents("tr"),m=k.data("request-id"),n=k.data("nonce"),o=k.data("erasers-count"),p=0,q=0,r=[];k.blur(),c(l),b(k,"remove_personal_data_processing"),i(1,1)})});
jQuery(document).ready(function(a){a("#link_rel").prop("readonly",!0),a("#linkxfndiv input").bind("click keyup",function(){var b=a("#me").is(":checked"),c="";a("input.valinp").each(function(){b?a(this).prop("disabled",!0).parent().addClass("disabled"):(a(this).removeAttr("disabled").parent().removeClass("disabled"),a(this).is(":checked")&&""!==a(this).val()&&(c+=a(this).val()+" "))}),a("#link_rel").val(b?"me":c.substr(0,c.length-1))})}),jQuery(document).ready(function(a){function b(a,b){a.children().hide(),a.children("."+b).show()}function c(a){a.next().hasClass("request-results")&&a.next().remove()}function d(b,d,e,f){c(b);var g="";f.length&&(a.each(f,function(a,b){g=g+"<li>"+b+"</li>"}),g="<ul>"+g+"</ul>"),b.after(function(){return'<tr class="request-results"><td colspan="5"><div class="notice inline notice-alt '+d+'"><p>'+e+"</p>"+g+"</div></td></tr>"})}var e=window.privacyToolsL10n||{};a(".export_personal_data a").click(function(f){function g(a){b(k,"export_personal_data_success"),"undefined"!=typeof a?window.location=a:p||h(e.noExportFile)}function h(a){b(k,"export_personal_data_failed"),a&&d(l,"notice-error",e.exportError,[a])}function i(b,c){a.ajax({url:window.ajaxurl,data:{action:"wp-privacy-export-personal-data",exporter:b,id:m,page:c,security:n,sendAsEmail:p},method:"post"}).done(function(a){if(!a.success)return void h(a.data);var d=a.data;d.done?b<o?setTimeout(i(b+1,1)):g(d.url):setTimeout(i(b,c+1))}).fail(function(a,b,c){h(c)})}f.preventDefault(),f.stopPropagation();var j=a(this),k=j.parents(".export_personal_data"),l=j.parents("tr"),m=k.data("request-id"),n=k.data("nonce"),o=k.data("exporters-count"),p=!!k.data("send-as-email");k.blur(),c(l),b(k,"export_personal_data_processing"),i(1,1)}),a(".remove_personal_data a").click(function(f){function g(){b(k,"remove_personal_data_idle");var a=e.noDataFound,c="notice-success";!1===p?!1===q?a=e.noDataFound:(a=e.noneRemoved,c="notice-warning"):!1===q?a=e.foundAndRemoved:(a=e.someNotRemoved,c="notice-warning"),d(l,"notice-success",a,[])}function h(){b(k,"remove_personal_data_failed"),d(l,"notice-error",e.removalError,[])}function i(b,c){a.ajax({url:window.ajaxurl,data:{action:"wp-privacy-erase-personal-data",eraser:b,id:m,page:c,security:n},method:"post"}).done(function(a){if(!a.success)return void h();var d=a.data;d.items_removed&&(p=p||d.items_removed),d.items_retained&&(q=q||d.items_retained),d.messages&&(r=r.concat(d.messages)),d.done?b<o?setTimeout(i(b+1,1)):g():setTimeout(i(b,c+1))}).fail(function(){h()})}f.preventDefault(),f.stopPropagation();var j=a(this),k=j.parents(".remove_personal_data"),l=j.parents("tr"),m=k.data("request-id"),n=k.data("nonce"),o=k.data("erasers-count"),p=!1,q=!1,r=[];k.blur(),c(l),b(k,"remove_personal_data_processing"),i(1,1)})});

View File

@ -3412,17 +3412,18 @@ function wp_comments_personal_data_eraser( $email_address, $page = 1 ) {
if ( empty( $email_address ) ) {
return array(
'num_items_removed' => 0,
'num_items_retained' => 0,
'messages' => array(),
'done' => true,
'items_removed' => false,
'items_retained' => false,
'messages' => array(),
'done' => true,
);
}
// Limit us to 500 comments at a time to avoid timing out.
$number = 500;
$page = (int) $page;
$num_items_removed = 0;
$number = 500;
$page = (int) $page;
$items_removed = false;
$items_retained = false;
$comments = get_comments(
array(
@ -3469,6 +3470,8 @@ function wp_comments_personal_data_eraser( $email_address, $page = 1 ) {
$messages[] = sprintf( __( 'Comment %d contains personal data but could not be anonymized.' ), $comment_id );
}
$items_retained = true;
continue;
}
@ -3479,17 +3482,20 @@ function wp_comments_personal_data_eraser( $email_address, $page = 1 ) {
$updated = $wpdb->update( $wpdb->comments, $anonymized_comment, $args );
if ( $updated ) {
$num_items_removed++;
$items_removed = true;
clean_comment_cache( $comment_id );
} else {
$items_retained = true;
}
}
$done = count( $comments ) < $number;
return array(
'num_items_removed' => $num_items_removed,
'num_items_retained' => count( $comments ) - $num_items_removed,
'messages' => $messages,
'done' => $done,
'items_removed' => $items_removed,
'items_retained' => $items_retained,
'messages' => $messages,
'done' => $done,
);
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-43060';
$wp_version = '5.0-alpha-43061';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.