wppaste
WordPress

block_core_navigation_parse_blocks_from_menu_items( array $menu_items, array $menu_items_by_parent_id ): array

Since
5.9.0
Source
wp-includes/blocks/navigation.php:1779
Turns menu item data into a nested array of parsed blocks

Compatibility

Deprecated in WordPress 6.3.0. Use WP_Navigation_Fallback::parse_blocks_from_menu_items() instead.

WordPress
since 5.9.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$menu_itemsarray
An array of menu items that represent an individual level of a menu.
$menu_items_by_parent_idarray
An array keyed by the id of the parent menu where each element is an array of menu items that belong to that parent.

Return value

array
An array of parsed block data.

Performance profile

How much work a call to block_core_navigation_parse_blocks_from_menu_items() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
10–14

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 107.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()one call below block_core_navigation_parse_blocks_from_menu_items()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost block_core_navigation_parse_blocks_from_menu_items() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always10–14_deprecated_function()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev10610–14121 fewer instruction than PHP 8.5
8.510710–1412
8.410710–14128 fewer instructions than PHP 8.3
8.311510–1412
8.211510–1412
8.111510–14122 fewer instructions than PHP 7.4
7.411710–1412

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 2

Used by · 3

Source code

function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) { 	_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::parse_blocks_from_menu_items' ); 	if ( empty( $menu_items ) ) {		return array();	} 	$blocks = array(); 	foreach ( $menu_items as $menu_item ) {		$class_name       = ! empty( $menu_item->classes ) ? implode( ' ', (array) $menu_item->classes ) : null;		$id               = ( null !== $menu_item->object_id && 'custom' !== $menu_item->object ) ? $menu_item->object_id : null;		$opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target;		$rel              = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null;		$kind             = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom'; 		$block = array(			'blockName' => isset( $menu_items_by_parent_id[ $menu_item->ID ] ) ? 'core/navigation-submenu' : 'core/navigation-link',			'attrs'     => array(				'className'     => $class_name,				'description'   => $menu_item->description,				'id'            => $id,				'kind'          => $kind,				'label'         => $menu_item->title,				'opensInNewTab' => $opens_in_new_tab,				'rel'           => $rel,				'title'         => $menu_item->attr_title,				'type'          => $menu_item->object,				'url'           => $menu_item->url,			),		); 		$block['innerBlocks']  = isset( $menu_items_by_parent_id[ $menu_item->ID ] )			? block_core_navigation_parse_blocks_from_menu_items( $menu_items_by_parent_id[ $menu_item->ID ], $menu_items_by_parent_id )			: array();		$block['innerContent'] = array_map( 'serialize_block', $block['innerBlocks'] ); 		$blocks[] = $block;	} 	return $blocks;}

Changelog

Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.3.0
Deprecated. Use WP_Navigation_Fallback::parse_blocks_from_menu_items() instead.from the docblock
5.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/blocks/navigation.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.