WordPress.org

Make WordPress Core

Ticket #43442: 43442.2.diff

File 43442.2.diff, 3.2 KB (added by allendav, 4 years ago)

Updated to match new impl in 43637 (returns number of comments updated per page, etc)

  • src/wp-includes/comment.php

     
    32783278/**
    32793279 * Registers the personal data exporter for comments
    32803280 *
     3281 * @since 4.9.6
     3282 *
    32813283 * @param array   $exporters   An array of personal data exporters.
    32823284 * @return array  An array of personal data exporters.
    32833285 */
     
    33753377                'done' => $done,
    33763378        );
    33773379}
     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 */
     3389function 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 */
     3407function 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}
  • src/wp-includes/default-filters.php

     
    329329add_action( 'do_robots', 'do_robots' );
    330330add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 3 );
    331331add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter', 10 );
     332add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser', 10 );
    332333add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' );
    333334add_action( 'admin_print_scripts', 'print_emoji_detection_script' );
    334335add_action( 'admin_print_scripts', 'print_head_scripts', 20 );