Changeset 42994 for trunk/src/wp-includes/comment.php
- Timestamp:
- 04/20/2018 12:18:35 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r42987 r42994 3379 3379 ); 3380 3380 } 3381 3382 /** 3383 * Registers the personal data eraser for comments. 3384 * 3385 * @since 4.9.6 3386 * 3387 * @param array $erasers An array of personal data erasers. 3388 * @return array $erasers An array of personal data erasers. 3389 */ 3390 function wp_register_comment_personal_data_eraser( $erasers ) { 3391 $erasers[] = array( 3392 'eraser_friendly_name' => __( 'WordPress Comments' ), 3393 'callback' => 'wp_comments_personal_data_eraser', 3394 ); 3395 3396 return $erasers; 3397 } 3398 3399 /** 3400 * Erases personal data associated with an email address from the comments table. 3401 * 3402 * @since 4.9.6 3403 * 3404 * @param string $email_address The comment author email address. 3405 * @param int $page Comment page. 3406 * @return array 3407 */ 3408 function wp_comments_personal_data_eraser( $email_address, $page = 1 ) { 3409 global $wpdb; 3410 3411 if ( empty( $email_address ) ) { 3412 return array( 3413 'num_items_removed' => 0, 3414 'num_items_retained' => 0, 3415 'messages' => array(), 3416 'done' => true, 3417 ); 3418 } 3419 3420 // Limit us to 500 comments at a time to avoid timing out. 3421 $number = 500; 3422 $page = (int) $page; 3423 $num_items_removed = 0; 3424 3425 $comments = get_comments( 3426 array( 3427 'author_email' => $email_address, 3428 'number' => $number, 3429 'paged' => $page, 3430 'order_by' => 'comment_ID', 3431 'order' => 'ASC', 3432 'include_unapproved' => true, 3433 ) 3434 ); 3435 3436 $anon_author = __( 'Anonymous' ); 3437 $messages = array(); 3438 3439 foreach ( (array) $comments as $comment ) { 3440 $anonymized_comment = array(); 3441 $anonymized_comment['comment_agent'] = ''; 3442 $anonymized_comment['comment_author'] = $anon_author; 3443 $anonymized_comment['comment_author_email'] = wp_privacy_anonymize_data( 'email', $comment->comment_author_email ); 3444 $anonymized_comment['comment_author_IP'] = wp_privacy_anonymize_data( 'ip', $comment->comment_author_IP ); 3445 $anonymized_comment['comment_author_url'] = wp_privacy_anonymize_data( 'url', $comment->comment_author_url ); 3446 $anonymized_comment['user_id'] = 0; 3447 3448 $comment_id = (int) $comment->comment_ID; 3449 3450 /** 3451 * Filters whether to anonymize the comment. 3452 * 3453 * @since 4.9.6 3454 * 3455 * @param bool|string Whether to apply the comment anonymization (bool). 3456 * Custom prevention message (string). Default true. 3457 * @param WP_Comment $comment WP_Comment object. 3458 * @param array $anonymized_comment Anonymized comment data. 3459 */ 3460 $anon_message = apply_filters( 'wp_anonymize_comment', true, $comment, $anonymized_comment ); 3461 3462 if ( true !== $anon_message ) { 3463 if ( $anon_message && is_string( $anon_message ) ) { 3464 $messages[] = esc_html( $anon_message ); 3465 } else { 3466 /* translators: %d: Comment ID */ 3467 $messages[] = sprintf( __( 'Comment %d contains personal data but could not be anonymized.' ), $comment_id ); 3468 } 3469 3470 continue; 3471 } 3472 3473 $args = array( 3474 'comment_ID' => $comment_id, 3475 ); 3476 3477 $updated = $wpdb->update( $wpdb->comments, $anonymized_comment, $args ); 3478 3479 if ( $updated ) { 3480 $num_items_removed++; 3481 clean_comment_cache( $comment_id ); 3482 } 3483 } 3484 3485 $done = count( $comments ) < $number; 3486 3487 return array( 3488 'num_items_removed' => $num_items_removed, 3489 'num_items_retained' => count( $comments ) - $num_items_removed, 3490 'messages' => $messages, 3491 'done' => $done, 3492 ); 3493 }
Note: See TracChangeset
for help on using the changeset viewer.