wppaste
WordPress

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
Returns a navigation link variation

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

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
57–98

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

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.

WhenInstructionsCalls it makes
!($entity instanceof) && !$title && $title !== "" && !$variation_overrides57–75__(), __()
$entity instanceof && !$title && $title !== "" && !$variation_overrides59–77::WP_Post_Type(), __(), __()
!($entity instanceof) && $entity instanceof && !$title && $title !== "" && !$variation_overrides60–78::WP_Taxonomy(), __(), __()
!($entity instanceof) && !$title && $title !== "" && !$variation_overrides62–80ucfirst(), __(), __()
!($entity instanceof) && !$variation_overrides63–83__(), sprintf(), __(), __()
!($entity instanceof) && !$title && $title !== "" && $variation_overrides64–82__(), __(), array_merge()
$entity instanceof && !$title && $title !== "" && !$variation_overrides64–82::WP_Post_Type(), ucfirst(), __(), __()
!($entity instanceof) && $entity instanceof && !$title && $title !== "" && !$variation_overrides65–83::WP_Taxonomy(), ucfirst(), __(), __()
$entity instanceof && !$variation_overrides65–85::WP_Post_Type(), __(), sprintf(), __(), __()
$entity instanceof && !$title && $title !== "" && $variation_overrides66–84::WP_Post_Type(), __(), __(), array_merge()
!($entity instanceof) && $entity instanceof && !$variation_overrides66–86::WP_Taxonomy(), __(), sprintf(), __(), __()
!($entity instanceof) && $entity instanceof && !$title && $title !== "" && $variation_overrides67–85::WP_Taxonomy(), __(), __(), array_merge()
12 further outcomes, up to 98 instructions
!($entity instanceof) && !$variation_overrides68–88ucfirst(), __(), sprintf(), __(), __()
!($entity instanceof) && !$title && $title !== "" && $variation_overrides69–87ucfirst(), __(), __(), array_merge()
!($entity instanceof) && $variation_overrides70–90__(), sprintf(), __(), __(), array_merge()
$entity instanceof && !$variation_overrides70–90::WP_Post_Type(), ucfirst(), __(), sprintf(), __(), __()
$entity instanceof && !$title && $title !== "" && $variation_overrides71–89::WP_Post_Type(), ucfirst(), __(), __(), array_merge()
!($entity instanceof) && $entity instanceof && !$variation_overrides71–91::WP_Taxonomy(), ucfirst(), __(), sprintf(), __(), __()
!($entity instanceof) && $entity instanceof && !$title && $title !== "" && $variation_overrides72–90::WP_Taxonomy(), ucfirst(), __(), __(), array_merge()
$entity instanceof && $variation_overrides72–92::WP_Post_Type(), __(), sprintf(), __(), __(), array_merge()
!($entity instanceof) && $entity instanceof && $variation_overrides73–93::WP_Taxonomy(), __(), sprintf(), __(), __(), array_merge()
!($entity instanceof) && $variation_overrides75–95ucfirst(), __(), sprintf(), __(), __(), array_merge()
$entity instanceof && $variation_overrides77–97::WP_Post_Type(), ucfirst(), __(), sprintf(), __(), __(), array_merge()
!($entity instanceof) && $entity instanceof && $variation_overrides78–98::WP_Taxonomy(), ucfirst(), __(), sprintf(), __(), __(), array_merge()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev10157–97121 fewer instruction than PHP 8.5
8.510257–9812
8.410257–981212 fewer instructions than PHP 8.3
8.311463–11012
8.211463–11012
8.111463–11012
7.411463–11012

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

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.