Automattic\WooCommerce\Internal\CLI\Migrator\Core

ProductsController::parse_query_filtersprivateWC 1.0

Parse query filters for platform-agnostic filtering.

Method of the class: ProductsController{}

No Hooks.

Returns

Array. Parsed query filters.

Usage

// private - for code of main (parent) class only
$result = $this->parse_query_filters( $assoc_args ): array;
$assoc_args(array) (required)
Command arguments.

ProductsController::parse_query_filters() code WC 11.0.1

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;
}