Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix sanitization callback
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Nov 2, 2021
1 parent c7742f8 commit 82e04ca
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/StoreApi/Schemas/AbstractSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ protected function get_recursive_sanitize_callback( $properties ) {
* @return true|\WP_Error
*/
return function ( $values, $request, $param ) use ( $properties ) {
$sanitized_values = [];

foreach ( $properties as $property_key => $property_value ) {
$current_value = isset( $values[ $property_key ] ) ? $values[ $property_key ] : null;

Expand All @@ -188,17 +190,20 @@ protected function get_recursive_sanitize_callback( $properties ) {
$current_value = rest_sanitize_value_from_schema( $current_value, $property_value, $param . ' > ' . $property_key );
}

// If sanitization failed, return the WP_Error object straight away.
if ( is_wp_error( $current_value ) ) {
return $current_value;
}

if ( isset( $property_value['properties'] ) ) {
$sanitize_callback = $this->get_recursive_sanitize_callback( $property_value['properties'] );
return $sanitize_callback( $current_value, $request, $param . ' > ' . $property_key );
$sanitize_callback = $this->get_recursive_sanitize_callback( $property_value['properties'] );
$sanitized_values[ $property_key ] = $sanitize_callback( $current_value, $request, $param . ' > ' . $property_key );
} else {
$sanitized_values[ $property_key ] = $current_value;
}
}

return true;
return $sanitized_values;
};
}

Expand Down

0 comments on commit 82e04ca

Please sign in to comment.