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
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
- Scaling
- Scales with input
- Instructions
- 83–146
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_post().
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 218.
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.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($attributes) && $value && !is_post_type_archive() | 83–103 | block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class() |
!isset($attributes) && !empty($attributes) && $value && !is_post_type_archive() | 89–111 | block_core_navigation_link_build_css_font_sizes(), array_merge(), is_post_type_archive(), class(), wp_kses_post() |
$value && !is_post_type_archive() | 90–111 | block_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–109 | block_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–114 | block_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–119 | block_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–117 | block_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–117 | block_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–115 | block_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–117 | block_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–122 | block_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–122 | block_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–120 | block_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–125 | block_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–123 | block_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–125 | block_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–123 | block_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–121 | block_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–130 | block_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–128 | block_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–128 | block_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–126 | block_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–128 | block_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–129 | block_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–131 | block_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–129 | block_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–136 | block_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–134 | block_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–136 | block_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–134 | block_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–132 | block_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–135 | block_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–140 | block_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–142 | block_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–140 | block_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–146 | block_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 218 | 83–146 | 34 | |
| 8.5 | 218 | 83–146 | 34 | |
| 8.4 | 218 | 83–146 | 34 | 16 fewer instructions than PHP 8.3 |
| 8.3 | 234 | 93–157 | 34 | |
| 8.2 | 234 | 93–157 | 34 | |
| 8.1 | 234 | 93–157 | 34 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 236 | 93–157 | 34 |
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:
- 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
- get_post()Retrieves post data given a post ID or post object.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- block_core_navigation_link_build_css_font_sizes()Build an array with CSS classes and inline styles defining the font sizes which will be applied to the navigation markup in the front-end.
- get_queried_object_id()Retrieves the ID of the currently queried object.
- get_queried_object()Retrieves the currently queried object.
- is_post_type_archive()Determines whether the query is for an existing post type archive page.
- get_post_type_archive_link()Retrieves the permalink for a post type archive.
- get_block_wrapper_attributes()Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.
- esc_url()Checks and cleans a URL.
- block_core_navigation_link_maybe_urldecode()Decodes a url if it's encoded, returning the same url if not.
- esc_attr()Escaping for HTML attributes.
- wp_kses_post()Sanitizes content for allowed HTML tags for post content.
Show all 13
- block_core_navigation_link_render_submenu_icon()Returns the top-level submenu SVG chevron icon.
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() && ! empty( $attributes['url'] ) ) { $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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.10 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.