| 4329 | |
| 4330 | function wp_ajax_wp_privacy_export_personal_data() { |
| 4331 | check_ajax_referer( 'wp-privacy-export-personal-data', 'security' ); |
| 4332 | |
| 4333 | if ( ! current_user_can( 'manage_options' ) ) { |
| 4334 | wp_send_json_error( 'access denied' ); |
| 4335 | } |
| 4336 | |
| 4337 | $email_address = $_POST['email']; |
| 4338 | $exporter_index = $_POST['exporter']; |
| 4339 | $page = $_POST['page']; |
| 4340 | |
| 4341 | /** |
| 4342 | * Filters the array of exporter callbacks. |
| 4343 | * |
| 4344 | * @since 4.9.5. |
| 4345 | * |
| 4346 | * @param array $args { |
| 4347 | * An array of callable exporters of personal data. Default empty array. |
| 4348 | * [ |
| 4349 | * callback string Callable exporter that accepts an email address and |
| 4350 | * a zero-based page and returns an array of name value |
| 4351 | * pairs of personal data |
| 4352 | * exporter_friendly_name string Translated user facing friendly name for the exporter |
| 4353 | * ] |
| 4354 | * } |
| 4355 | */ |
| 4356 | $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); |
| 4357 | |
| 4358 | if ( $exporter_index < 0 ) { |
| 4359 | wp_send_json_error( 'exporter index cannot be negative' ); |
| 4360 | } |
| 4361 | |
| 4362 | if ( $exporter_index > count( $exporters ) - 1 ) { |
| 4363 | wp_send_json_error( 'exporter index out of range' ); |
| 4364 | } |
| 4365 | |
| 4366 | if ( $page < 0 ) { |
| 4367 | wp_send_json_error( 'page index cannot be negative' ); |
| 4368 | } |
| 4369 | |
| 4370 | // Surprisingly, email addresses can contain mutli-byte characters now |
| 4371 | $email_address = trim( mb_strtolower( $email_address ) ); |
| 4372 | |
| 4373 | if ( ! is_email( $email_address ) ) { |
| 4374 | wp_send_json_error( 'a valid email address must be given' ); |
| 4375 | } |
| 4376 | |
| 4377 | $response = call_user_func( $exporters[ $exporter_index ]['callback'], $email_address, $page ); |
| 4378 | |
| 4379 | /** |
| 4380 | * Fires after a personal data exporter has provided data. |
| 4381 | * |
| 4382 | * Allows the export response to be consumed by destinations in addition to Ajax. |
| 4383 | * |
| 4384 | * @since 4.9.5 |
| 4385 | * |
| 4386 | * @param array $response The personal data for the given exporter and page. |
| 4387 | * @param int $exporter_index The index of the exporter that provided this data. |
| 4388 | * @param string $email_address The email address associated with this personal data. |
| 4389 | * @param int $page The zero-based page for this response. |
| 4390 | */ |
| 4391 | do_action( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page ); |
| 4392 | |
| 4393 | wp_send_json_success( $response ); |
| 4394 | } |