wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_upgrade › WordPress Function

Since2.1.0
Deprecatedn/a
wp_upgrade ( No parameters )
Defined at:
Codex:

Runs WordPress Upgrade functions.

Upgrades the database if needed during a site update.


Source

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

/**
 * Functions to be called in installation and upgrade scripts.
 *
 * Contains conditional checks to determine which upgrade scripts to run,
 * based on database version and WP version being updated-to.
 *
 * @ignore
 * @since 1.0.1
 *
 * @global int $wp_current_db_version The old (current) database version.
 * @global int $wp_db_version         The new database version.
 */
function upgrade_all() {
	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 the version is not set in the DB, try to guess the version.
	if ( empty( $wp_current_db_version ) ) {
		$wp_current_db_version = 0;

		// If the template option exists, we have 1.5.
		$template = __get_option( 'template' );
		if ( ! empty( $template ) ) {
			$wp_current_db_version = 2541;
		}
	}

	if ( $wp_current_db_version < 6039 ) {
		upgrade_230_options_table();
	}

	populate_options();

	if ( $wp_current_db_version < 2541 ) {
		upgrade_100();
		upgrade_101();
		upgrade_110();
		upgrade_130();
	}

	if ( $wp_current_db_version < 3308 ) {
		upgrade_160();
	}

	if ( $wp_current_db_version < 4772 ) {
		upgrade_210();
	}

	if ( $wp_current_db_version < 4351 ) {
		upgrade_old_slugs();
	}

	if ( $wp_current_db_version < 5539 ) {
		upgrade_230();
	}

	if ( $wp_current_db_version < 6124 ) {
		upgrade_230_old_tables();
	}

	if ( $wp_current_db_version < 7499 ) {
		upgrade_250();
	}

	if ( $wp_current_db_version < 7935 ) {
		upgrade_252();
	}

	if ( $wp_current_db_version < 8201 ) {
		upgrade_260();
	}

	if ( $wp_current_db_version < 8989 ) {
		upgrade_270();
	}

	if ( $wp_current_db_version < 10360 ) {
		upgrade_280();
	}

	if ( $wp_current_db_version < 11958 ) {
		upgrade_290();
	}

	if ( $wp_current_db_version < 15260 ) {
		upgrade_300();
	}

	if ( $wp_current_db_version < 19389 ) {
		upgrade_330();
	}

	if ( $wp_current_db_version < 20080 ) {
		upgrade_340();
	}

	if ( $wp_current_db_version < 22422 ) {
		upgrade_350();
	}

	if ( $wp_current_db_version < 25824 ) {
		upgrade_370();
	}

	if ( $wp_current_db_version < 26148 ) {
		upgrade_372();
	}

	if ( $wp_current_db_version < 26691 ) {
		upgrade_380();
	}

	if ( $wp_current_db_version < 29630 ) {
		upgrade_400();
	}

	if ( $wp_current_db_version < 33055 ) {
		upgrade_430();
	}

	if ( $wp_current_db_version < 33056 ) {
		upgrade_431();
	}

	if ( $wp_current_db_version < 35700 ) {
		upgrade_440();
	}

	if ( $wp_current_db_version < 36686 ) {
		upgrade_450();
	}

	if ( $wp_current_db_version < 37965 ) {
		upgrade_460();
	}

	if ( $wp_current_db_version < 44719 ) {
		upgrade_510();
	}

	if ( $wp_current_db_version < 45744 ) {
		upgrade_530();
	}

	if ( $wp_current_db_version < 48575 ) {
		upgrade_550();
	}

	if ( $wp_current_db_version < 49752 ) {
		upgrade_560();
	}

	if ( $wp_current_db_version < 51917 ) {
		upgrade_590();
	}

	if ( $wp_current_db_version < 53011 ) {
		upgrade_600();
	}

	if ( $wp_current_db_version < 55853 ) {
		upgrade_630();
	}

	if ( $wp_current_db_version < 56657 ) {
		upgrade_640();
	}

	if ( $wp_current_db_version < 57155 ) {
		upgrade_650();
	}

	if ( $wp_current_db_version < 58975 ) {
		upgrade_670();
	}
	maybe_disable_link_manager();

	maybe_disable_automattic_widgets();

	update_option( 'db_version', $wp_db_version );
	update_option( 'db_upgraded', true );
}