wppaste
WordPress

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

Since
5.9.0
Source
wp-includes/blocks/navigation-link.php:172
Renders the core/navigation-link 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_link() 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
83–146

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

Plugin surface
1 hook

Third-party callbacks on 'render_block_core_navigation_link_allowed_post_status' run inside this call, and their cost is not bounded by anything here.

Called by
0

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

What it touches

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

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

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

WhenInstructionsCalls it makes
!isset($attributes) && $value && !is_post_type_archive()83–103block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive()89–111block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), wp_kses_post()
$value && !is_post_type_archive()90–111block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr()
!isset($attributes) && $value && !is_post_type_archive() && isset($value)92–109block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_render_submenu_icon()
$value && !is_post_type_archive()94–114block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url()
!empty($attributes) && $value && !is_post_type_archive()96–119block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), wp_kses_post()
!empty($attributes) && $value && !is_post_type_archive()97–117block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), wp_kses_post(), wp_kses_post()
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() && isset($value)98–117block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
$value && !is_post_type_archive()98–115block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), esc_attr()
$value && !is_post_type_archive() && isset($value)99–117block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive()100–122block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), wp_kses_post()
$value && !is_post_type_archive()101–122block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr()
24 further outcomes, up to 146 instructions
$value && !is_post_type_archive() && isset($value)103–120block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive()104–125block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), wp_kses_post(), wp_kses_post()
!empty($attributes) && $value && !is_post_type_archive()104–123block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), esc_attr(), wp_kses_post()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)105–125block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)106–123block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), wp_kses_post(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
$value && !is_post_type_archive() && isset($value)107–121block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), esc_attr(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive()107–130block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), wp_kses_post()
!empty($attributes) && $value && !is_post_type_archive()108–128block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), wp_kses_post(), wp_kses_post()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)109–128block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
$value && !is_post_type_archive()109–126block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr()
$value && !is_post_type_archive() && isset($value)110–128block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive()112–129block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), esc_attr(), wp_kses_post(), wp_kses_post()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)113–131block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), wp_kses_post(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)113–129block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), esc_attr(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive()115–136block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), wp_kses_post(), wp_kses_post()
!empty($attributes) && $value && !is_post_type_archive()115–134block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), wp_kses_post()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)116–136block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)117–134block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), wp_kses_post(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
$value && !is_post_type_archive() && isset($value)118–132block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)121–135block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), esc_attr(), esc_attr(), wp_kses_post(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive()123–140block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), wp_kses_post(), wp_kses_post()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)124–142block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), wp_kses_post(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)124–140block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()
!empty($attributes) && $value && !is_post_type_archive() && isset($value)132–146block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), block_core_navigation_link_maybe_urldecode(), esc_url(), esc_attr(), esc_attr(), wp_kses_post(), wp_kses_post(), block_core_navigation_link_render_submenu_icon()

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-dev21683–14633
8.521683–14633
8.421683–1463316 fewer instructions than PHP 8.3
8.323293–15733
8.223293–15733
8.123293–157332 fewer instructions than PHP 7.4
7.423493–15733

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.

Hooks and filters fired · 1

One hook fires while render_block_core_navigation_link() runs, in this order:

  1. apply_filters( render_block_core_navigation_link_allowed_post_status )filterline 189 (+17 into the body)

    Filter allowed post_status for navigation link block to render.

Uses · 13

Show all 13

Source code

function render_block_core_navigation_link( $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 or if the ID does not exist.	if ( $is_post_type && $navigation_link_has_id ) {		$post = get_post( $attributes['id'] );		/**		 * Filter allowed post_status for navigation link block to render.		 *		 * @since 6.8.0		 *		 * @param array $post_status		 * @param array $attributes		 * @param WP_Block $block		 */		$allowed_post_status = (array) apply_filters(			'render_block_core_navigation_link_allowed_post_status',			array( 'publish' ),			$attributes,			$block		);		if ( ! $post || ! in_array( $post->post_status, $allowed_post_status, true ) ) {			return '';		}	} 	// Don't render the block's subtree if it has no label.	if ( empty( $attributes['label'] ) ) {		return '';	} 	$font_sizes      = block_core_navigation_link_build_css_font_sizes( $block->context );	$classes         = array_merge(		$font_sizes['css_classes']	);	$style_attribute = $font_sizes['inline_styles']; 	$css_classes = trim( implode( ' ', $classes ) );	$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;		}	} 	$wrapper_attributes = get_block_wrapper_attributes(		array(			'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) .				( $is_active ? ' current-menu-item' : '' ),			'style' => $style_attribute,		)	);	$html               = '<li ' . $wrapper_attributes . '>' .		'<a class="wp-block-navigation-item__content" '; 	// Start appending HTML attributes to anchor tag.	if ( isset( $attributes['url'] ) ) {		$html .= ' href="' . esc_url( block_core_navigation_link_maybe_urldecode( $attributes['url'] ) ) . '"';	} 	if ( $is_active ) {		$html .= ' aria-current="page"';	} 	if ( isset( $attributes['opensInNewTab'] ) && true === $attributes['opensInNewTab'] ) {		$html .= ' target="_blank"  ';	} 	if ( isset( $attributes['rel'] ) ) {		$html .= ' rel="' . esc_attr( $attributes['rel'] ) . '"';	} elseif ( isset( $attributes['nofollow'] ) && $attributes['nofollow'] ) {		$html .= ' rel="nofollow"';	}

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-link.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.