WP_Widget::update_callback( int $deprecated = 1 )
- Since
- 2.8.0
- Source
wp-includes/class-wp-widget.php:411
Compatibility
- WordPress
- since 2.8.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
$deprecatedintoptional- Not used.Default:
1
Performance profile
How much work a call to WP_Widget::update_callback() 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
- 8–97
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via ->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 131.
Third-party callbacks on 'widget_update_callback' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - sqldatabase query
->update()called directly
What one call costs · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Widget::update_callback() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8–33 | ->get_settings() |
isset($value) | 30–51 | ->get_settings(), ->save_settings() |
isset($value) && !$num && !$settings && !->is_preview() | 71–91 | ->get_settings(), stripslashes_deep(), ->_set(), wp_suspend_cache_addition(), ->is_preview(), ->update(), ->is_preview(), apply_filters(), ->save_settings() |
isset($value) && !$num && !$settings && ->is_preview() | 74–94 | ->get_settings(), stripslashes_deep(), ->_set(), wp_suspend_cache_addition(), ->is_preview(), ->update(), ->is_preview(), wp_suspend_cache_addition(), apply_filters(), ->save_settings() |
isset($value) && !$num && !$settings | 75–94 | ->get_settings(), stripslashes_deep(), ->_set(), wp_suspend_cache_addition(), ->is_preview(), wp_suspend_cache_addition(), ->update(), ->is_preview(), apply_filters(), ->save_settings() |
isset($value) && !$num && !$settings && ->is_preview() | 78–97 | ->get_settings(), stripslashes_deep(), ->_set(), wp_suspend_cache_addition(), ->is_preview(), wp_suspend_cache_addition(), ->update(), ->is_preview(), wp_suspend_cache_addition(), apply_filters(), ->save_settings() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 131 | 8–97 | 18 | |
| 8.5 | 131 | 8–97 | 18 | |
| 8.4 | 131 | 8–97 | 18 | |
| 8.3 | 131 | 8–97 | 18 | |
| 8.2 | 131 | 8–97 | 18 | |
| 8.1 | 131 | 8–97 | 18 | 3 fewer instructions than PHP 7.4 |
| 7.4 | 134 | 8–99 | 18 |
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.
Hooks and filters fired · 1
One hook fires while WP_Widget::update_callback() runs, in this order:
- apply_filters( widget_update_callback )filterline 476 (+65 into the body)
Filters a widget's settings before saving.
Uses · 8
- stripslashes_deep()Navigates through an array, object, or scalar, and removes slashes from the values.
- wp_suspend_cache_addition()Temporarily suspends cache additions.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Widget::get_settings()Retrieves the settings for all instances of the widget class.
- WP_Widget::_set()Sets the internal order number for the widget instance.
- WP_Widget::is_preview()Determines whether the current request is inside the Customizer preview.
- WP_Widget::update()Updates a particular instance of a widget.
- WP_Widget::save_settings()Saves the settings for all instances of the widget class.
Source code
public function update_callback( $deprecated = 1 ) { global $wp_registered_widgets; $all_instances = $this->get_settings(); // We need to update the data. if ( $this->updated ) { return; } if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) { // Delete the settings for this instance of the widget. if ( isset( $_POST['the-widget-id'] ) ) { $del_id = $_POST['the-widget-id']; } else { return; } if ( isset( $wp_registered_widgets[ $del_id ]['params'][0]['number'] ) ) { $number = $wp_registered_widgets[ $del_id ]['params'][0]['number']; if ( $this->id_base . '-' . $number === $del_id ) { unset( $all_instances[ $number ] ); } } } else { if ( isset( $_POST[ 'widget-' . $this->id_base ] ) && is_array( $_POST[ 'widget-' . $this->id_base ] ) ) { $settings = $_POST[ 'widget-' . $this->id_base ]; } elseif ( isset( $_POST['id_base'] ) && $_POST['id_base'] === $this->id_base ) { $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number']; $settings = array( $num => array() ); } else { return; } foreach ( $settings as $number => $new_instance ) { $new_instance = stripslashes_deep( $new_instance ); $this->_set( $number ); $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); $was_cache_addition_suspended = wp_suspend_cache_addition(); if ( $this->is_preview() && ! $was_cache_addition_suspended ) { wp_suspend_cache_addition( true ); } $instance = $this->update( $new_instance, $old_instance ); if ( $this->is_preview() ) { wp_suspend_cache_addition( $was_cache_addition_suspended ); } /** * Filters a widget's settings before saving. * * Returning false will effectively short-circuit the widget's ability * to update settings. * * @since 2.8.0 * * @param array $instance The current widget instance's settings. * @param array $new_instance Array of new widget settings. * @param array $old_instance Array of old widget settings. * @param WP_Widget $widget The current widget instance. */ $instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this ); if ( false !== $instance ) { $all_instances[ $number ] = $instance; } break; // Run only once. } } $this->save_settings( $all_instances ); $this->updated = true; }Changelog
Introduced in 2.8.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/class-wp-widget.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.