Changeset 43074 for branches/4.9/src/wp-admin/includes/ajax-actions.php
- Timestamp:
- 05/01/2018 11:57:42 PM (7 years ago)
- Location:
- branches/4.9
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9
-
branches/4.9/src/wp-admin/includes/ajax-actions.php
r43064 r43074 4018 4018 } 4019 4019 } 4020 4021 function wp_ajax_wp_privacy_export_personal_data() { 4022 // check_ajax_referer( 'wp-privacy-export-personal-data', 'security' ); 4023 4024 if ( ! current_user_can( 'manage_options' ) ) { 4025 wp_send_json_error( 'access denied' ); 4026 } 4027 4028 $email_address = sanitize_text_field( $_POST['email'] ); 4029 $exporter_index = (int) $_POST['exporter']; 4030 $page = (int) $_POST['page']; 4031 4032 /** 4033 * Filters the array of exporter callbacks. 4034 * 4035 * @since 4.9.5. 4036 * 4037 * @param array $args { 4038 * An array of callable exporters of personal data. Default empty array. 4039 * [ 4040 * callback string Callable exporter that accepts an email address and 4041 * a page and returns an array of name => value 4042 * pairs of personal data 4043 * exporter_friendly_name string Translated user facing friendly name for the exporter 4044 * ] 4045 * } 4046 */ 4047 $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); 4048 4049 if ( ! is_array( $exporters ) ) { 4050 wp_send_json_error( 'An exporter has improperly used the registration filter.' ); 4051 } 4052 4053 // Do we have any registered exporters? 4054 if ( 0 < count( $exporters ) ) { 4055 if ( $exporter_index < 1 ) { 4056 wp_send_json_error( 'Exporter index cannot be negative.' ); 4057 } 4058 4059 if ( $exporter_index > count( $exporters ) ) { 4060 wp_send_json_error( 'Exporter index out of range.' ); 4061 } 4062 4063 $index = $exporter_index - 1; 4064 4065 if ( $page < 1 ) { 4066 wp_send_json_error( 'Page index cannot be less than one.' ); 4067 } 4068 4069 // Surprisingly, email addresses can contain mutli-byte characters now 4070 $email_address = trim( mb_strtolower( $email_address ) ); 4071 4072 if ( ! is_email( $email_address ) ) { 4073 wp_send_json_error( 'A valid email address must be given.' ); 4074 } 4075 4076 $exporter = $exporters[ $index ]; 4077 if ( ! is_array( $exporter ) ) { 4078 wp_send_json_error( "Expected an array describing the exporter at index {$exporter_index}." ); 4079 } 4080 if ( ! array_key_exists( 'callback', $exporter ) ) { 4081 wp_send_json_error( "Exporter array at index {$exporter_index} does not include a callback." ); 4082 } 4083 if ( ! is_callable( $exporter['callback'] ) ) { 4084 wp_send_json_error( "Exporter callback at index {$exporter_index} is not a valid callback." ); 4085 } 4086 if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) { 4087 wp_send_json_error( "Exporter array at index {$exporter_index} does not include a friendly name." ); 4088 } 4089 4090 $callback = $exporters[ $index ]['callback']; 4091 $exporter_friendly_name = $exporters[ $index ]['exporter_friendly_name']; 4092 4093 $response = call_user_func( $callback, $email_address, $page ); 4094 if ( is_wp_error( $response ) ) { 4095 wp_send_json_error( $response ); 4096 } 4097 4098 if ( ! is_array( $response ) ) { 4099 wp_send_json_error( "Expected response as an array from exporter: {$exporter_friendly_name}." ); 4100 } 4101 if ( ! array_key_exists( 'data', $response ) ) { 4102 wp_send_json_error( "Expected data in response array from exporter: {$exporter_friendly_name}." ); 4103 } 4104 if ( ! is_array( $response['data'] ) ) { 4105 wp_send_json_error( "Expected data array in response array from exporter: {$exporter_friendly_name}." ); 4106 } 4107 if ( ! array_key_exists( 'done', $response ) ) { 4108 wp_send_json_error( "Expected done (boolean) in response array from exporter: {$exporter_friendly_name}." ); 4109 } 4110 } else { 4111 // No exporters, so we're done 4112 $response = array( 4113 'data' => array(), 4114 'done' => true, 4115 ); 4116 } 4117 4118 /** 4119 * Filters a page of personal data exporter data. Used to build the export report. 4120 * 4121 * Allows the export response to be consumed by destinations in addition to Ajax. 4122 * 4123 * @since 4.9.5 4124 * 4125 * @param array $response The personal data for the given exporter and page. 4126 * @param int $exporter_index The index of the exporter that provided this data. 4127 * @param string $email_address The email address associated with this personal data. 4128 * @param int $page The zero-based page for this response. 4129 */ 4130 $response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page ); 4131 if ( is_wp_error( $response ) ) { 4132 wp_send_json_error( $response ); 4133 } 4134 4135 wp_send_json_success( $response ); 4136 }
Note: See TracChangeset
for help on using the changeset viewer.