Make WordPress Core

Ticket #43440: 43440.2.diff

File 43440.2.diff, 3.1 KB (added by allendav, 6 years ago)

Comment exporter ported from 43438

  • src/wp-includes/comment.php

     
    32743274
    32753275        return get_comment( $comment_id );
    32763276}
     3277
     3278/**
     3279 * Registers the personal data exporter for comments
     3280 *
     3281 * @param array   $exporters   An array of personal data exporters.
     3282 * @return array  An array of personal data exporters.
     3283 */
     3284function wp_register_comment_personal_data_exporter( $exporters ) {
     3285        $exporters[] = array(
     3286                'exporter_friendly_name' => __( 'WordPress Comments' ),
     3287                'callback'               => 'wp_comments_personal_data_exporter',
     3288        );
     3289
     3290        return $exporters;
     3291}
     3292
     3293/**
     3294 * Finds and exports data which could be used to identify a person from comments assocated with an email address.
     3295 *
     3296 * @param string  $email  The comment author email address.
     3297 * @param int     $page   Comment page, zero based.
     3298 * @return array  An array of personal data in name value pairs
     3299 */
     3300function wp_comments_personal_data_exporter( $email_address, $page ) {
     3301
     3302        $personal_data = array();
     3303
     3304        // Technically, strtolower isn't necessary since get_comments will match email insensitive
     3305        // But it is a good example for plugin developers whose targets might not be as generous
     3306        $email_address = trim( strtolower( $email_address ) );
     3307
     3308        // Limit us to 100 comments at a time to avoid timing out
     3309        $number = 100;
     3310        $offset = $number * (int) $page;
     3311
     3312        $comments = get_comments(
     3313                array(
     3314                        'author_email' => $email_address,
     3315                        'number'       => $number,
     3316                        'offset'       => $offset,
     3317                        'order_by'     => 'comment_ID',
     3318                        'order'        => 'ASC',
     3319                )
     3320        );
     3321
     3322        $comment_personal_data_props = array(
     3323                'comment_author'       => __( 'Comment Author' ),
     3324                'comment_author_email' => __( 'Comment Author Email' ),
     3325                'comment_author_url'   => __( 'Comment Author URL' ),
     3326                'comment_author_IP'    => __( 'Comment Author IP' ),
     3327                'comment_agent'        => __( 'Comment Agent' ),
     3328        );
     3329
     3330        foreach ( (array) $comments as $comment ) {
     3331                foreach ( (array) $comment_personal_data_props as $key => $name ) {
     3332                        $value = $comment->$key;
     3333                        if ( ! empty( $value ) ) {
     3334                                $personal_data[] = array(
     3335                                        'name'  => $name,
     3336                                        'value' => $value,
     3337                                );
     3338                        }
     3339                }
     3340        }
     3341
     3342        $done = count( $comments ) <= 0;
     3343
     3344        return array(
     3345                'data' => $personal_data,
     3346                'done' => $done,
     3347        );
     3348}
  • src/wp-includes/default-filters.php

     
    328328add_action( 'do_pings', 'do_all_pings', 10, 1 );
    329329add_action( 'do_robots', 'do_robots' );
    330330add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 3 );
     331add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter', 10 );
    331332add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' );
    332333add_action( 'admin_print_scripts', 'print_emoji_detection_script' );
    333334add_action( 'admin_print_scripts', 'print_head_scripts', 20 );