Automattic\WooCommerce\Internal\CLI\Migrator\Core

ProductsController::parse_query_filters │ private │ WC 1.0

Parse query filters for platform-agnostic filtering.

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

Хуков нет.

Возвращает

array. Parsed query filters.

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

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

Код ProductsController::parse_query_filters() WC 11.2.2

private function parse_query_filters( array $assoc_args ): array {
	$filters = array();

	if ( isset( $assoc_args['status'] ) ) {
		$valid_statuses = array( 'active', 'archived', 'draft' );
		$status         = strtolower( $assoc_args['status'] );
		if ( in_array( $status, $valid_statuses, true ) ) {
			$filters['status'] = $status;
		} else {
			WP_CLI::warning(
				sprintf(
					'Invalid status "%s". Valid options: %s',
					$status,
					implode( ', ', $valid_statuses )
				)
			);
		}
	}

	if ( isset( $assoc_args['created-after'] ) ) {
		$date = $this->validate_date_filter( $assoc_args['created-after'], 'created-after' );
		if ( $date ) {
			$filters['created_after'] = $date;
		}
	}

	if ( isset( $assoc_args['created-before'] ) ) {
		$date = $this->validate_date_filter( $assoc_args['created-before'], 'created-before' );
		if ( $date ) {
			$filters['created_before'] = $date;
		}
	}

	if ( isset( $assoc_args['product-type'] ) && 'all' !== $assoc_args['product-type'] ) {
		$filters['product_type'] = $assoc_args['product-type'];
	}

	if ( isset( $assoc_args['handle'] ) ) {
		$filters['handle'] = sanitize_title( $assoc_args['handle'] );
	}

	if ( isset( $assoc_args['vendor'] ) ) {
		$filters['vendor'] = $assoc_args['vendor'];
	}

	if ( isset( $assoc_args['ids'] ) ) {
		$filters['ids'] = $assoc_args['ids'];
	}

	return $filters;
}