block_core_navigation_get_classic_menu_fallback_blocks

函数
block_core_navigation_get_classic_menu_fallback_blocks ( $classic_nav_menu )
参数
  • (object) $classic_nav_menu WP_Term The classic navigation object to convert.
    Required:
返回值
  • (array) the normalized parsed blocks.
定义位置
相关方法
block_core_navigation_get_classic_menu_fallbackblock_core_navigation_get_fallback_blocksblock_core_navigation_maybe_use_classic_menu_fallbackblock_core_navigation_get_menu_items_at_locationblock_core_navigation_render_submenu_icon
引入
-
弃用
6.3.0

将经典导航转换为区块。

function block_core_navigation_get_classic_menu_fallback_blocks( $classic_nav_menu ) {

	_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::get_classic_menu_fallback_blocks' );

	// BEGIN: Code that already exists in wp_nav_menu().
	$menu_items = wp_get_nav_menu_items( $classic_nav_menu->term_id, array( 'update_post_term_cache' => false ) );

	// Set up the $menu_item variables.
	_wp_menu_item_classes_by_context( $menu_items );

	$sorted_menu_items = array();
	foreach ( (array) $menu_items as $menu_item ) {
		$sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
	}

	unset( $menu_items, $menu_item );

	// END: Code that already exists in wp_nav_menu().

	$menu_items_by_parent_id = array();
	foreach ( $sorted_menu_items as $menu_item ) {
		$menu_items_by_parent_id[ $menu_item->menu_item_parent ][] = $menu_item;
	}

	$inner_blocks = block_core_navigation_parse_blocks_from_menu_items(
		isset( $menu_items_by_parent_id[0] )
			? $menu_items_by_parent_id[0]
			: array(),
		$menu_items_by_parent_id
	);

	return serialize_blocks( $inner_blocks );
}

常见问题

FAQs
查看更多 >