| 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 = 0 ) { |
| 3301 | |
| 3302 | // Technically, strtolower isn't necessary since get_comments will match email insensitive |
| 3303 | // But it is a good example for plugin developers whose targets might not be as generous |
| 3304 | $email_address = trim( strtolower( $email_address ) ); |
| 3305 | |
| 3306 | // Limit us to 500 comments at a time to avoid timing out |
| 3307 | $number = 500; |
| 3308 | $offset = $number * (int) $page; |
| 3309 | |
| 3310 | $data_to_export = array(); |
| 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_prop_to_export = 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 | 'comment_date' => __( 'Comment Date' ), |
| 3329 | 'comment_content' => __( 'Comment Content' ), |
| 3330 | 'comment_link' => __( 'Comment URL' ), |
| 3331 | ); |
| 3332 | |
| 3333 | foreach ( (array) $comments as $comment ) { |
| 3334 | $comment_data_to_export = array(); |
| 3335 | |
| 3336 | foreach ( $comment_prop_to_export as $key => $name ) { |
| 3337 | $value = ''; |
| 3338 | |
| 3339 | switch( $key ) { |
| 3340 | case 'comment_author': |
| 3341 | case 'comment_author_email': |
| 3342 | case 'comment_author_url': |
| 3343 | case 'comment_author_IP': |
| 3344 | case 'comment_agent': |
| 3345 | case 'comment_date': |
| 3346 | $value = $comment->$key; |
| 3347 | break; |
| 3348 | |
| 3349 | case 'comment_content': |
| 3350 | $value = get_comment_text( $comment->comment_ID ); |
| 3351 | break; |
| 3352 | |
| 3353 | case 'comment_link': |
| 3354 | $value = get_comment_link( $comment->comment_ID ); |
| 3355 | break; |
| 3356 | } |
| 3357 | |
| 3358 | if ( ! empty( $value ) ) { |
| 3359 | $comment_data_to_export[] = array( 'name' => $name, 'value' => $value ); |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | $data_to_export[] = array( |
| 3364 | 'group_id' => 'comments', |
| 3365 | 'group_label' => __( 'Comments' ), |
| 3366 | 'item_id' => "comment-{$comment->comment_ID}", |
| 3367 | 'data' => $comment_data_to_export, |
| 3368 | ); |
| 3369 | } |
| 3370 | |
| 3371 | $done = count( $comments ) < $number; |
| 3372 | |
| 3373 | return array( |
| 3374 | 'data' => $data_to_export, |
| 3375 | 'done' => $done, |
| 3376 | ); |
| 3377 | } |