Automattic\WooCommerce\StoreApi\Schemas\V1
AbstractSchema::get_recursive_sanitize_callback
Gets a function that sanitizes recursively.
Метод класса: AbstractSchema{}
Хуков нет.
Возвращает
function. Anonymous validation callback.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_recursive_sanitize_callback( $properties );
- $properties(массив) (обязательный)
- Schema property data.
Код AbstractSchema::get_recursive_sanitize_callback() AbstractSchema::get recursive sanitize callback WC 10.5.0
protected function get_recursive_sanitize_callback( $properties ) {
/**
* Validate a request argument based on details registered to the route.
*
* @param mixed $values
* @param \WP_REST_Request $request
* @param string $param
* @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;
if ( isset( $property_value['arg_options']['sanitize_callback'] ) ) {
$callback = $property_value['arg_options']['sanitize_callback'];
$current_value = is_callable( $callback ) ? $callback( $current_value, $request, $param ) : $current_value;
} else {
$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'] );
$sanitized_values[ $property_key ] = $sanitize_callback( $current_value, $request, $param . ' > ' . $property_key );
} else {
$sanitized_values[ $property_key ] = $current_value;
}
}
return $sanitized_values;
};
}