Automattic\WooCommerce\Internal\DataStores\Orders

LegacyDataHandler::validate_backfill_fields()privateWC 1.0

Validates meta_keys and property names for a partial order backfill.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->validate_backfill_fields( $fields, $order );
$fields(массив) (обязательный)
An array possibly having entries with index 'meta_keys' and/or 'props', corresponding to an array of order meta keys and/or order properties.
$order(\WC_Abstract_Order) (обязательный)
The order being validated.

Код LegacyDataHandler::validate_backfill_fields() WC 9.7.1

private function validate_backfill_fields( array $fields, \WC_Abstract_Order $order ) {
	if ( ! $fields ) {
		return;
	}

	if ( ! empty( $fields['meta_keys'] ) ) {
		$internal_meta_keys = array_unique(
			array_merge(
				$this->data_store->get_internal_meta_keys(),
				$this->data_store->get_cpt_data_store_instance()->get_internal_meta_keys()
			)
		);

		$possibly_internal_keys = array_intersect( $internal_meta_keys, $fields['meta_keys'] );
		if ( ! empty( $possibly_internal_keys ) ) {
			throw new \Exception(
				esc_html(
					sprintf(
						// translators: %s is a comma separated list of metakey names.
						_n(
							'%s is an internal meta key. Use --props to set it.',
							'%s are internal meta keys. Use --props to set them.',
							count( $possibly_internal_keys ),
							'woocommerce'
						),
						implode( ', ', $possibly_internal_keys )
					)
				)
			);
		}
	}

	if ( ! empty( $fields['props'] ) ) {
		$invalid_props = array_filter(
			$fields['props'],
			function ( $prop_name ) use ( $order ) {
				return ! method_exists( $order, "get_{$prop_name}" );
			}
		);

		if ( ! empty( $invalid_props ) ) {
			throw new \Exception(
				esc_html(
					sprintf(
						// translators: %s is a list of order property names.
						_n(
							'%s is not a valid order property.',
							'%s are not valid order properties.',
							count( $invalid_props ),
							'woocommerce'
						),
						implode( ', ', $invalid_props )
					)
				)
			);
		}
	}
}