WP_Navigation_Block_Renderer::get_overlay_blocks_from_template_part( string $overlay_template_part_id, array $attributes ): WP_Block_List
- Since
- 6.5.0
- Source
wp-includes/blocks/navigation.php:417
Compatibility
- WordPress
- since 6.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 2 of the 5 tracked releases, added in 6.5.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$overlay_template_part_idstring- The overlay template part ID in format "theme//slug".
$attributesarray- The block attributes.
Return value
WP_Block_List- Returns the inner blocks for the overlay template part.
Performance profile
How much work a call to WP_Navigation_Block_Renderer::get_overlay_blocks_from_template_part() 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
- Heavy
- Scaling
- Constant
- Instructions
- 9–94
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 154.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below WP_Navigation_Block_Renderer::get_overlay_blocks_from_template_part() - optionoption read or write
get_option()one call below WP_Navigation_Block_Renderer::get_overlay_blocks_from_template_part() - querycontent query
get_post()one call below WP_Navigation_Block_Renderer::get_overlay_blocks_from_template_part()
Further down the call graph this can also reach 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 · 19 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Navigation_Block_Renderer::get_overlay_blocks_from_template_part() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9–11 | none |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme !== false | 27 | explode(), get_stylesheet() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme !== false | 28 | explode(), get_stylesheet(), get_stylesheet() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && !->have_posts() && !isset($block_template) | 55 | explode(), get_stylesheet(), ->have_posts(), _build_block_template_result_from_post(), wp_template_part() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && !->have_posts() && !isset($block_template) | 56 | explode(), get_stylesheet(), get_stylesheet(), ->have_posts(), _build_block_template_result_from_post(), wp_template_part() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && !->have_posts() && !isset($block_template) | 58 | explode(), get_stylesheet(), ->have_posts(), get_block_file_template() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && ->have_posts() && !isset($block_template) | 58 | explode(), get_stylesheet(), ->have_posts(), ->next_post(), _build_block_template_result_from_post(), wp_template_part() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && !->have_posts() && !isset($block_template) | 59 | explode(), get_stylesheet(), get_stylesheet(), ->have_posts(), get_block_file_template() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && ->have_posts() && !isset($block_template) | 59 | explode(), get_stylesheet(), get_stylesheet(), ->have_posts(), ->next_post(), _build_block_template_result_from_post(), wp_template_part() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && ->have_posts() && !isset($block_template) | 61 | explode(), get_stylesheet(), ->have_posts(), ->next_post(), get_block_file_template() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && ->have_posts() && !isset($block_template) | 62 | explode(), get_stylesheet(), get_stylesheet(), ->have_posts(), ->next_post(), get_block_file_template() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && !->have_posts() && isset($block_template) | 80 | explode(), get_stylesheet(), ->have_posts(), get_block_file_template(), shortcode_unautop(), do_shortcode(), parse_blocks(), block_core_navigation_filter_out_empty_blocks(), ::disable_overlay_menu_for_nested_navigation_blocks(), wp_theme() |
7 further outcomes, up to 94 instructions
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && !->have_posts() && isset($block_template) | 81 | explode(), get_stylesheet(), get_stylesheet(), ->have_posts(), get_block_file_template(), shortcode_unautop(), do_shortcode(), parse_blocks(), block_core_navigation_filter_out_empty_blocks(), ::disable_overlay_menu_for_nested_navigation_blocks(), wp_theme() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && ->have_posts() && isset($block_template) | 83 | explode(), get_stylesheet(), ->have_posts(), ->next_post(), get_block_file_template(), shortcode_unautop(), do_shortcode(), parse_blocks(), block_core_navigation_filter_out_empty_blocks(), ::disable_overlay_menu_for_nested_navigation_blocks(), wp_theme() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && ->have_posts() && isset($block_template) | 84 | explode(), get_stylesheet(), get_stylesheet(), ->have_posts(), ->next_post(), get_block_file_template(), shortcode_unautop(), do_shortcode(), parse_blocks(), block_core_navigation_filter_out_empty_blocks(), ::disable_overlay_menu_for_nested_navigation_blocks(), wp_theme() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && !->have_posts() && isset($block_template) | 90 | explode(), get_stylesheet(), ->have_posts(), _build_block_template_result_from_post(), parse_blocks(), block_core_navigation_filter_out_empty_blocks(), serialize_blocks(), apply_block_hooks_to_content_from_post_object(), shortcode_unautop(), do_shortcode(), parse_blocks(), ::disable_overlay_menu_for_nested_navigation_blocks() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && !->have_posts() && isset($block_template) | 91 | explode(), get_stylesheet(), get_stylesheet(), ->have_posts(), _build_block_template_result_from_post(), parse_blocks(), block_core_navigation_filter_out_empty_blocks(), serialize_blocks(), apply_block_hooks_to_content_from_post_object(), shortcode_unautop(), do_shortcode(), parse_blocks(), ::disable_overlay_menu_for_nested_navigation_blocks() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && ->have_posts() && isset($block_template) | 93 | explode(), get_stylesheet(), ->have_posts(), ->next_post(), _build_block_template_result_from_post(), parse_blocks(), block_core_navigation_filter_out_empty_blocks(), serialize_blocks(), apply_block_hooks_to_content_from_post_object(), shortcode_unautop(), do_shortcode(), parse_blocks(), ::disable_overlay_menu_for_nested_navigation_blocks() |
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && ->have_posts() && isset($block_template) | 94 | explode(), get_stylesheet(), get_stylesheet(), ->have_posts(), ->next_post(), _build_block_template_result_from_post(), parse_blocks(), block_core_navigation_filter_out_empty_blocks(), serialize_blocks(), apply_block_hooks_to_content_from_post_object(), shortcode_unautop(), do_shortcode(), parse_blocks(), ::disable_overlay_menu_for_nested_navigation_blocks() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 153 | 9–93 | 8 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 154 | 9–94 | 8 | |
| 8.4 | 154 | 9–94 | 8 | |
| 8.3 | 154 | 9–94 | 8 | |
| 8.2 | 154 | 9–94 | 8 | |
| 8.1 | 154 | 9–94 | 8 | |
| 7.4 | 154 | 9–94 | 8 |
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 · 12
- get_stylesheet()Retrieves name of the current stylesheet.
- get_block_file_template()Retrieves a unified template object based on a theme file or plugin registration.
- shortcode_unautop()Don't auto-p wrap shortcodes that stand alone.
- do_shortcode()Searches content for shortcodes and filter shortcodes through their hooks.
- parse_blocks()Parses blocks out of a content string.
- block_core_navigation_filter_out_empty_blocks()Filter out empty "null" blocks from the block list.
- _build_block_template_result_from_post()Builds a unified template object based a post Object.
- serialize_blocks()Returns a joined string of the aggregate serialization of the given parsed blocks.
- apply_block_hooks_to_content_from_post_object()Run the Block Hooks algorithm on a post object's content.
- WP_Block_List::__construct()Constructor.
- WP_Query::__construct()Constructor.
- static::disable_overlay_menu_for_nested_navigation_blocks()
Source code
private static function get_overlay_blocks_from_template_part( $overlay_template_part_id, $attributes ) { if ( empty( $overlay_template_part_id ) || ! is_string( $overlay_template_part_id ) ) { return new WP_Block_List( array(), $attributes ); } // Parse the template part ID (format: "theme//slug"). // If it's just a slug, construct the full ID using the current theme. $parts = explode( '//', $overlay_template_part_id, 2 ); if ( count( $parts ) === 2 ) { // Already in "theme//slug" format (backward compatibility). $theme = $parts[0]; $slug = $parts[1]; } else { // Just a slug, use current theme. $theme = get_stylesheet(); $slug = $overlay_template_part_id; } // Only query for template parts from the active theme. if ( get_stylesheet() !== $theme ) { return new WP_Block_List( array(), $attributes ); } // Query for the template part post. $template_part_query = new WP_Query( array( 'post_type' => 'wp_template_part', 'post_status' => 'publish', 'post_name__in' => array( $slug ), 'tax_query' => array( array( 'taxonomy' => 'wp_theme', 'field' => 'name', 'terms' => $theme, ), ), 'posts_per_page' => 1, 'no_found_rows' => true, 'lazy_load_term_meta' => false, // Do not lazy load term meta, as template parts only have one term. ) ); $template_part_post = $template_part_query->have_posts() ? $template_part_query->next_post() : null; if ( ! $template_part_post ) { // Try to get from theme file if not in database. // Construct the full template part ID for get_block_file_template. $full_template_part_id = $theme . '//' . $slug; $block_template = get_block_file_template( $full_template_part_id, 'wp_template_part' ); if ( isset( $block_template->content ) ) { // Expand shortcodes before parsing blocks, matching the order in // `render_block_core_template_part()`. $content = shortcode_unautop( $block_template->content ); $content = do_shortcode( $content ); $parsed_blocks = parse_blocks( $content ); $blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks ); // Disable overlay menu for any navigation blocks within the overlay to prevent nested overlays. $blocks = static::disable_overlay_menu_for_nested_navigation_blocks( $blocks ); return new WP_Block_List( $blocks, $attributes ); } return new WP_Block_List( array(), $attributes ); } // Get the template part content. $block_template = _build_block_template_result_from_post( $template_part_post ); if ( ! isset( $block_template->content ) ) { return new WP_Block_List( array(), $attributes ); } $parsed_blocks = parse_blocks( $block_template->content ); // 'parse_blocks' includes a null block with '\n\n' as the content when // it encounters whitespace. This code strips it. $blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks ); // Re-serialize, and run Block Hooks algorithm to inject hooked blocks. $markup = serialize_blocks( $blocks ); $markup = apply_block_hooks_to_content_from_post_object( $markup, $template_part_post ); // Expand shortcodes before parsing blocks, matching the order inChangelog
Introduced in 6.5.0. Unchanged from 7.0.4 through 7.1.0.
Signature, return type and hooks compared across 2 parsed releases.
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.