Automattic\WooCommerce\Blocks\BlockTypes

ProductFilterActive::get_filter_query_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.

Method of the class: ProductFilterActive{}

Hooks from the method

Return

Array. Parsed filter params.

Usage

// private - for code of main (parent) class only
$result = $this->get_filter_query_params( $query_id );
$query_id(int) (required)
Query ID.

ProductFilterActive::get_filter_query_params() code WC 8.9.0

private function get_filter_query_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( 'collection_filter_query_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
	);
}