wp_upgrade() WordPress Function

The wp_upgrade() function is used to upgrade the WordPress database. This function is used to upgrade the WordPress database to a newer version.

wp_upgrade() #

Runs WordPress Upgrade functions.


Description

Upgrades the database if needed during a site update.


Top ↑

Source

File: wp-admin/includes/upgrade.php

	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 );
	}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.