Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableFieldQuery::sanitize_query()privateWC 1.0

Sanitizes the field_query argument.

Метод класса: OrdersTableFieldQuery{}

No Hooks.

Return

Array. A sanitized field query array.

Usage

// private - for code of main (parent) class only
$result = $this->sanitize_query( $q );
$q(array) (required)
A field_query array.

Code of OrdersTableFieldQuery::sanitize_query() WC 7.1.0

private function sanitize_query( array $q ) {
	$sanitized = array();

	foreach ( $q as $key => $arg ) {
		if ( 'relation' === $key ) {
			$relation = $arg;
		} elseif ( ! is_array( $arg ) ) {
			continue;
		} elseif ( $this->is_atomic( $arg ) ) {
			if ( isset( $arg['value'] ) && array() === $arg['value'] ) {
				continue;
			}

			// Sanitize 'compare'.
			$arg['compare'] = strtoupper( $arg['compare'] ?? '=' );
			$arg['compare'] = in_array( $arg['compare'], self::VALID_COMPARISON_OPERATORS, true ) ? $arg['compare'] : '=';

			if ( '=' === $arg['compare'] && isset( $arg['value'] ) && is_array( $arg['value'] ) ) {
				$arg['compare'] = 'IN';
			}

			// Sanitize 'cast'.
			$arg['cast'] = $this->sanitize_cast_type( $arg['type'] ?? '' );

			$field_info = $this->query->get_field_mapping_info( $arg['field'] );
			if ( ! $field_info ) {
				$this->force_no_results = true;
				continue;
			}

			$arg = array_merge( $arg, $field_info );

			$sanitized[ $key ] = $arg;
		} else {
			$sanitized_arg = $this->sanitize_query( $arg );

			if ( $sanitized_arg ) {
				$sanitized[ $key ] = $sanitized_arg;
			}
		}
	}

	if ( $sanitized ) {
		$sanitized['relation'] = 1 === count( $sanitized ) ? 'OR' : $this->sanitize_relation( $relation ?? 'AND' );
	}

	return $sanitized;
}