build_variation_for_navigation_link( WP_Taxonomy|WP_Post_Type $entity, string $kind ): array
- Since
- 5.9.0
- Source
wp-includes/blocks/navigation-link.php:311
Compatibility
- WordPress
- since 5.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$entityWP_Taxonomy|WP_Post_Type- post type or taxonomy entity.
$kindstring- string of value 'taxonomy' or 'post-type'.
Return value
array
Performance profile
How much work a call to build_variation_for_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
- Trivial
- Scaling
- Constant
- Instructions
- 57–98
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
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 102.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 24 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost build_variation_for_navigation_link() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!($entity instanceof) && !$title && $title !== "" && !$variation_overrides | 57–75 | __(), __() |
$entity instanceof && !$title && $title !== "" && !$variation_overrides | 59–77 | ::WP_Post_Type(), __(), __() |
!($entity instanceof) && $entity instanceof && !$title && $title !== "" && !$variation_overrides | 60–78 | ::WP_Taxonomy(), __(), __() |
!($entity instanceof) && !$title && $title !== "" && !$variation_overrides | 62–80 | ucfirst(), __(), __() |
!($entity instanceof) && !$variation_overrides | 63–83 | __(), sprintf(), __(), __() |
!($entity instanceof) && !$title && $title !== "" && $variation_overrides | 64–82 | __(), __(), array_merge() |
$entity instanceof && !$title && $title !== "" && !$variation_overrides | 64–82 | ::WP_Post_Type(), ucfirst(), __(), __() |
!($entity instanceof) && $entity instanceof && !$title && $title !== "" && !$variation_overrides | 65–83 | ::WP_Taxonomy(), ucfirst(), __(), __() |
$entity instanceof && !$variation_overrides | 65–85 | ::WP_Post_Type(), __(), sprintf(), __(), __() |
$entity instanceof && !$title && $title !== "" && $variation_overrides | 66–84 | ::WP_Post_Type(), __(), __(), array_merge() |
!($entity instanceof) && $entity instanceof && !$variation_overrides | 66–86 | ::WP_Taxonomy(), __(), sprintf(), __(), __() |
!($entity instanceof) && $entity instanceof && !$title && $title !== "" && $variation_overrides | 67–85 | ::WP_Taxonomy(), __(), __(), array_merge() |
12 further outcomes, up to 98 instructions
!($entity instanceof) && !$variation_overrides | 68–88 | ucfirst(), __(), sprintf(), __(), __() |
!($entity instanceof) && !$title && $title !== "" && $variation_overrides | 69–87 | ucfirst(), __(), __(), array_merge() |
!($entity instanceof) && $variation_overrides | 70–90 | __(), sprintf(), __(), __(), array_merge() |
$entity instanceof && !$variation_overrides | 70–90 | ::WP_Post_Type(), ucfirst(), __(), sprintf(), __(), __() |
$entity instanceof && !$title && $title !== "" && $variation_overrides | 71–89 | ::WP_Post_Type(), ucfirst(), __(), __(), array_merge() |
!($entity instanceof) && $entity instanceof && !$variation_overrides | 71–91 | ::WP_Taxonomy(), ucfirst(), __(), sprintf(), __(), __() |
!($entity instanceof) && $entity instanceof && !$title && $title !== "" && $variation_overrides | 72–90 | ::WP_Taxonomy(), ucfirst(), __(), __(), array_merge() |
$entity instanceof && $variation_overrides | 72–92 | ::WP_Post_Type(), __(), sprintf(), __(), __(), array_merge() |
!($entity instanceof) && $entity instanceof && $variation_overrides | 73–93 | ::WP_Taxonomy(), __(), sprintf(), __(), __(), array_merge() |
!($entity instanceof) && $variation_overrides | 75–95 | ucfirst(), __(), sprintf(), __(), __(), array_merge() |
$entity instanceof && $variation_overrides | 77–97 | ::WP_Post_Type(), ucfirst(), __(), sprintf(), __(), __(), array_merge() |
!($entity instanceof) && $entity instanceof && $variation_overrides | 78–98 | ::WP_Taxonomy(), ucfirst(), __(), sprintf(), __(), __(), array_merge() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 101 | 57–97 | 12 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 102 | 57–98 | 12 | |
| 8.4 | 102 | 57–98 | 12 | 12 fewer instructions than PHP 8.3 |
| 8.3 | 114 | 63–110 | 12 | |
| 8.2 | 114 | 63–110 | 12 | |
| 8.1 | 114 | 63–110 | 12 | |
| 7.4 | 114 | 63–110 | 12 |
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 · 3
- __()Retrieves the translation of $text.
- WP_Post_Type::get_default_labels()Returns the default labels for post types.
- WP_Taxonomy::get_default_labels()Returns the default labels for taxonomies.
Used by · 1
- block_core_navigation_link_build_variations()Returns an array of variations for the navigation link block.
Source code
function build_variation_for_navigation_link( $entity, $kind ) { $title = ''; $description = ''; // Get default labels based on entity type $default_labels = null; if ( $entity instanceof WP_Post_Type ) { $default_labels = WP_Post_Type::get_default_labels(); } elseif ( $entity instanceof WP_Taxonomy ) { $default_labels = WP_Taxonomy::get_default_labels(); } // Get title and check if it's default $is_default_title = false; if ( property_exists( $entity->labels, 'item_link' ) ) { $title = $entity->labels->item_link; if ( isset( $default_labels['item_link'] ) ) { $is_default_title = in_array( $title, $default_labels['item_link'], true ); } } // Get description and check if it's default $is_default_description = false; if ( property_exists( $entity->labels, 'item_link_description' ) ) { $description = $entity->labels->item_link_description; if ( isset( $default_labels['item_link_description'] ) ) { $is_default_description = in_array( $description, $default_labels['item_link_description'], true ); } } // Calculate singular name once (used for both title and description) $singular = $entity->labels->singular_name ?? ucfirst( $entity->name ); // Set default title if needed if ( $is_default_title || '' === $title ) { /* translators: %s: Singular label of the entity. */ $title = sprintf( __( '%s link' ), $singular ); } // Default description if needed. // Use a single space character instead of an empty string to prevent fallback to the // block.json default description ("Add a page, link, or another item to your navigation."). // An empty string would be treated as missing and trigger the fallback, while a single // space appears blank in the UI but prevents the fallback behavior. // We avoid generating descriptions like "A link to a %s" to prevent grammatical errors // (e.g., "A link to a event" should be "A link to an event"). if ( $is_default_description || '' === $description ) { $description = ' '; } $variation = array( 'name' => $entity->name, 'title' => $title, 'description' => $description, 'attributes' => array( 'type' => $entity->name, 'kind' => $kind, ), ); // Tweak some value for the variations. $variation_overrides = array( 'post_tag' => array( 'name' => 'tag', 'attributes' => array( 'type' => 'tag', 'kind' => $kind, ), ), 'post_format' => array( // The item_link and item_link_description for post formats is the // same as for tags, so need to be overridden. 'title' => __( 'Post Format Link' ), 'description' => __( 'A link to a post format' ), 'attributes' => array( 'type' => 'post_format', 'kind' => $kind, ), ), );Changelog
Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.