| | 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 | */ |
| | 3284 | function 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 | */ |
| | 3300 | function 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 | } |