Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableMetaQuery::sanitize_meta_query()privateWC 1.0

Sanitizes the meta_query argument.

{} Это метод класса: OrdersTableMetaQuery{}

Хуков нет.

Возвращает

Массив. A sanitized meta query array.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->sanitize_meta_query( $q ): array;
$q(массив) (обязательный)
A meta_query array.

Код OrdersTableMetaQuery::sanitize_meta_query() WC 6.9.4

private function sanitize_meta_query( array $q ): array {
	$sanitized = array();

	if ( $this->is_atomic( $q ) ) {
		if ( isset( $q['value'] ) && array() === $q['value'] ) {
			unset( $q['value'] );
		}

		$q['compare']     = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : ( isset( $q['value'] ) && is_array( $q['value'] ) ? 'IN' : '=' );
		$q['compare_key'] = isset( $q['compare_key'] ) ? strtoupper( $q['compare_key'] ) : ( isset( $q['key'] ) && is_array( $q['key'] ) ? 'IN' : '=' );

		if ( ! in_array( $q['compare'], self::NON_NUMERIC_OPERATORS, true ) && ! in_array( $q['compare'], self::NUMERIC_OPERATORS, true ) ) {
			$q['compare'] = '=';
		}

		if ( ! in_array( $q['compare_key'], self::NON_NUMERIC_OPERATORS, true ) ) {
			$q['compare_key'] = '=';
		}

		return $q;
	}

	// Nested.
	foreach ( $q as $key => $arg ) {
		if ( 'relation' === $key ) {
			$relation = $arg;
		} elseif ( ! is_array( $arg ) ) {
			continue;
		} else {
			$sanitized_arg = $this->sanitize_meta_query( $arg );

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

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

	return $sanitized;
}