wp_upgrade()
- Since
- 2.1.0
- Source
wp-admin/includes/upgrade.php:660
Description
Upgrades the database if needed during a site update.
Compatibility
- WordPress
- since 2.1.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 wp_upgrade() 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
- Moderate
- Scaling
- Constant
- Instructions
- 10–60
- Plugin surface
- 1 hook
- Called by
- 0
Reads stored settings via update_option(), cached per request but not free on a cold cache.
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 62.
Third-party callbacks on 'wp_upgrade' 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
- cacheobject cache
wp_cache_flush()called directly - transienttransient
delete_transient()called directly - hookthird-party callbacks
do_action()called directly - serializeserialisation
maybe_unserialize()one call below wp_upgrade() - optionoption read or write
update_option()one call below wp_upgrade()
Further down the call graph this can also reach query. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_upgrade() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$wp_db_version === false | 10 | __get_option() |
$wp_db_version !== false && !is_blog_installed() | 13 | __get_option(), is_blog_installed() |
$wp_db_version !== false && is_blog_installed() && !is_multisite() | 39 | __get_option(), is_blog_installed(), wp_check_mysql_version(), wp_cache_flush(), pre_schema_upgrade(), make_db_current_silent(), upgrade_all(), is_multisite(), wp_cache_flush(), is_multisite(), delete_transient(), do_action() |
$wp_db_version !== false && is_blog_installed() && !is_main_site() | 42 | __get_option(), is_blog_installed(), wp_check_mysql_version(), wp_cache_flush(), pre_schema_upgrade(), make_db_current_silent(), upgrade_all(), is_multisite(), is_main_site(), wp_cache_flush(), is_multisite(), delete_transient(), do_action() |
$wp_db_version !== false && is_blog_installed() && is_main_site() | 44 | __get_option(), is_blog_installed(), wp_check_mysql_version(), wp_cache_flush(), pre_schema_upgrade(), make_db_current_silent(), upgrade_all(), is_multisite(), is_main_site(), upgrade_network(), wp_cache_flush(), is_multisite(), delete_transient(), do_action() |
$wp_db_version !== false && is_blog_installed() | 55 | __get_option(), is_blog_installed(), wp_check_mysql_version(), wp_cache_flush(), pre_schema_upgrade(), make_db_current_silent(), upgrade_all(), is_multisite(), wp_cache_flush(), is_multisite(), get_current_blog_id(), update_site_meta(), get_current_blog_id(), microtime(), update_site_meta(), delete_transient(), do_action() |
$wp_db_version !== false && is_blog_installed() && is_multisite() && !is_main_site() | 58 | __get_option(), is_blog_installed(), wp_check_mysql_version(), wp_cache_flush(), pre_schema_upgrade(), make_db_current_silent(), upgrade_all(), is_multisite(), is_main_site(), wp_cache_flush(), is_multisite(), get_current_blog_id(), update_site_meta(), get_current_blog_id(), microtime(), update_site_meta(), delete_transient(), do_action() |
$wp_db_version !== false && is_blog_installed() && is_multisite() && is_main_site() | 60 | __get_option(), is_blog_installed(), wp_check_mysql_version(), wp_cache_flush(), pre_schema_upgrade(), make_db_current_silent(), upgrade_all(), is_multisite(), is_main_site(), upgrade_network(), wp_cache_flush(), is_multisite(), get_current_blog_id(), update_site_meta(), get_current_blog_id(), microtime(), update_site_meta(), delete_transient(), do_action() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 62 instructions, 10–60 executed per call, 5 branches. The work does not change between versions.
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_upgrade() runs, in this order:
Uses · 14
- __get_option()Utility version of get_option that is private to installation/upgrade.
- is_blog_installed()Determines whether WordPress is already installed.
- wp_check_mysql_version()Checks the version of the installed MySQL binary.
- wp_cache_flush()Removes all cache items.
- pre_schema_upgrade()Runs before the schema is upgraded.
- make_db_current_silent()Updates the database tables to a new schema, but without displaying results.
- upgrade_all()Functions to be called in installation and upgrade scripts.
- is_multisite()Determines whether Multisite is enabled.
- is_main_site()Determines whether a site is the main site of the current network.
- upgrade_network()Executes network-level upgrade routines.
- update_site_meta()Updates metadata for a site.
- get_current_blog_id()Retrieves the current site ID.
Show all 14
- delete_transient()Deletes a transient.
- do_action()Calls the callback functions that have been added to an action hook.
Source code
function wp_upgrade() { global $wp_current_db_version, $wp_db_version; $wp_current_db_version = (int) __get_option( 'db_version' ); // We are up to date. Nothing to do. if ( $wp_db_version === $wp_current_db_version ) { return; } if ( ! is_blog_installed() ) { return; } wp_check_mysql_version(); wp_cache_flush(); pre_schema_upgrade(); make_db_current_silent(); upgrade_all(); if ( is_multisite() && is_main_site() ) { upgrade_network(); } wp_cache_flush(); if ( is_multisite() ) { update_site_meta( get_current_blog_id(), 'db_version', $wp_db_version ); update_site_meta( get_current_blog_id(), 'db_last_updated', microtime() ); } delete_transient( 'wp_core_block_css_files' ); /** * Fires after a site is fully upgraded. * * @since 3.9.0 * * @param int $wp_db_version The new $wp_db_version. * @param int $wp_current_db_version The old (current) $wp_db_version. */ do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version ); }Changelog
Introduced in 2.1.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.