On this page
wp_upgrade()
Runs WordPress Upgrade functions.
Description
Upgrades the database if needed during a site update.
Source
File: wp-admin/includes/upgrade.php. View all references
function wp_upgrade() {
global $wp_current_db_version, $wp_db_version, $wpdb;
$wp_current_db_version = __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() );
}
/**
* 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 );
}
Hooks
- do_action( 'wp_upgrade',
int $wp_db_version ,int $wp_current_db_version ) -
Fires after a site is fully upgraded.
Related
Uses
| Uses | Description |
|---|---|
| update_site_meta() wp-includes/ms-site.php | Updates metadata for a site. |
| wp_check_mysql_version() wp-admin/includes/upgrade.php | Checks the version of the installed MySQL binary. |
| pre_schema_upgrade() wp-admin/includes/upgrade.php | Runs before the schema is upgraded. |
| make_db_current_silent() wp-admin/includes/upgrade.php | Updates the database tables to a new schema, but without displaying results. |
| upgrade_network() wp-admin/includes/upgrade.php | Executes network-level upgrade routines. |
| wp_cache_flush() wp-includes/cache.php | Removes all cache items. |
| is_main_site() wp-includes/functions.php | Determines whether a site is the main site of the current network. |
| is_blog_installed() wp-includes/functions.php | Determines whether WordPress is already installed. |
| is_multisite() wp-includes/load.php | If Multisite is enabled. |
| get_current_blog_id() wp-includes/load.php | Retrieve the current site ID. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_upgrade