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