Automattic\WooCommerce\Internal\ProductFilters

TaxonomyHierarchyData::get_hierarchy_mappublicWC 1.0

Get optimized hierarchy map for a taxonomy.

Method of the class: TaxonomyHierarchyData{}

No Hooks.

Returns

Array. Hierarchy map structure optimized for the taxonomy size.

Usage

$TaxonomyHierarchyData = new TaxonomyHierarchyData();
$TaxonomyHierarchyData->get_hierarchy_map( $taxonomy ): array;
$taxonomy(string) (required)
The taxonomy name.

TaxonomyHierarchyData::get_hierarchy_map() code WC 10.3.3

public function get_hierarchy_map( string $taxonomy ): array {
	if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
		return array();
	}

	// Check in-memory cache first.
	if ( isset( $this->hierarchy_data[ $taxonomy ] ) ) {
		return $this->hierarchy_data[ $taxonomy ];
	}

	// Check option cache.
	$cache_key  = self::CACHE_GROUP . '_' . $taxonomy;
	$cached_map = null;

	if ( ! ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) {
		$cached_map = get_option( $cache_key );
	}

	if ( ! empty( $cached_map ) && $this->validate_cache( $cached_map ) ) {
		// Cache in memory and return.
		$this->hierarchy_data[ $taxonomy ] = $cached_map;
		return $cached_map;
	}

	// Build the complete hierarchy map with all descendants pre-computed.
	$map = $this->build_full_hierarchy_map( $taxonomy );

	// Cache the map in options and memory.
	if ( ! ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) {
		update_option( $cache_key, $map, false );
	}

	$this->hierarchy_data[ $taxonomy ] = $map;

	return $map;
}