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
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
- Scaling
- Constant
- Instructions
- 10–62
- Plugin surface
- None
- Called by
- 3
Reaches the database via get_post().
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 79.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_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.
| When | Instructions | Calls it makes |
|---|---|---|
isset($value) && !is_array($value) | 10 | none |
isset($value) && !is_array($value) | 15 | get_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) | 22 | get_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–26 | get_current_blog_id(), ->populate_value() |
!isset($value) && !is_array($value) | 27–32 | get_post(), ->populate_value() |
isset($value) && is_array($value) && isset($type_label) | 27 | get_current_blog_id(), ->get_original_title() |
isset($value) && is_array($value) && !isset($type_label) | 29 | get_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–37 | get_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) | 34 | get_current_blog_id(), ->post_value(), ->get_original_title() |
is_array($value) && !isset($type_label) | 36 | get_current_blog_id(), ->post_value(), ->get_type_label(), ->get_original_title() |
!isset($value) && is_array($value) && isset($type_label) | 37–38 | get_current_blog_id(), ->populate_value(), ->get_original_title() |
!isset($value) && is_array($value) && isset($type_label) | 39–44 | get_post(), ->populate_value(), ->get_original_title() |
!isset($value) && !is_array($value) | 39–43 | get_post(), wp_setup_nav_menu_item(), ->populate_value() |
!isset($value) && is_array($value) && !isset($type_label) | 39–40 | get_current_blog_id(), ->populate_value(), ->get_type_label(), ->get_original_title() |
!isset($value) && is_array($value) && !isset($type_label) | 41–46 | get_post(), ->populate_value(), ->get_type_label(), ->get_original_title() |
!isset($value) && is_array($value) && isset($type_label) | 44–49 | get_current_blog_id(), get_post(), ->populate_value(), ->get_original_title() |
!isset($value) && !is_array($value) | 44–48 | get_current_blog_id(), get_post(), wp_setup_nav_menu_item(), ->populate_value() |
!isset($value) && is_array($value) && !isset($type_label) | 46–51 | get_current_blog_id(), get_post(), ->populate_value(), ->get_type_label(), ->get_original_title() |
!isset($value) && is_array($value) && isset($type_label) | 51–55 | get_post(), wp_setup_nav_menu_item(), ->populate_value(), ->get_original_title() |
!isset($value) && is_array($value) && !isset($type_label) | 53–57 | get_post(), wp_setup_nav_menu_item(), ->populate_value(), ->get_type_label(), ->get_original_title() |
!isset($value) && is_array($value) && isset($type_label) | 56–60 | get_current_blog_id(), get_post(), wp_setup_nav_menu_item(), ->populate_value(), ->get_original_title() |
!isset($value) && is_array($value) && !isset($type_label) | 58–62 | get_current_blog_id(), get_post(), wp_setup_nav_menu_item(), ->populate_value(), ->get_type_label(), ->get_original_title() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 78 | 10–61 | 12 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 79 | 10–62 | 12 | |
| 8.4 | 79 | 10–62 | 12 | |
| 8.3 | 79 | 10–62 | 12 | |
| 8.2 | 79 | 10–62 | 12 | |
| 8.1 | 79 | 10–62 | 12 | |
| 7.4 | 79 | 10–62 | 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 · 8
- get_current_blog_id()Retrieves the current site ID.
- get_post()Retrieves post data given a post ID or post object.
- wp_setup_nav_menu_item()Decorates a menu item object with the shared navigation menu item properties.
- stdClass::__construct()
- WP_Customize_Nav_Menu_Item_Setting::post_value()
- WP_Customize_Nav_Menu_Item_Setting::populate_value()Ensure that the value is fully populated with the necessary properties.
- WP_Customize_Nav_Menu_Item_Setting::get_type_label()Get type label.
- WP_Customize_Nav_Menu_Item_Setting::get_original_title()Get original title.
Used by · 3
- WP_Customize_Nav_Menu_Item_Setting::filter_wp_get_nav_menu_items()Filters the wp_get_nav_menu_items() result to supply the previewed menu items.
- WP_Customize_Nav_Menu_Item_Setting::preview()Handle previewing the setting.
- WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item()Get the value emulated into a WP_Post and set up as a nav_menu_item.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.