| 3380 | |
| 3381 | /** |
| 3382 | * Registers the personal data eraser for comments |
| 3383 | * |
| 3384 | * @since 4.9.6 |
| 3385 | * |
| 3386 | * @param array $erasers An array of personal data erasers. |
| 3387 | * @return array An array of personal data erasers. |
| 3388 | */ |
| 3389 | function wp_register_comment_personal_data_eraser( $erasers ) { |
| 3390 | $erasers[] = array( |
| 3391 | 'eraser_friendly_name' => __( 'WordPress Comments' ), |
| 3392 | 'callback' => 'wp_comments_personal_data_eraser', |
| 3393 | ); |
| 3394 | |
| 3395 | return $erasers; |
| 3396 | } |
| 3397 | |
| 3398 | /** |
| 3399 | * Erases personal data associated with an email address from the comments table. |
| 3400 | * |
| 3401 | * @since 4.9.6 |
| 3402 | * |
| 3403 | * @param string $email_address The comment author email address. |
| 3404 | * @param int $page Comment page. |
| 3405 | * @return array |
| 3406 | */ |
| 3407 | function wp_comments_personal_data_eraser( $email_address, $page = 1 ) { |
| 3408 | |
| 3409 | // Limit us to 500 comments at a time to avoid timing out |
| 3410 | $number = 500; |
| 3411 | $page = (int) $page; |
| 3412 | |
| 3413 | $comments = get_comments( |
| 3414 | array( |
| 3415 | 'author_email' => $email_address, |
| 3416 | 'number' => $number, |
| 3417 | 'paged' => $page, |
| 3418 | 'order_by' => 'comment_ID', |
| 3419 | 'order' => 'ASC', |
| 3420 | 'include_unapproved' => true, |
| 3421 | ) |
| 3422 | ); |
| 3423 | |
| 3424 | // TODO - use anonymization functions for author, author email and IP |
| 3425 | // from 43545 when they become available |
| 3426 | foreach ( (array) $comments as $comment ) { |
| 3427 | $anonymized_comment = array(); |
| 3428 | $anonymized_comment['comment_ID'] = $comment->comment_ID; |
| 3429 | $anonymized_comment['comment_agent'] = ''; |
| 3430 | $anonymized_comment['comment_author'] = __( 'Anonymous' ); |
| 3431 | $anonymized_comment['comment_author_email'] = ''; |
| 3432 | $anonymized_comment['comment_author_IP'] = '0.0.0.0'; |
| 3433 | $anonymized_comment['comment_author_url'] = ''; |
| 3434 | $anonymized_comment['user_id'] = 0; |
| 3435 | wp_update_comment( $anonymized_comment ); |
| 3436 | } |
| 3437 | |
| 3438 | $done = count( $comments ) < $number; |
| 3439 | |
| 3440 | return array( |
| 3441 | 'num_items_removed' => count( $comments ), |
| 3442 | 'num_items_retained' => 0, |
| 3443 | 'messages' => array(), |
| 3444 | 'done' => $done, |
| 3445 | ); |
| 3446 | } |