Index: wp-admin/includes/upgrade.php
===================================================================
--- wp-admin/includes/upgrade.php	(revision 6519)
+++ wp-admin/includes/upgrade.php	(working copy)
@@ -144,11 +144,13 @@
 	if ( $wp_db_version == $wp_current_db_version )
 		return;
 
+	$plugin_results = wp_call_pre_upgrade_hook();
 	wp_check_mysql_version();
 	wp_cache_flush();
 	make_db_current_silent();
 	upgrade_all();
 	wp_cache_flush();
+	wp_call_post_upgrade_hook($plugin_results);
 }
 endif;
 
@@ -1243,6 +1245,111 @@
 	}
 }
 
+/**
+ * plugin_disable_self() - When called will disable the current plugin
+ *
+ * Allows plugins a simple way to disable their plugin during the
+ * pre-upgrade process. The plugin just has to call the function and it
+ * will do all the work.
+ *
+ * Also a safer way, in case the way plugins are enabled changes.
+ *
+ * @uses $current_plugin_processed Disables current plugin
+ */
+function plugin_disable_self() {
+	global $current_plugin_processed;
+
+	$plugins = __get_option( 'active_plugins' );
+
+	foreach ( (array) $plugins as $plugin ) {
+		if ( $current_plugin_processed == $plugin ) {
+			array_splice( $plugins, array_search( $plugin, $plugins ), 1 );
+			update_option( 'active_plugins', $plugins );
+			break;
+		}
+	}
+}
+
+/**
+ * plugin_enable_self() - When called will enable the current plugin
+ *
+ * Companion of plugin_disable_self(), will enable the plugin if it disabled
+ * itself. Real simple way of enabling a plugin that disabled itself and is
+ * future proof, in case the plugin activation is changed.
+ *
+ * @uses $current_plugin_processed Enables the current plugin
+ */
+function plugin_enable_self() {
+	global $current_plugin_processed;
+
+	$plugins = __get_option( 'active_plugins' );
+
+	// Prevent duplicate plugin entries if the plugin did not disable itself.
+	if( false === in_array($current_plugin_processed, $plugins) )
+		$plugins[] = $current_plugin_processed;
+
+	sort($plugins);
+	update_option( 'active_plugins', $plugins );
+}
+
+/**
+ * Called before upgrade for plugins to clean up.
+ *
+ * Plugins must not die during their call. Plugins will be able to enable themselves
+ * after the upgrade has been made and the result of the pre-upgrade hook will be passed
+ * to the post upgrade plugin hook.
+ *
+ * @uses apply_filters() Calls pre_upgrade_PLUGIN PLUGIN is the path from PLUGINDIR.
+ * @global string $current_plugin_processed Sets the current plugin processed value
+ * @since 2.4
+ *
+ * @returns array The results of the plugins upgrade hook
+ */
+function wp_call_pre_upgrade_hook()
+{
+	global $current_plugin_processed;
+
+	$plugin_pre_upgrade = array();
+	$current_plugins = __get_option('active_plugins');
+	if ( is_array($current_plugins) ) {
+		foreach ($current_plugins as $plugin) {
+			if ('' != $plugin && file_exists(ABSPATH . PLUGINDIR . '/' . $plugin)) {
+				// Use '@' to prevent errors from halting the rest of the upgrade process
+				@include_once(ABSPATH . PLUGINDIR . '/' . $plugin);
+
+				$current_plugin_processed = $plugin;
+				$plugin_pre_upgrade[ $plugin ] = apply_filters('pre_upgrade_'.$plugin, null);
+			}
+		}
+	}
+
+	return $plugin_pre_upgrade;
+}
+
+/**
+ * Called for plugins after the WordPress upgrade process has been made.
+ *
+ * The result of the pre-upgrade process for the plugin is passed to the plugin
+ * from the pre upgrade process. The plugin can use this as they will. The plugin
+ * may also  output their status for the user to see on the upgrade page to provide
+ * feedback.
+ *
+ * @uses do_action() Calls post_upgrade_PLUGIN where PLUGIN is the path of the plugin from PLUGINDIR
+ * @since 2.4
+ * @param array $pre_upgrade Passed the array from the pre upgrade
+ */
+function wp_call_post_upgrade_hook($pre_upgrade)
+{
+	global $current_plugin_processed;
+
+	if ( is_array($pre_upgrade) ) {
+		foreach ($pre_upgrade as $plugin => $result) {
+			$current_plugin_processed = $plugin;
+			do_action( 'post_upgrade_'.$plugin, $result );
+		}
+	}
+}
+
 function wp_check_mysql_version() {
 	global $wpdb;
 	$result = $wpdb->check_database_version();
Index: wp-includes/plugin.php
===================================================================
--- wp-includes/plugin.php	(revision 6521)
+++ wp-includes/plugin.php	(working copy)
@@ -504,6 +504,55 @@
 	add_action('deactivate_' . $file, $function);
 }
 
+/**
+ * register_pre_upgrade_hook() - Hook a plugin function into the pre upgrade process
+ *
+ * The pre-upgrade process is called before the upgrade is started to allow plugins
+ * to shut themselves down or do any cleanup that may cause the upgrade to fail.
+ *
+ * The filter expects the called plugin function to return true, if the function
+ * succeeded in doing what it was supposed to do and false if it failed to complete
+ * what it was supposed to do. These values aren't currently used by WordPress
+ * upgrade process, but they may in the future.
+ *
+ * The plugins should not make calls to any WordPress function without checking that
+ * it exists first. The upgrade process halts the inclusion of the entire WordPress
+ * library, therefore access to many of the WordPress API will not be available.
+ * However, the administration API will be available.
+ *
+ * The script should also take care to not run anything outside of functions in the
+ * plugin file. On plugin error, the script must not harm the upgrade process in any
+ * way and must not try to halt the upgrade process. If the script wishes to halt
+ * reading of the script, the script can return within the script body and outside of
+ * any functions.
+ *
+ * @param string $file The plugin file path that has the plugin info
+ * @param callback $function The function or method to call when hook is called.
+ */
+function register_pre_upgrade_hook($file, $function) {
+	add_filter('pre_upgrade_'.plugin_basename($file), $function);
+}
+
+/**
+ * register_post_upgrade_hook() - Hook a plugin function into the post upgrade process
+ *
+ * The post upgrade hook is called after the upgrade has finished. This allows plugins
+ * which previously disabled themselves to enable themselves again. The plugin can run
+ * their install process again, if they previously uninstalled themselves.
+ *
+ * The plugin function will be passed the value of the pre-upgrade hook in an attempt
+ * for the post to handle any errors or problems that weren't handled in the pre upgrade
+ * hook.
+ *
+ * The function again must not cause WordPress to die any errors must fail silently.
+ *
+ * @param string $file The plugin file path that has the plugin info
+ * @param callback $function The function or method to call when hook is called.
+ */
+function register_post_upgrade_hook($file, $function) {
+	add_action('post_upgrade_'.plugin_basename($file), $function);
+}
+
 /** 
  * _wp_call_all_hook() - Calls the 'all' hook, which will process the functions hooked into it.
  *
