wppaste
WordPress

render_block_core_navigation_submenu( array $attributes, string $content, WP_Block $block ): string

Since
5.9.0
Source
wp-includes/blocks/navigation-submenu.php:67
Renders the core/navigation-submenu block.

Compatibility

WordPress
since 5.9.0
PHP
7.4–8.6-dev
  • 6.7.10
  • 6.8.11
  • 6.9.10
  • 7.0.7
  • 7.1.3

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

Parameters

$attributesarray
The block attributes.
$contentstring
The saved content.
$blockWP_Block
The parsed block.

Return value

string
Returns the post content with the legacy widget added.

Performance profile

How much work a call to render_block_core_navigation_submenu() 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
Scales with input

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

Instructions
103–222

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

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

  • querycontent queryget_post()one call below render_block_core_navigation_submenu()
  • hookthird-party callbacksapply_filters()one call below render_block_core_navigation_submenu()
  • optionoption read or writeget_option()one call below render_block_core_navigation_submenu()

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 · 27 distinct outcomes

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

WhenInstructionsCalls it makes
!isset($attributes) && $value && !is_post_type_archive() && !isset($value)103–123block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), block_core_navigation_submenu_render_submenu_icon()
!isset($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url)110–112block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() && !isset($value)111block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_kses_post(), block_core_navigation_submenu_render_submenu_icon()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url)118–120block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), wp_kses_post()
$value && !is_post_type_archive() && !isset($value) && empty($item_url)118–120block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr()
!empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url)126block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_kses_post()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url)129–131block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), wp_kses_post(), esc_attr(), block_core_navigation_submenu_render_submenu_icon()
$value && !is_post_type_archive() && !isset($value) && empty($item_url)129–131block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), esc_attr(), block_core_navigation_submenu_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url)137block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_kses_post(), esc_attr(), block_core_navigation_submenu_render_submenu_icon()
!isset($attributes) && $value && !is_post_type_archive() && !isset($value) && !$inner_blocks_html150–196block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), block_core_navigation_submenu_render_submenu_icon(), wp_apply_colors_support(), class()
!isset($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url) && !$inner_blocks_html157–185block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), wp_apply_colors_support(), class()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() && !isset($value) && !$inner_blocks_html158–184block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_kses_post(), block_core_navigation_submenu_render_submenu_icon(), wp_apply_colors_support(), class()
15 further outcomes, up to 222 instructions
!isset($attributes) && $value && !is_post_type_archive() && !isset($value) && $inner_blocks_html && !->next_tag()162–208block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), block_core_navigation_submenu_render_submenu_icon(), wp_apply_colors_support(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html(), class()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url) && !$inner_blocks_html165–193block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), wp_kses_post(), wp_apply_colors_support(), class()
$value && !is_post_type_archive() && !isset($value) && empty($item_url) && !$inner_blocks_html165–193block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_apply_colors_support(), class()
!isset($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url) && $inner_blocks_html && !->next_tag()169–197block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), wp_apply_colors_support(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html(), class()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() && !isset($value) && $inner_blocks_html && !->next_tag()170–196block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_kses_post(), block_core_navigation_submenu_render_submenu_icon(), wp_apply_colors_support(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html(), class()
!empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url) && !$inner_blocks_html173–199block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_kses_post(), wp_apply_colors_support(), class()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url) && !$inner_blocks_html176–204block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), wp_kses_post(), esc_attr(), block_core_navigation_submenu_render_submenu_icon(), wp_apply_colors_support(), class()
$value && !is_post_type_archive() && !isset($value) && empty($item_url) && !$inner_blocks_html176–202block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), esc_attr(), block_core_navigation_submenu_render_submenu_icon(), wp_apply_colors_support(), class()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url) && $inner_blocks_html && !->next_tag()177–205block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), wp_kses_post(), wp_apply_colors_support(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html(), class()
$value && !is_post_type_archive() && !isset($value) && empty($item_url) && $inner_blocks_html && !->next_tag()177–205block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_apply_colors_support(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html(), class()
!empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url) && !$inner_blocks_html184–210block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_kses_post(), esc_attr(), block_core_navigation_submenu_render_submenu_icon(), wp_apply_colors_support(), class()
!empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url) && $inner_blocks_html && !->next_tag()185–211block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_kses_post(), wp_apply_colors_support(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html(), class()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url) && $inner_blocks_html && !->next_tag()188–216block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), wp_kses_post(), esc_attr(), block_core_navigation_submenu_render_submenu_icon(), wp_apply_colors_support(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html(), class()
$value && !is_post_type_archive() && !isset($value) && empty($item_url) && $inner_blocks_html && !->next_tag()188–214block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), esc_attr(), block_core_navigation_submenu_render_submenu_icon(), wp_apply_colors_support(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html(), class()
!empty($attributes) && $value && !is_post_type_archive() && !isset($value) && empty($item_url) && $inner_blocks_html && !->next_tag()196–222block_core_navigation_submenu_build_css_font_sizes(), is_post_type_archive(), array_merge(), class(), __(), wp_strip_all_tags(), sprintf(), esc_attr(), wp_kses_post(), esc_attr(), block_core_navigation_submenu_render_submenu_icon(), wp_apply_colors_support(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html(), class()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev350103–22247
8.5350103–22247
8.4350103–2224712 fewer instructions than PHP 8.3
8.3362110–23247
8.2362110–23247
8.1362110–232473 fewer instructions than PHP 7.4
7.4365110–23247

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 · 15

Show all 15

Source code

function render_block_core_navigation_submenu( $attributes, $content, $block ) {	$navigation_link_has_id = isset( $attributes['id'] ) && is_numeric( $attributes['id'] );	$is_post_type           = isset( $attributes['kind'] ) && 'post-type' === $attributes['kind'];	$is_post_type           = $is_post_type || isset( $attributes['type'] ) && ( 'post' === $attributes['type'] || 'page' === $attributes['type'] ); 	// Don't render the block's subtree if it is a draft.	if ( $is_post_type && $navigation_link_has_id && 'publish' !== get_post_status( $attributes['id'] ) ) {		return '';	} 	// Don't render the block's subtree if it has no label.	if ( empty( $attributes['label'] ) ) {		return '';	} 	$font_sizes      = block_core_navigation_submenu_build_css_font_sizes( $block->context );	$style_attribute = $font_sizes['inline_styles']; 	$has_submenu = count( $block->inner_blocks ) > 0;	$kind        = empty( $attributes['kind'] ) ? 'post_type' : str_replace( '-', '_', $attributes['kind'] );	$is_active   = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind ); 	if ( is_post_type_archive() ) {		$queried_archive_link = get_post_type_archive_link( get_queried_object()->name );		if ( $attributes['url'] === $queried_archive_link ) {			$is_active = true;		}	} 	$show_submenu_indicators = isset( $block->context['showSubmenuIcon'] ) && $block->context['showSubmenuIcon'];	$open_on_click           = isset( $block->context['openSubmenusOnClick'] ) && $block->context['openSubmenusOnClick'];	$open_on_hover_and_click = isset( $block->context['openSubmenusOnClick'] ) && ! $block->context['openSubmenusOnClick'] &&		$show_submenu_indicators; 	$classes = array(		'wp-block-navigation-item',	);	$classes = array_merge(		$classes,		$font_sizes['css_classes']	);	if ( $has_submenu ) {		$classes[] = 'has-child';	}	if ( $open_on_click ) {		$classes[] = 'open-on-click';	}	if ( $open_on_hover_and_click ) {		$classes[] = 'open-on-hover-click';	}	if ( $is_active ) {		$classes[] = 'current-menu-item';	} 	$wrapper_attributes = get_block_wrapper_attributes(		array(			'class' => implode( ' ', $classes ),			'style' => $style_attribute,		)	); 	$label = ''; 	if ( isset( $attributes['label'] ) ) {		$label .= wp_kses_post( $attributes['label'] );	} 	$aria_label = sprintf(		/* translators: Accessibility text. %s: Parent page title. */		__( '%s submenu' ),		wp_strip_all_tags( $label )	); 	$html = '<li ' . $wrapper_attributes . '>'; 	// If Submenus open on hover, we render an anchor tag with attributes.	// If submenu icons are set to show, we also render a submenu button, so the submenu can be opened on click.	if ( ! $open_on_click ) {		$item_url = isset( $attributes['url'] ) ? $attributes['url'] : '';		// Start appending HTML attributes to anchor tag.

Changelog

Introduced in 5.9.0. Unchanged from 6.7.10 through 7.1.3.

  1. 6.7.10
  2. 6.8.11
  3. 6.9.10
  4. 7.0.7
  5. 7.1.3

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

About this page

Parsed data
Generated from the wordpress-develop 6.8.11 tag, from src/wp-includes/blocks/navigation-submenu.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.