wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



block_core_navigation_link_filter_variations › WordPress Function

Seit6.5.0
Veraltetn/v
block_core_navigation_link_filter_variations ( $variations, $block_type )
Parameter: (2)
  • (array) $variations Array of registered variations for a block type.
    Erforderlich: Ja
  • (WP_Block_Type) $block_type The full block type object.
    Erforderlich: Ja
Gibt zurück:
  • (array) Numerically indexed array of block variations.
Definiert in:
Codex:

Filters the registered variations for a block type.

Returns the dynamically built variations for all post-types and taxonomies.


Quellcode

function block_core_navigation_link_filter_variations( $variations, $block_type ) {
	if ( 'core/navigation-link' !== $block_type->name ) {
		return $variations;
	}

	$generated_variations = block_core_navigation_link_build_variations();

	/*
	 * IMPORTANT: Order matters for deduplication.
	 *
	 * The variations returned from this filter are bootstrapped to JavaScript and
	 * processed by the block variations reducer. The reducer uses `getUniqueItemsByName()`
	 * (packages/blocks/src/store/reducer.js:51-57) which keeps the FIRST variation with
	 * a given 'name' and discards later duplicates when processing the array in order.
	 *
	 * By placing generated variations first in `array_merge()`, the improved
	 * labels (e.g., "Product link" instead of generic "Post Link") are processed first
	 * and preserved. The generic incoming variations are then discarded as duplicates.
	 *
	 * Why `array_merge()` instead of manual deduplication?
	 * - Both arrays use numeric indices (0, 1, 2...), so `array_merge()` concatenates
	 *   and re-indexes them sequentially, preserving order
	 * - The reducer handles deduplication, so it is not needed here
	 * - This keeps the PHP code simple and relies on the established JavaScript behavior
	 *
	 * See: https://github.com/WordPress/gutenberg/pull/72517
	 */
	return array_merge( $generated_variations, $variations );
}