Automattic\WooCommerce\Admin\API\Reports\Export

Controller::validate_report_argspublicWC 11.0.1

Validate report_args against the target report's own collection schema.

The export route accepts report_args as a free-form object, so its keys (e.g. orderby) must be validated against the schema of the report being exported the same way the non-export report route validates them.

Method of the class: Controller{}

No Hooks.

Returns

true|\WP_Error.

Usage

$Controller = new Controller();
$Controller->validate_report_args( $value, $request, $param );
$value(mixed) (required)
The report_args value.
$request(required)
.
$param(string) (required)
The parameter name.

Changelog

Since 11.0.1 Introduced.

Controller::validate_report_args() code WC 11.0.1

public function validate_report_args( $value, $request, $param ) {
	$validity = rest_validate_request_arg( $value, $request, $param );
	if ( true !== $validity ) {
		return $validity;
	}

	$report_controller = ReportCSVExporter::get_report_controller( $request['type'] );
	if ( ! $report_controller ) {
		// Fail closed: an unresolved report type cannot be validated, and
		// exporting it would otherwise run with unvalidated arguments.
		return new \WP_Error(
			'woocommerce_rest_invalid_report_type',
			__( 'Invalid report type.', 'woocommerce' ),
			array( 'status' => 400 )
		);
	}

	$schema_check = new \WP_REST_Request();
	$schema_check->set_attributes( array( 'args' => $report_controller->get_collection_params() ) );
	$schema_check->set_query_params( is_array( $value ) ? $value : array() );

	return $schema_check->has_valid_params();
}