wppaste
WordPress

WP_Customize_Nav_Menu_Item_Setting::value(): array|false

Since
4.3.0
Source
wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:211
Get the instance data for a given nav_menu_item setting.

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.

Return value

array|false
Instance data array, or false if the item is marked for deletion.

Performance profile

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

Scaling
Constant

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

Instructions
10–62

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

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

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()one call below WP_Customize_Nav_Menu_Item_Setting::value()

Further down the call graph this can also reach 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 · 27 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::value() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
isset($value) && !is_array($value)10none
isset($value) && !is_array($value)15get_current_blog_id()
!isset($value) && !is_array($value)20–21->populate_value()
isset($value) && is_array($value) && isset($type_label)22->get_original_title()
!is_array($value)22get_current_blog_id(), ->post_value()
isset($value) && is_array($value) && !isset($type_label)24->get_type_label(), ->get_original_title()
!isset($value) && !is_array($value)25–26get_current_blog_id(), ->populate_value()
!isset($value) && !is_array($value)27–32get_post(), ->populate_value()
isset($value) && is_array($value) && isset($type_label)27get_current_blog_id(), ->get_original_title()
isset($value) && is_array($value) && !isset($type_label)29get_current_blog_id(), ->get_type_label(), ->get_original_title()
!isset($value) && is_array($value) && isset($type_label)32–33->populate_value(), ->get_original_title()
!isset($value) && !is_array($value)32–37get_current_blog_id(), get_post(), ->populate_value()
15 further outcomes, up to 62 instructions
!isset($value) && is_array($value) && !isset($type_label)34–35->populate_value(), ->get_type_label(), ->get_original_title()
is_array($value) && isset($type_label)34get_current_blog_id(), ->post_value(), ->get_original_title()
is_array($value) && !isset($type_label)36get_current_blog_id(), ->post_value(), ->get_type_label(), ->get_original_title()
!isset($value) && is_array($value) && isset($type_label)37–38get_current_blog_id(), ->populate_value(), ->get_original_title()
!isset($value) && is_array($value) && isset($type_label)39–44get_post(), ->populate_value(), ->get_original_title()
!isset($value) && !is_array($value)39–43get_post(), wp_setup_nav_menu_item(), ->populate_value()
!isset($value) && is_array($value) && !isset($type_label)39–40get_current_blog_id(), ->populate_value(), ->get_type_label(), ->get_original_title()
!isset($value) && is_array($value) && !isset($type_label)41–46get_post(), ->populate_value(), ->get_type_label(), ->get_original_title()
!isset($value) && is_array($value) && isset($type_label)44–49get_current_blog_id(), get_post(), ->populate_value(), ->get_original_title()
!isset($value) && !is_array($value)44–48get_current_blog_id(), get_post(), wp_setup_nav_menu_item(), ->populate_value()
!isset($value) && is_array($value) && !isset($type_label)46–51get_current_blog_id(), get_post(), ->populate_value(), ->get_type_label(), ->get_original_title()
!isset($value) && is_array($value) && isset($type_label)51–55get_post(), wp_setup_nav_menu_item(), ->populate_value(), ->get_original_title()
!isset($value) && is_array($value) && !isset($type_label)53–57get_post(), wp_setup_nav_menu_item(), ->populate_value(), ->get_type_label(), ->get_original_title()
!isset($value) && is_array($value) && isset($type_label)56–60get_current_blog_id(), get_post(), wp_setup_nav_menu_item(), ->populate_value(), ->get_original_title()
!isset($value) && is_array($value) && !isset($type_label)58–62get_current_blog_id(), get_post(), wp_setup_nav_menu_item(), ->populate_value(), ->get_type_label(), ->get_original_title()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7810–61121 fewer instruction than PHP 8.5
8.57910–6212
8.47910–6212
8.37910–6212
8.27910–6212
8.17910–6212
7.47910–6212

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

Used by · 3

Source code

	public function value() {		$type_label = null;		if ( $this->is_previewed && get_current_blog_id() === $this->_previewed_blog_id ) {			$undefined  = new stdClass(); // Symbol.			$post_value = $this->post_value( $undefined ); 			if ( $undefined === $post_value ) {				$value = $this->_original_value;			} else {				$value = $post_value;			}		} elseif ( isset( $this->value ) ) {			$value = $this->value;		} else {			$value = false; 			// Note that an ID of less than one indicates a nav_menu not yet inserted.			if ( $this->post_id > 0 ) {				$post = get_post( $this->post_id );				if ( $post && self::POST_TYPE === $post->post_type ) {					$is_title_empty = empty( $post->post_title );					$value          = (array) wp_setup_nav_menu_item( $post );					if ( isset( $value['type_label'] ) ) {						$type_label = $value['type_label'];					}					if ( $is_title_empty ) {						$value['title'] = '';					}				}			} 			if ( ! is_array( $value ) ) {				$value = $this->default;			} 			// Cache the value for future calls to avoid having to re-call wp_setup_nav_menu_item().			$this->value = $value;			$this->populate_value();			$value = $this->value;		} 		// These properties are read-only and are part of the setting for use in the Customizer UI.		if ( is_array( $value ) ) {			$value_obj               = (object) $value;			$value['type_label']     = isset( $type_label ) ? $type_label : $this->get_type_label( $value_obj );			$value['original_title'] = $this->get_original_title( $value_obj );		} 		return $value;	}

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