Automattic\WooCommerce\Blocks\BlockTypes

ProductFilters::get_filter_params()privateWC 1.0

Parse the filter parameters from the URL. For now we only get the global query params from the URL. In the future, we should get the query params based on $query_id.

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

Возвращает

Массив. Parsed filter params.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_filter_params( $query_id );
$query_id(int) (обязательный)
Query ID.

Код ProductFilters::get_filter_params() WC 9.7.1

private function get_filter_params( $query_id ) {
	// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
	$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '';

	$parsed_url = wp_parse_url( esc_url_raw( $request_uri ) );

	if ( empty( $parsed_url['query'] ) ) {
		return array();
	}

	parse_str( $parsed_url['query'], $url_query_params );

	/**
	 * Filters the active filter data provided by filter blocks.
	 *
	 * @since 11.7.0
	 *
	 * @param array $filter_param_keys The active filters data
	 * @param array $url_param_keys    The query param parsed from the URL.
	 *
	 * @return array Active filters params.
	 */
	$filter_param_keys = array_unique( apply_filters( 'woocommerce_blocks_product_filters_param_keys', array(), array_keys( $url_query_params ) ) );

	return array_filter(
		$url_query_params,
		function ( $key ) use ( $filter_param_keys ) {
			return in_array( $key, $filter_param_keys, true );
		},
		ARRAY_FILTER_USE_KEY
	);
}