wppaste
WordPress

WP_Customize_Nav_Menu_Item_Setting::populate_value()

Since
4.3.0
Source
wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:353
Ensure that the value is fully populated with the necessary properties.

Description

Translates some properties added by wp_setup_nav_menu_item() and removes others.

Compatibility

WordPress
since 4.3.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.

Performance profile

How much work a call to WP_Customize_Nav_Menu_Item_Setting::populate_value() 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 wp_get_object_terms().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
25–96

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent querywp_get_object_terms()one call below WP_Customize_Nav_Menu_Item_Setting::populate_value()

Further down the call graph this can also reach hook, option, 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 · 12 distinct outcomes

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

WhenInstructionsCalls it makes
always25–68none
!isset($value)42–76post_type_exists()
!isset($value) && empty($menus)42–81wp_get_post_terms()
!isset($value) && !empty($menus)46–79wp_get_post_terms(), array_shift()
!isset($value)49–75taxonomy_exists()
!isset($value) && $value53–83post_type_exists(), taxonomy_exists()
!isset($value) && empty($menus)59–89wp_get_post_terms(), post_type_exists()
!isset($value) && !empty($menus)63–87wp_get_post_terms(), array_shift(), post_type_exists()
!isset($value) && empty($menus)66–88wp_get_post_terms(), taxonomy_exists()
!isset($value) && empty($menus) && $value70–96wp_get_post_terms(), post_type_exists(), taxonomy_exists()
!isset($value) && !empty($menus)70–86wp_get_post_terms(), array_shift(), taxonomy_exists()
!isset($value) && !empty($menus) && $value74–94wp_get_post_terms(), array_shift(), post_type_exists(), taxonomy_exists()

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-dev13025–9621
8.513025–9621
8.413025–96213 fewer instructions than PHP 8.3
8.313325–9621
8.213325–9621
8.113325–9621
7.413325–9621

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

Source code

	protected function populate_value() {		if ( ! is_array( $this->value ) ) {			return;		} 		if ( isset( $this->value['menu_order'] ) ) {			$this->value['position'] = $this->value['menu_order'];			unset( $this->value['menu_order'] );		}		if ( isset( $this->value['post_status'] ) ) {			$this->value['status'] = $this->value['post_status'];			unset( $this->value['post_status'] );		} 		if ( ! isset( $this->value['nav_menu_term_id'] ) && $this->post_id > 0 ) {			$menus = wp_get_post_terms(				$this->post_id,				WP_Customize_Nav_Menu_Setting::TAXONOMY,				array(					'fields' => 'ids',				)			);			if ( ! empty( $menus ) ) {				$this->value['nav_menu_term_id'] = array_shift( $menus );			} else {				$this->value['nav_menu_term_id'] = 0;			}		} 		foreach ( array( 'object_id', 'menu_item_parent', 'nav_menu_term_id' ) as $key ) {			if ( ! is_int( $this->value[ $key ] ) ) {				$this->value[ $key ] = (int) $this->value[ $key ];			}		}		foreach ( array( 'classes', 'xfn' ) as $key ) {			if ( is_array( $this->value[ $key ] ) ) {				$this->value[ $key ] = implode( ' ', $this->value[ $key ] );			}		} 		if ( ! isset( $this->value['title'] ) ) {			$this->value['title'] = '';		} 		if ( ! isset( $this->value['_invalid'] ) ) {			$this->value['_invalid'] = false;			$is_known_invalid        = (				( ( 'post_type' === $this->value['type'] || 'post_type_archive' === $this->value['type'] ) && ! post_type_exists( $this->value['object'] ) )				||				( 'taxonomy' === $this->value['type'] && ! taxonomy_exists( $this->value['object'] ) )			);			if ( $is_known_invalid ) {				$this->value['_invalid'] = true;			}		} 		// Remove remaining properties available on a setup nav_menu_item post object which aren't relevant to the setting value.		$irrelevant_properties = array(			'ID',			'comment_count',			'comment_status',			'db_id',			'filter',			'guid',			'ping_status',			'pinged',			'post_author',			'post_content',			'post_content_filtered',			'post_date',			'post_date_gmt',			'post_excerpt',			'post_mime_type',			'post_modified',			'post_modified_gmt',			'post_name',			'post_parent',			'post_password',			'post_title',			'post_type',

Changelog

Introduced in 4.3.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.0.4 tag, from src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.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.