block_core_navigation_block_tree_has_block_type( WP_Block_List $blocks, string $block_type, array $skip_block_types = array() ): bool
- Since
- 7.0.0
- Source
wp-includes/blocks/navigation.php:1429
Compatibility
- WordPress
- since 7.0.0
- PHP
- 7.4–8.6-dev
- 6.7.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in 2 of the 5 tracked releases, added in 7.0.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$blocksWP_Block_List- The list of blocks to check.
$block_typestring- The block type to search for (e.g., 'core/navigation').
$skip_block_typesarrayoptional- Block types to skip when recursing. Default empty array.Default:
array()
Return value
bool- Returns true if the specified block type is found.
Performance profile
How much work a call to block_core_navigation_block_tree_has_block_type() 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
- Scaling
- Scales with input
- Instructions
- 6–26
- Plugin surface
- None
- Called by
- 3
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 31.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost block_core_navigation_block_tree_has_block_type() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6–12 | none |
!empty($blocks) && !$blocks && $block_type !== false && !$skip_block_types && !empty($block) && block_core_navigation_block_tree_has_block_type() | 26 | block_core_navigation_block_tree_has_block_type() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 31 | 6–26 | 7 | |
| 8.5 | 31 | 6–26 | 7 | |
| 8.4 | 31 | 6–26 | 7 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 34 | 6–29 | 7 | |
| 8.2 | 34 | 6–29 | 7 | |
| 8.1 | 34 | 6–29 | 7 | |
| 7.4 | 34 | 6–29 | 7 |
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 · 1
- block_core_navigation_block_tree_has_block_type()Recursively checks if blocks contain a specific block type.
Used by · 3
- WP_Navigation_Block_Renderer::render()Renders the navigation block.
- block_core_navigation_block_contains_core_navigation()Returns true if the navigation block contains a nested navigation block.
- block_core_navigation_block_tree_has_block_type()Recursively checks if blocks contain a specific block type.
Source code
function block_core_navigation_block_tree_has_block_type( $blocks, $block_type, $skip_block_types = array() ) { if ( empty( $blocks ) ) { return false; } foreach ( $blocks as $block ) { if ( $block_type === $block->name ) { return true; } // Recursively check inner blocks, skipping specified block types. if ( ! in_array( $block->name, $skip_block_types, true ) && ! empty( $block->inner_blocks ) ) { if ( block_core_navigation_block_tree_has_block_type( $block->inner_blocks, $block_type, $skip_block_types ) ) { return true; } } } return false;}Changelog
Introduced in 7.0.0. Unchanged from 7.0.7 through 7.1.3.
Signature, return type and hooks compared across 2 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.3 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.