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



block_core_navigation_get_submenu_visibility › WordPress Function

Seit6.9.0
Veraltetn/v
block_core_navigation_get_submenu_visibility ( $attributes )
Parameter:
  • (array) $attributes Block attributes containing submenuVisibility and/or openSubmenusOnClick.
    Erforderlich: Ja
Gibt zurück:
  • (string) The visibility mode: 'hover', 'click', or 'always'.
Definiert in:
Codex:

Returns the submenu visibility value with backward compatibility for the deprecated openSubmenusOnClick attribute.

This function centralizes the migration logic from the boolean openSubmenusOnClick to the new submenuVisibility enum. Backward compatibility: WordPress applies default attribute values, so submenuVisibility will always have a value even for legacy blocks. We check the legacy openSubmenusOnClick attribute first to preserve original behavior for blocks saved before the migration.


Quellcode

function block_core_navigation_get_submenu_visibility( $attributes ) {
	$deprecated_open_submenus_on_click = $attributes['openSubmenusOnClick'] ?? null;

	// For backward compatibility, prioritize the legacy attribute if present.
	// Legacy blocks have openSubmenusOnClick in the database. Since WordPress applies
	// default values, submenuVisibility will also have a value, but we check the legacy
	// attribute first to preserve the original behavior. If the block has been updated
	// and saved in the editor, then the deprecated attribute will be replaced by submenuVisibility.
	if ( null !== $deprecated_open_submenus_on_click ) {
		// Convert boolean to string: true -> 'click', false -> 'hover'.
		return ! empty( $deprecated_open_submenus_on_click ) ? 'click' : 'hover';
	}

	$submenu_visibility = $attributes['submenuVisibility'] ?? null;

	// Use submenuVisibility for migrated/new blocks (where openSubmenusOnClick is null).
	return $submenu_visibility ?? 'hover';
}