wppaste
WordPress

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
Gets the inner blocks for the navigation block from an overlay template part.

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

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
9–94

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()one call below WP_Navigation_Block_Renderer::get_overlay_blocks_from_template_part()
  • optionoption read or writeget_option()one call below WP_Navigation_Block_Renderer::get_overlay_blocks_from_template_part()
  • querycontent queryget_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.

WhenInstructionsCalls it makes
always9–11none
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme !== false27explode(), get_stylesheet()
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme !== false28explode(), get_stylesheet(), get_stylesheet()
!empty($overlay_template_part_id) && is_string($overlay_template_part_id) && $theme === false && !->have_posts() && !isset($block_template)55explode(), 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)56explode(), 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)58explode(), 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)58explode(), 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)59explode(), 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)59explode(), 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)61explode(), 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)62explode(), 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)80explode(), 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)81explode(), 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)83explode(), 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)84explode(), 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)90explode(), 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)91explode(), 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)93explode(), 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)94explode(), 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

PHPCompiledExecutedBranchesNotes
8.6-dev1539–9381 fewer instruction than PHP 8.5
8.51549–948
8.41549–948
8.31549–948
8.21549–948
8.11549–948
7.41549–948

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

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 in

Changelog

Introduced in 6.5.0. Unchanged from 7.0.4 through 7.1.0.

  1. 7.0.4
  2. 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.