wp_convert_widget_settings( string $base_name, string $option_name, array $settings ): array
- Since
- 2.8.0
- Source
wp-includes/widgets.php:1141
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
$base_namestring- Root ID for all widgets of this type.
$option_namestring- Option name for this widget type.
$settingsarray- The array of widget instance settings.
Return value
array- The array of widget settings converted to multi-widget format.
Performance profile
How much work a call to wp_convert_widget_settings() 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
- Scales with input
- Instructions
- 16–71
- Plugin surface
- None
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 80.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()one call below wp_convert_widget_settings() - cacheobject cache
wp_cache_get()one call below wp_convert_widget_settings() - serializeserialisation
maybe_unserialize()one call below wp_convert_widget_settings()
Further down the call graph this can also reach query 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 · 20 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_convert_widget_settings() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($settings) && !is_admin() | 16 | is_admin() |
!empty($settings) && !is_admin() | 19–25 | array_keys(), is_admin() |
empty($settings) && is_admin() | 20 | is_admin(), update_option() |
!empty($settings) && is_admin() | 23–29 | array_keys(), is_admin(), update_option() |
empty($settings) && !is_admin() && !empty($value) | 31–48 | is_admin(), is_admin(), is_admin() |
empty($settings) && !is_admin() | 32–54 | is_admin(), get_option(), is_admin(), is_admin() |
!empty($settings) && !is_admin() && !empty($value) | 34–57 | array_keys(), is_admin(), is_admin(), is_admin() |
empty($settings) && !empty($value) | 35–52 | is_admin(), is_admin(), is_admin(), update_option() |
!empty($settings) && !is_admin() | 35–63 | array_keys(), is_admin(), get_option(), is_admin(), is_admin() |
empty($settings) && !empty($value) | 36–52 | is_admin(), is_admin(), update_option(), is_admin() |
empty($settings) && is_admin() | 36–58 | is_admin(), get_option(), is_admin(), is_admin(), update_option() |
empty($settings) | 37–58 | is_admin(), get_option(), is_admin(), update_option(), is_admin() |
8 further outcomes, up to 71 instructions
!empty($settings) && !empty($value) | 38–61 | array_keys(), is_admin(), is_admin(), is_admin(), update_option() |
!empty($settings) && !empty($value) | 39–61 | array_keys(), is_admin(), is_admin(), update_option(), is_admin() |
!empty($settings) && is_admin() | 39–67 | array_keys(), is_admin(), get_option(), is_admin(), is_admin(), update_option() |
empty($settings) && !empty($value) | 40–56 | is_admin(), is_admin(), update_option(), is_admin(), update_option() |
!empty($settings) | 40–67 | array_keys(), is_admin(), get_option(), is_admin(), update_option(), is_admin() |
empty($settings) && is_admin() | 41–62 | is_admin(), get_option(), is_admin(), update_option(), is_admin(), update_option() |
!empty($settings) && !empty($value) | 43–65 | array_keys(), is_admin(), is_admin(), update_option(), is_admin(), update_option() |
!empty($settings) && is_admin() | 44–71 | array_keys(), is_admin(), get_option(), is_admin(), update_option(), is_admin(), update_option() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 80 | 16–71 | 17 | |
| 8.5 | 80 | 16–71 | 17 | |
| 8.4 | 80 | 16–71 | 17 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 82 | 16–73 | 17 | |
| 8.2 | 82 | 16–73 | 17 | |
| 8.1 | 82 | 16–73 | 17 | 3 fewer instructions than PHP 7.4 |
| 7.4 | 85 | 16–76 | 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 · 3
- is_admin()Determines whether the current request is for an administrative interface page.
- get_option()Retrieves an option value based on an option name.
- update_option()Updates the value of an option that was already added.
Used by · 1
- WP_Widget::get_settings()Retrieves the settings for all instances of the widget class.
Source code
function wp_convert_widget_settings( $base_name, $option_name, $settings ) { // This test may need expanding. $single = false; $changed = false; if ( empty( $settings ) ) { $single = true; } else { foreach ( array_keys( $settings ) as $number ) { if ( 'number' === $number ) { continue; } if ( ! is_numeric( $number ) ) { $single = true; break; } } } if ( $single ) { $settings = array( 2 => $settings ); // If loading from the front page, update sidebar in memory but don't save to options. if ( is_admin() ) { $sidebars_widgets = get_option( 'sidebars_widgets' ); } else { if ( empty( $GLOBALS['_wp_sidebars_widgets'] ) ) { $GLOBALS['_wp_sidebars_widgets'] = get_option( 'sidebars_widgets', array() ); } $sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets']; } foreach ( (array) $sidebars_widgets as $index => $sidebar ) { if ( is_array( $sidebar ) ) { foreach ( $sidebar as $i => $name ) { if ( $base_name === $name ) { $sidebars_widgets[ $index ][ $i ] = "$name-2"; $changed = true; break 2; } } } } if ( is_admin() && $changed ) { update_option( 'sidebars_widgets', $sidebars_widgets ); } } $settings['_multiwidget'] = 1; if ( is_admin() ) { update_option( $option_name, $settings ); } return $settings;}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 7.1.0 tag, from
src/wp-includes/widgets.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.