upgrade_330()
- Since
- 3.3.0
- Source
wp-admin/includes/upgrade.php:1763
Compatibility
- WordPress
- since 3.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.
Performance profile
How much work a call to upgrade_330() 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
- 9–54
- Plugin surface
- None
- Called by
- 1
Reaches the database via ->query().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 129.
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 - sqldatabase query
->query()called directly - hookthird-party callbacks
apply_filters()one call below upgrade_330() - cacheobject cache
wp_cache_get()one call below upgrade_330() - serializeserialisation
maybe_unserialize()one call below upgrade_330()
Further down the call graph this can also reach transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 9 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost upgrade_330() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9 | none |
$wp_current_db_version && !wp_should_upgrade_global_tables() | 12 | wp_should_upgrade_global_tables() |
$wp_current_db_version && wp_should_upgrade_global_tables() | 19 | wp_should_upgrade_global_tables(), ->query() |
!$wp_current_db_version | 27–30 | get_option() |
!wp_should_upgrade_global_tables() | 30–33 | wp_should_upgrade_global_tables(), get_option() |
!$wp_current_db_version | 35–44 | get_option(), retrieve_widgets(), update_option() |
wp_should_upgrade_global_tables() | 37–40 | wp_should_upgrade_global_tables(), ->query(), get_option() |
!wp_should_upgrade_global_tables() | 38–47 | wp_should_upgrade_global_tables(), get_option(), retrieve_widgets(), update_option() |
wp_should_upgrade_global_tables() | 45–54 | wp_should_upgrade_global_tables(), ->query(), get_option(), retrieve_widgets(), update_option() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 129 | 9–54 | 20 | |
| 8.5 | 129 | 9–54 | 20 | |
| 8.4 | 129 | 9–54 | 20 | |
| 8.3 | 129 | 9–54 | 20 | |
| 8.2 | 129 | 9–54 | 20 | 1 more instruction than PHP 8.1 |
| 8.1 | 128 | 9–56 | 20 | |
| 7.4 | 128 | 9–56 | 20 |
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 · 5
- wp_should_upgrade_global_tables()Determine if global tables should be upgraded.
- get_option()Retrieves an option value based on an option name.
- sanitize_title()Sanitizes a string into a slug, which can be used in URLs or HTML attributes.
- retrieve_widgets()Validates and remaps any "orphaned" widgets to wp_inactive_widgets sidebar, and saves the widget settings. This has to run at least on each theme change.
- update_option()Updates the value of an option that was already added.
Used by · 1
- upgrade_all()Functions to be called in installation and upgrade scripts.
Source code
function upgrade_330() { global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets; if ( $wp_current_db_version < 19061 && wp_should_upgrade_global_tables() ) { $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" ); } if ( $wp_current_db_version >= 11548 ) { return; } $sidebars_widgets = get_option( 'sidebars_widgets', array() ); $_sidebars_widgets = array(); if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) || empty( $sidebars_widgets ) ) { $sidebars_widgets['array_version'] = 3; } elseif ( ! isset( $sidebars_widgets['array_version'] ) ) { $sidebars_widgets['array_version'] = 1; } switch ( $sidebars_widgets['array_version'] ) { case 1: foreach ( (array) $sidebars_widgets as $index => $sidebar ) { if ( is_array( $sidebar ) ) { foreach ( (array) $sidebar as $i => $name ) { $id = strtolower( $name ); if ( isset( $wp_registered_widgets[ $id ] ) ) { $_sidebars_widgets[ $index ][ $i ] = $id; continue; } $id = sanitize_title( $name ); if ( isset( $wp_registered_widgets[ $id ] ) ) { $_sidebars_widgets[ $index ][ $i ] = $id; continue; } $found = false; foreach ( $wp_registered_widgets as $widget_id => $widget ) { if ( strtolower( $widget['name'] ) === strtolower( $name ) ) { $_sidebars_widgets[ $index ][ $i ] = $widget['id']; $found = true; break; } elseif ( sanitize_title( $widget['name'] ) === sanitize_title( $name ) ) { $_sidebars_widgets[ $index ][ $i ] = $widget['id']; $found = true; break; } } if ( $found ) { continue; } unset( $_sidebars_widgets[ $index ][ $i ] ); } } } $_sidebars_widgets['array_version'] = 2; $sidebars_widgets = $_sidebars_widgets; unset( $_sidebars_widgets ); // Intentional fall-through to upgrade to the next version. case 2: $sidebars_widgets = retrieve_widgets(); $sidebars_widgets['array_version'] = 3; update_option( 'sidebars_widgets', $sidebars_widgets ); }}Changelog
Introduced in 3.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 7.1.0 tag, from
src/wp-admin/includes/upgrade.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.