Changeset 43105 for branches/4.9/src/wp-admin/includes/ajax-actions.php
- Timestamp:
- 05/02/2018 03:18:19 AM (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
r43092 r43105 4025 4025 */ 4026 4026 function wp_ajax_wp_privacy_export_personal_data() { 4027 $request_id = (int) $_POST['id']; 4028 4029 if ( empty( $request_id ) ) { 4030 wp_send_json_error( __( 'Error: Invalid request ID.' ) ); 4027 4028 if ( empty( $_POST['id'] ) ) { 4029 wp_send_json_error( __( 'Missing request ID.' ) ); 4030 } 4031 $request_id = (int) $_POST['id']; 4032 4033 if ( $request_id < 1 ) { 4034 wp_send_json_error( __( 'Invalid request ID.' ) ); 4031 4035 } 4032 4036 4033 4037 if ( ! current_user_can( 'manage_options' ) ) { 4034 wp_send_json_error( __( ' Error:Invalid request.' ) );4038 wp_send_json_error( __( 'Invalid request.' ) ); 4035 4039 } 4036 4040 … … 4041 4045 4042 4046 if ( ! $request || 'export_personal_data' !== $request->action_name ) { 4043 wp_send_json_error( __( ' Error:Invalid request type.' ) );4047 wp_send_json_error( __( 'Invalid request type.' ) ); 4044 4048 } 4045 4049 4046 4050 $email_address = $request->email; 4047 4051 if ( ! is_email( $email_address ) ) { 4048 wp_send_json_error( __( 'Error: A valid email address must be given.' ) ); 4049 } 4050 4052 wp_send_json_error( __( 'A valid email address must be given.' ) ); 4053 } 4054 4055 if ( ! isset( $_POST['exporter'] ) ) { 4056 wp_send_json_error( __( 'Missing exporter index.' ) ); 4057 } 4051 4058 $exporter_index = (int) $_POST['exporter']; 4052 $page = (int) $_POST['page']; 4053 $send_as_email = isset( $_POST['sendAsEmail'] ) ? ( "true" === $_POST['sendAsEmail'] ) : false; 4059 4060 if ( ! isset( $_POST['page'] ) ) { 4061 wp_send_json_error( __( 'Missing page index.' ) ); 4062 } 4063 $page = (int) $_POST['page']; 4064 4065 $send_as_email = isset( $_POST['sendAsEmail'] ) ? ( 'true' === $_POST['sendAsEmail'] ) : false; 4054 4066 4055 4067 /** … … 4060 4072 * @param array $args { 4061 4073 * An array of callable exporters of personal data. Default empty array. 4062 * [ 4063 * callback string Callable exporter that accepts an email address and 4064 * a page and returns an array of name => value 4065 * pairs of personal data. 4066 * exporter_friendly_name string Translated user facing friendly name for the exporter. 4067 * ] 4074 * 4075 * @type array { 4076 * Array of personal data exporters. 4077 * 4078 * @type string $callback Callable exporter function that accepts an 4079 * email address and a page and returns an array 4080 * of name => value pairs of personal data. 4081 * @type string $exporter_friendly_name Translated user facing friendly name for the 4082 * exporter. 4083 * } 4068 4084 * } 4069 4085 */ … … 4071 4087 4072 4088 if ( ! is_array( $exporters ) ) { 4073 wp_send_json_error( 'An exporter has improperly used the registration filter.');4089 wp_send_json_error( __( 'An exporter has improperly used the registration filter.' ) ); 4074 4090 } 4075 4091 … … 4077 4093 if ( 0 < count( $exporters ) ) { 4078 4094 if ( $exporter_index < 1 ) { 4079 wp_send_json_error( 'Exporter index cannot be negative.');4095 wp_send_json_error( __( 'Exporter index cannot be negative.' ) ); 4080 4096 } 4081 4097 4082 4098 if ( $exporter_index > count( $exporters ) ) { 4083 wp_send_json_error( 'Exporter index out of range.');4099 wp_send_json_error( __( 'Exporter index out of range.' ) ); 4084 4100 } 4085 4101 … … 4087 4103 4088 4104 if ( $page < 1 ) { 4089 wp_send_json_error( 'Page index cannot be less than one.');4105 wp_send_json_error( __( 'Page index cannot be less than one.' ) ); 4090 4106 } 4091 4107 … … 4093 4109 4094 4110 if ( ! is_array( $exporter ) ) { 4095 wp_send_json_error( "Expected an array describing the exporter at index {$exporter_index}." ); 4111 wp_send_json_error( 4112 /* translators: %d: array index */ 4113 sprintf( __( 'Expected an array describing the exporter at index %d.' ), $exporter_index ) 4114 ); 4096 4115 } 4097 4116 if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) { 4098 wp_send_json_error( "Exporter array at index {$exporter_index} does not include a friendly name." ); 4117 wp_send_json_error( 4118 /* translators: %d: array index */ 4119 sprintf( __( 'Exporter array at index %d does not include a friendly name.' ), $exporter_index ) 4120 ); 4099 4121 } 4100 4122 if ( ! array_key_exists( 'callback', $exporter ) ) { 4101 wp_send_json_error( "Exporter does not include a callback: {$exporter['exporter_friendly_name']}." ); 4123 wp_send_json_error( 4124 /* translators: %s: exporter friendly name */ 4125 sprintf( __( 'Exporter does not include a callback: %s.' ), esc_html( $exporter['exporter_friendly_name'] ) ) 4126 ); 4102 4127 } 4103 4128 if ( ! is_callable( $exporter['callback'] ) ) { 4104 wp_send_json_error( "Exporter callback is not a valid callback: {$exporter['exporter_friendly_name']}." ); 4129 wp_send_json_error( 4130 /* translators: %s: exporter friendly name */ 4131 sprintf( __( 'Exporter callback is not a valid callback: %s.' ), esc_html( $exporter['exporter_friendly_name'] ) ) 4132 ); 4105 4133 } 4106 4134 … … 4114 4142 4115 4143 if ( ! is_array( $response ) ) { 4116 wp_send_json_error( "Expected response as an array from exporter: {$exporter_friendly_name}." ); 4144 wp_send_json_error( 4145 /* translators: %s: exporter friendly name */ 4146 sprintf( __( 'Expected response as an array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) 4147 ); 4117 4148 } 4118 4149 if ( ! array_key_exists( 'data', $response ) ) { 4119 wp_send_json_error( "Expected data in response array from exporter: {$exporter_friendly_name}." ); 4150 wp_send_json_error( 4151 /* translators: %s: exporter friendly name */ 4152 sprintf( __( 'Expected data in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) 4153 ); 4120 4154 } 4121 4155 if ( ! is_array( $response['data'] ) ) { 4122 wp_send_json_error( "Expected data array in response array from exporter: {$exporter_friendly_name}." ); 4156 wp_send_json_error( 4157 /* translators: %s: exporter friendly name */ 4158 sprintf( __( 'Expected data array in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) 4159 ); 4123 4160 } 4124 4161 if ( ! array_key_exists( 'done', $response ) ) { 4125 wp_send_json_error( "Expected done (boolean) in response array from exporter: {$exporter_friendly_name}." ); 4162 wp_send_json_error( 4163 /* translators: %s: exporter friendly name */ 4164 sprintf( __( 'Expected done (boolean) in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) ) 4165 ); 4126 4166 } 4127 4167 } else { … … 4143 4183 * @param int $exporter_index The index of the exporter that provided this data. 4144 4184 * @param string $email_address The email address associated with this personal data. 4145 * @param int $page The zero-basedpage for this response.4185 * @param int $page The page for this response. 4146 4186 * @param int $request_id The privacy request post ID associated with this request. 4147 4187 * @param bool $send_as_email Whether the final results of the export should be emailed to the user. … … 4162 4202 */ 4163 4203 function wp_ajax_wp_privacy_erase_personal_data() { 4164 $request_id = (int) $_POST['id']; 4165 4166 if ( empty( $request_id ) ) { 4167 wp_send_json_error( __( 'Error: Invalid request ID.' ) ); 4204 4205 if ( empty( $_POST['id'] ) ) { 4206 wp_send_json_error( __( 'Missing request ID.' ) ); 4207 } 4208 4209 $request_id = (int) $_POST['id']; 4210 4211 if ( $request_id < 1 ) { 4212 wp_send_json_error( __( 'Invalid request ID.' ) ); 4168 4213 } 4169 4214 4170 4215 if ( ! current_user_can( 'delete_users' ) ) { 4171 wp_send_json_error( __( ' Error:Invalid request.' ) );4216 wp_send_json_error( __( 'Invalid request.' ) ); 4172 4217 } 4173 4218 … … 4178 4223 4179 4224 if ( ! $request || 'remove_personal_data' !== $request->action_name ) { 4180 wp_send_json_error( __( ' Error:Invalid request ID.' ) );4225 wp_send_json_error( __( 'Invalid request ID.' ) ); 4181 4226 } 4182 4227 … … 4184 4229 4185 4230 if ( ! is_email( $email_address ) ) { 4186 wp_send_json_error( __( 'Error: Invalid email address in request.' ) ); 4231 wp_send_json_error( __( 'Invalid email address in request.' ) ); 4232 } 4233 4234 if ( ! isset( $_POST['eraser'] ) ) { 4235 wp_send_json_error( __( 'Missing eraser index.' ) ); 4187 4236 } 4188 4237 4189 4238 $eraser_index = (int) $_POST['eraser']; 4190 $page = (int) $_POST['page']; 4239 4240 if ( ! isset( $_POST['page'] ) ) { 4241 wp_send_json_error( __( 'Missing page index.' ) ); 4242 } 4243 4244 $page = (int) $_POST['page']; 4191 4245 4192 4246 /** … … 4197 4251 * @param array $args { 4198 4252 * An array of callable erasers of personal data. Default empty array. 4199 * [ 4200 * callback string Callable eraser that accepts an email address and 4201 * a page and returns an array with the number of items 4202 * removed, the number of items retained and any messages 4203 * from the eraser, as well as if additional pages are 4204 * available. 4205 * eraser_friendly_name string Translated user facing friendly name for the eraser. 4206 * ] 4253 * @type array { 4254 * Array of personal data exporters. 4255 * 4256 * @type string $callback Callable eraser that accepts an email address and 4257 * a page and returns an array with the number of items 4258 * removed, the number of items retained and any messages 4259 * from the eraser, as well as if additional pages are 4260 * available. 4261 * @type string $exporter_friendly_name Translated user facing friendly name for the eraser. 4262 * } 4207 4263 * } 4208 4264 */ … … 4211 4267 // Do we have any registered erasers? 4212 4268 if ( 0 < count( $erasers ) ) { 4269 4213 4270 if ( $eraser_index < 1 ) { 4214 wp_send_json_error( __( 'Er ror: Eraser index cannot be less than one.' ) );4271 wp_send_json_error( __( 'Eraser index cannot be less than one.' ) ); 4215 4272 } 4216 4273 4217 4274 if ( $eraser_index > count( $erasers ) ) { 4218 wp_send_json_error( __( 'Er ror: Eraser index is out of range.' ) );4275 wp_send_json_error( __( 'Eraser index is out of range.' ) ); 4219 4276 } 4220 4277 4221 4278 if ( $page < 1 ) { 4222 wp_send_json_error( __( ' Error:Page index cannot be less than one.' ) );4223 } 4224 4225 $index = $eraser_index - 1; // Convert to zero based for eraser index4279 wp_send_json_error( __( 'Page index cannot be less than one.' ) ); 4280 } 4281 4282 $index = $eraser_index - 1; // Convert to zero based for eraser index. 4226 4283 $eraser = $erasers[ $index ]; 4284 4227 4285 if ( ! is_array( $eraser ) ) { 4286 /* translators: %d: array index */ 4287 wp_send_json_error( sprintf( __( 'Expected an array describing the eraser at index %d.' ), $eraser_index ) ); 4288 } 4289 4290 if ( ! array_key_exists( 'callback', $eraser ) ) { 4291 /* translators: %d: array index */ 4292 wp_send_json_error( sprintf( __( 'Eraser array at index %d does not include a callback.' ), $eraser_index ) ); 4293 } 4294 4295 if ( ! is_callable( $eraser['callback'] ) ) { 4296 /* translators: %d: array index */ 4297 wp_send_json_error( sprintf( __( 'Eraser callback at index %d is not a valid callback.' ), $eraser_index ) ); 4298 } 4299 4300 if ( ! array_key_exists( 'eraser_friendly_name', $eraser ) ) { 4301 /* translators: %d: array index */ 4302 wp_send_json_error( sprintf( __( 'Eraser array at index %d does not include a friendly name.' ), $eraser_index ) ); 4303 } 4304 4305 $callback = $erasers[ $index ]['callback']; 4306 $eraser_friendly_name = $erasers[ $index ]['eraser_friendly_name']; 4307 4308 $response = call_user_func( $callback, $email_address, $page ); 4309 4310 if ( is_wp_error( $response ) ) { 4311 wp_send_json_error( $response ); 4312 } 4313 4314 if ( ! is_array( $response ) ) { 4228 4315 wp_send_json_error( 4229 4316 sprintf( 4230 __( 'Error: Expected an array describing the eraser at index %d.' ), 4317 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4318 __( 'Did not receive array from %1$s eraser (index %2$d).' ), 4319 esc_html( $eraser_friendly_name ), 4231 4320 $eraser_index 4232 4321 ) 4233 4322 ); 4234 4323 } 4235 if ( ! array_key_exists( 'callback', $eraser ) ) { 4324 4325 if ( ! array_key_exists( 'num_items_removed', $response ) ) { 4236 4326 wp_send_json_error( 4237 4327 sprintf( 4238 __( 'Error: Eraser array at index %d does not include a callback.' ), 4328 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4329 __( 'Expected num_items_removed key in response array from %1$s eraser (index %2$d).' ), 4330 esc_html( $eraser_friendly_name ), 4239 4331 $eraser_index 4240 4332 ) 4241 4333 ); 4242 4334 } 4243 if ( ! is_callable( $eraser['callback'] ) ) { 4335 4336 if ( ! array_key_exists( 'num_items_retained', $response ) ) { 4244 4337 wp_send_json_error( 4245 4338 sprintf( 4246 __( 'Error: Eraser callback at index %d is not a valid callback.' ), 4339 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4340 __( 'Expected num_items_retained key in response array from %1$s eraser (index %2$d).' ), 4341 esc_html( $eraser_friendly_name ), 4247 4342 $eraser_index 4248 4343 ) 4249 4344 ); 4250 4345 } 4251 if ( ! array_key_exists( 'eraser_friendly_name', $eraser ) ) { 4346 4347 if ( ! array_key_exists( 'messages', $response ) ) { 4252 4348 wp_send_json_error( 4253 4349 sprintf( 4254 __( 'Error: Eraser array at index %d does not include a friendly name.' ), 4350 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4351 __( 'Expected messages key in response array from %1$s eraser (index %2$d).' ), 4352 esc_html( $eraser_friendly_name ), 4255 4353 $eraser_index 4256 4354 ) … … 4258 4356 } 4259 4357 4260 $callback = $erasers[ $index ]['callback']; 4261 $eraser_friendly_name = $erasers[ $index ]['eraser_friendly_name']; 4262 4263 $response = call_user_func( $callback, $email_address, $page ); 4264 if ( is_wp_error( $response ) ) { 4265 wp_send_json_error( $response ); 4266 } 4267 4268 if ( ! is_array( $response ) ) { 4358 if ( ! is_array( $response['messages'] ) ) { 4269 4359 wp_send_json_error( 4270 4360 sprintf( 4271 __( 'Error: Did not receive array from %s eraser (index %d).' ), 4272 $eraser_friendly_name, 4361 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4362 __( 'Expected messages key to reference an array in response array from %1$s eraser (index %2$d).' ), 4363 esc_html( $eraser_friendly_name ), 4273 4364 $eraser_index 4274 4365 ) 4275 4366 ); 4276 4367 } 4277 if ( ! array_key_exists( 'num_items_removed', $response ) ) { 4368 4369 if ( ! array_key_exists( 'done', $response ) ) { 4278 4370 wp_send_json_error( 4279 4371 sprintf( 4280 __( 'Error: Expected num_items_removed key in response array from %s eraser (index %d).' ), 4281 $eraser_friendly_name, 4372 /* translators: %1$s: eraser friendly name, %2$d: array index */ 4373 __( 'Expected done flag in response array from %1$s eraser (index %2$d).' ), 4374 esc_html( $eraser_friendly_name ), 4282 4375 $eraser_index 4283 4376 ) 4284 4377 ); 4285 4378 } 4286 if ( ! array_key_exists( 'num_items_retained', $response ) ) {4287 wp_send_json_error(4288 sprintf(4289 __( 'Error: Expected num_items_retained key in response array from %s eraser (index %d).' ),4290 $eraser_friendly_name,4291 $eraser_index4292 )4293 );4294 }4295 if ( ! array_key_exists( 'messages', $response ) ) {4296 wp_send_json_error(4297 sprintf(4298 __( 'Error: Expected messages key in response array from %s eraser (index %d).' ),4299 $eraser_friendly_name,4300 $eraser_index4301 )4302 );4303 }4304 if ( ! is_array( $response['messages'] ) ) {4305 wp_send_json_error(4306 sprintf(4307 __( 'Error: Expected messages key to reference an array in response array from %s eraser (index %d).' ),4308 $eraser_friendly_name,4309 $eraser_index4310 )4311 );4312 }4313 if ( ! array_key_exists( 'done', $response ) ) {4314 wp_send_json_error(4315 sprintf(4316 __( 'Error: Expected done flag in response array from %s eraser (index %d).' ),4317 $eraser_friendly_name,4318 $eraser_index4319 )4320 );4321 }4322 4379 } else { 4323 // No erasers, so we're done 4380 // No erasers, so we're done. 4324 4381 $response = array( 4325 'num_items_removed' => 0,4382 'num_items_removed' => 0, 4326 4383 'num_items_retained' => 0, 4327 'messages' => array(),4328 'done' => true,4384 'messages' => array(), 4385 'done' => true, 4329 4386 ); 4330 4387 } … … 4340 4397 * @param int $exporter_index The index of the exporter that provided this data. 4341 4398 * @param string $email_address The email address associated with this personal data. 4342 * @param int $page The zero-basedpage for this response.4399 * @param int $page The page for this response. 4343 4400 * @param int $request_id The privacy request post ID associated with this request. 4344 4401 */ 4345 4402 $response = apply_filters( 'wp_privacy_personal_data_erasure_page', $response, $eraser_index, $email_address, $page, $request_id ); 4403 4346 4404 if ( is_wp_error( $response ) ) { 4347 4405 wp_send_json_error( $response );
Note: See TracChangeset
for help on using the changeset viewer.