Make WordPress Core

Ticket #43442: 43442.diff

File 43442.diff, 3.3 KB (added by allendav, 5 years ago)

Builds on fclaussen's patch but makes it pageable and compatible with the ajax in 43637

  • src/wp-includes/comment.php

     
    33113311
    33123312        $comments = get_comments(
    33133313                array(
    3314                         'author_email' => $email_address,
    3315                         'number'       => $number,
    3316                         'paged'        => $page,
    3317                         'order_by'     => 'comment_ID',
    3318                         'order'        => 'ASC',
     3314                        'author_email'       => $email_address,
     3315                        'number'             => $number,
     3316                        'paged'              => $page,
     3317                        'order_by'           => 'comment_ID',
     3318                        'order'              => 'ASC',
    33193319                )
    33203320        );
    33213321
     
    33753375                'done' => $done,
    33763376        );
    33773377}
     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 */
     3385function 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 */
     3401function 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}
  • 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 );