WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Schemas

AbstractSchema::get_recursive_validate_callback() protected WC 1.0

Gets a function that validates recursively.

{} It's a method of the class: AbstractSchema{}

No Hooks.

Return

function. Anonymous validation callback.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_recursive_validate_callback( $properties );
$properties(array) (required)
Schema property data.

Code of AbstractSchema::get_recursive_validate_callback() WC 5.8.0

protected function get_recursive_validate_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 ) {
		foreach ( $properties as $property_key => $property_value ) {
			$current_value = isset( $values[ $property_key ] ) ? $values[ $property_key ] : null;

			if ( isset( $property_value['arg_options']['validate_callback'] ) ) {
				$callback = $property_value['arg_options']['validate_callback'];
				$result   = is_callable( $callback ) ? $callback( $current_value, $request, $param ) : false;
			} else {
				$result = rest_validate_value_from_schema( $current_value, $property_value, $param . ' > ' . $property_key );
			}

			if ( ! $result || is_wp_error( $result ) ) {
				return $result;
			}

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

		return true;
	};
}