WP_Customize_Nav_Menu_Item_Setting::update( array|false $value ): bool
- Since
- 4.3.0, 7.0.0
- Source
wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:771
Description
Any created menu items will have their assigned post IDs exported to the client via the 'customize_save_response' filter. Likewise, any errors will be exported to the client via the customize_save_response() filter.
To delete a menu, the client can send false as the value.
Compatibility
- WordPress
- since 7.0.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
$valuearray|false- The menu item array to update. If false, then the menu item will be deleted entirely. See WP_Customize_Nav_Menu_Item_Setting::$default for what the value should consist of.
Return value
bool- Whether updated.
Performance profile
How much work a call to WP_Customize_Nav_Menu_Item_Setting::update() 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
- 6–129
- Plugin surface
- None
- Called by
- 0
Reaches the database via WP_Customize_Nav_Menu_Item_Setting::update().
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 212.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- sqldatabase query
WP_Customize_Nav_Menu_Item_Setting::update()this function does it - querycontent query
get_post()one call below WP_Customize_Nav_Menu_Item_Setting::update() - hookthird-party callbacks
apply_filters()one call below WP_Customize_Nav_Menu_Item_Setting::update()
Further down the call graph this can also reach cache, option, transient and serialize. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 10 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::update() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6–25 | none |
$value === false && $r !== false | 34 | wp_delete_post() |
$value !== false | 39–44 | ->get_setting() |
$value === false && $r === false | 39 | wp_delete_post(), add_filter() |
$value !== false | 45–53 | ->get_setting(), ->save() |
$value !== false && $nav_menu_setting instanceof | 66–68 | ->get_setting(), ->save(), ->get_setting() |
$value !== false && $nav_menu_setting instanceof && $parent_nav_menu_item_setting instanceof | 72–77 | ->get_setting(), ->save(), ->get_setting(), ->save() |
$value !== false | 74–81 | wp_slash(), wp_update_nav_menu_item(), is_wp_error() |
$value !== false | 98–105 | ->get_setting(), ->save(), wp_slash(), wp_update_nav_menu_item(), is_wp_error() |
$value !== false && $nav_menu_setting instanceof && $parent_nav_menu_item_setting instanceof | 122–129 | ->get_setting(), ->save(), ->get_setting(), ->save(), wp_slash(), wp_update_nav_menu_item(), is_wp_error() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 212 | 6–129 | 17 | |
| 8.5 | 212 | 6–129 | 17 | |
| 8.4 | 212 | 6–129 | 17 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 216 | 6–133 | 17 | |
| 8.2 | 216 | 6–133 | 17 | |
| 8.1 | 216 | 6–133 | 17 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 217 | 6–133 | 17 |
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 · 6
- add_filter()Adds a callback function to a filter hook.
- wp_delete_post()Trashes or deletes a post or page.
- wp_update_nav_menu_item()Saves the properties of a menu item or create a new one.
- wp_slash()Adds slashes to a string or recursively adds slashes to strings within an array.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- WP_Error::__construct()Initializes the error.
Source code
protected function update( $value ) { if ( $this->is_updated ) { return ( 'error' !== $this->update_status ); } $this->is_updated = true; $is_placeholder = ( $this->post_id < 0 ); $is_delete = ( false === $value ); // Update the cached value. $this->value = $value; add_filter( 'customize_save_response', array( $this, 'amend_customize_save_response' ) ); if ( $is_delete ) { // If the current setting post is a placeholder, a delete request is a no-op. if ( $is_placeholder ) { $this->update_status = 'deleted'; } else { $r = wp_delete_post( $this->post_id, true ); if ( false === $r ) { $this->update_error = new WP_Error( 'delete_failure' ); $this->update_status = 'error'; } else { $this->update_status = 'deleted'; } // @todo send back the IDs for all associated nav menu items deleted, so these settings (and controls) can be removed from Customizer? } } else { // Handle saving menu items for menus that are being newly-created. if ( $value['nav_menu_term_id'] < 0 ) { $nav_menu_setting_id = sprintf( 'nav_menu[%s]', $value['nav_menu_term_id'] ); $nav_menu_setting = $this->manager->get_setting( $nav_menu_setting_id ); if ( ! $nav_menu_setting || ! ( $nav_menu_setting instanceof WP_Customize_Nav_Menu_Setting ) ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'unexpected_nav_menu_setting' ); return false; } if ( false === $nav_menu_setting->save() ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'nav_menu_setting_failure' ); return false; } if ( (int) $value['nav_menu_term_id'] !== $nav_menu_setting->previous_term_id ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'unexpected_previous_term_id' ); return false; } $value['nav_menu_term_id'] = $nav_menu_setting->term_id; } // Handle saving a nav menu item that is a child of a nav menu item being newly-created. if ( $value['menu_item_parent'] < 0 ) { $parent_nav_menu_item_setting_id = sprintf( 'nav_menu_item[%s]', $value['menu_item_parent'] ); $parent_nav_menu_item_setting = $this->manager->get_setting( $parent_nav_menu_item_setting_id ); if ( ! $parent_nav_menu_item_setting || ! ( $parent_nav_menu_item_setting instanceof WP_Customize_Nav_Menu_Item_Setting ) ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'unexpected_nav_menu_item_setting' ); return false; } if ( false === $parent_nav_menu_item_setting->save() ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'nav_menu_item_setting_failure' ); return false; } if ( (int) $value['menu_item_parent'] !== $parent_nav_menu_item_setting->previous_post_id ) { $this->update_status = 'error'; $this->update_error = new WP_Error( 'unexpected_previous_post_id' ); return false; }Changelog
Introduced in 4.3.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
null|void to bool.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.