+ if ( $wp_current_db_version < 11958 ) {
+ // Previously, setting depth to 1 would redundantly disable threading, but now 2 is the minimum depth to avoid confusion
+ if ( get_option( 'thread_comments_depth' ) == '1' ) {
+ update_option( 'thread_comments_depth', 2 );
+ update_option( 'thread_comments', 0 );
+ }
+ }
+}
+
+/**
+ * Execute changes made in WordPress 3.0.
+ *
+ * @since 3.0.0
+ */
+function upgrade_300() {
+ global $wp_current_db_version, $wpdb;
+
+ if ( $wp_current_db_version < 15093 )
+ populate_roles_300();
+
+ if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false )
+ add_site_option( 'siteurl', '' );
+
+ // 3.0 screen options key name changes.
+ if ( is_main_site() && !defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
+ $prefix = like_escape($wpdb->base_prefix);
+ $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE '{$prefix}%meta-box-hidden%' OR meta_key LIKE '{$prefix}%closedpostboxes%' OR meta_key LIKE '{$prefix}%manage-%-columns-hidden%' OR meta_key LIKE '{$prefix}%meta-box-order%' OR meta_key LIKE '{$prefix}%metaboxorder%' OR meta_key LIKE '{$prefix}%screen_layout%'
+ OR meta_key = 'manageedittagscolumnshidden' OR meta_key='managecategoriescolumnshidden' OR meta_key = 'manageedit-tagscolumnshidden' OR meta_key = 'manageeditcolumnshidden' OR meta_key = 'categories_per_page' OR meta_key = 'edit_tags_per_page'" );
+ }
+
+}
+
+/**
+ * Execute changes made in WordPress 3.3.
+ *
+ * @since 3.3.0
+ */
+function upgrade_330() {
+ global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets;
+
+ if ( $wp_current_db_version < 19061 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
+ $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" );
+ }
+
+ if ( $wp_current_db_version >= 11548 )
+ return;
+
+ $sidebars_widgets = get_option( 'sidebars_widgets', array() );
+ $_sidebars_widgets = array();
+
+ if ( isset($sidebars_widgets['wp_inactive_widgets']) || empty($sidebars_widgets) )
+ $sidebars_widgets['array_version'] = 3;
+ elseif ( !isset($sidebars_widgets['array_version']) )
+ $sidebars_widgets['array_version'] = 1;
+
+ switch ( $sidebars_widgets['array_version'] ) {
+ case 1 :
+ foreach ( (array) $sidebars_widgets as $index => $sidebar )
+ if ( is_array($sidebar) )
+ foreach ( (array) $sidebar as $i => $name ) {
+ $id = strtolower($name);
+ if ( isset($wp_registered_widgets[$id]) ) {
+ $_sidebars_widgets[$index][$i] = $id;
+ continue;
+ }
+ $id = sanitize_title($name);
+ if ( isset($wp_registered_widgets[$id]) ) {
+ $_sidebars_widgets[$index][$i] = $id;
+ continue;
+ }
+
+ $found = false;
+
+ foreach ( $wp_registered_widgets as $widget_id => $widget ) {
+ if ( strtolower($widget['name']) == strtolower($name) ) {
+ $_sidebars_widgets[$index][$i] = $widget['id'];
+ $found = true;
+ break;
+ } elseif ( sanitize_title($widget['name']) == sanitize_title($name) ) {
+ $_sidebars_widgets[$index][$i] = $widget['id'];
+ $found = true;
+ break;
+ }
+ }
+
+ if ( $found )
+ continue;
+
+ unset($_sidebars_widgets[$index][$i]);
+ }
+ $_sidebars_widgets['array_version'] = 2;
+ $sidebars_widgets = $_sidebars_widgets;
+ unset($_sidebars_widgets);
+
+ case 2 :
+ $sidebars_widgets = retrieve_widgets();
+ $sidebars_widgets['array_version'] = 3;
+ update_option( 'sidebars_widgets', $sidebars_widgets );
+ }
+}
+
+/**
+ * Execute changes made in WordPress 3.4.
+ *
+ * @since 3.4.0
+ */
+function upgrade_340() {
+ global $wp_current_db_version, $wpdb;
+
+ if ( $wp_current_db_version < 19798 ) {
+ $wpdb->hide_errors();
+ $wpdb->query( "ALTER TABLE $wpdb->options DROP COLUMN blog_id" );
+ $wpdb->show_errors();
+ }
+
+ if ( $wp_current_db_version < 19799 ) {
+ $wpdb->hide_errors();
+ $wpdb->query("ALTER TABLE $wpdb->comments DROP INDEX comment_approved");
+ $wpdb->show_errors();
+ }
+
+ if ( $wp_current_db_version < 20022 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
+ $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" );
+ }
+
+ if ( $wp_current_db_version < 20080 ) {
+ if ( 'yes' == $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
+ $uninstall_plugins = get_option( 'uninstall_plugins' );
+ delete_option( 'uninstall_plugins' );
+ add_option( 'uninstall_plugins', $uninstall_plugins, null, 'no' );
+ }
+ }
+}
+
+/**
+ * Execute changes made in WordPress 3.5.
+ *
+ * @since 3.5.0
+ */
+function upgrade_350() {
+ global $wp_current_db_version, $wpdb;
+
+ if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) )
+ update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options()
+
+ if ( $wp_current_db_version < 21811 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
+ $meta_keys = array();
+ foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) {
+ if ( false !== strpos( $name, '-' ) )
+ $meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page';
+ }
+ if ( $meta_keys ) {
+ $meta_keys = implode( "', '", $meta_keys );
+ $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('$meta_keys')" );
+ }
+ }
+
+ if ( $wp_current_db_version < 22422 && $term = get_term_by( 'slug', 'post-format-standard', 'post_format' ) )
+ wp_delete_term( $term->term_id, 'post_format' );
+}
+
+/**
+ * Execute changes made in WordPress 3.7.
+ *
+ * @since 3.7.0
+ */
+function upgrade_370() {
+ global $wp_current_db_version;
+ if ( $wp_current_db_version < 25824 )
+ wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' );
+}
+
+/**
+ * Execute changes made in WordPress 3.7.2.
+ *
+ * @since 3.7.2
+ * @since 3.8.0
+ */
+function upgrade_372() {
+ global $wp_current_db_version;
+ if ( $wp_current_db_version < 26148 )
+ wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
+}
+
+/**
+ * Execute changes made in WordPress 3.8.0.
+ *
+ * @since 3.8.0
+ */
+function upgrade_380() {
+ global $wp_current_db_version;
+ if ( $wp_current_db_version < 26691 ) {
+ deactivate_plugins( array( 'mp6/mp6.php' ), true );
+ }
+}
+/**
+ * Execute network level changes
+ *
+ * @since 3.0.0
+ */
+function upgrade_network() {
+ global $wp_current_db_version, $wpdb;
+
+ // Always
+ if ( is_main_network() ) {
+ // Deletes all expired transients.
+ // The multi-table delete syntax is used to delete the transient record from table a,
+ // and the corresponding transient_timeout record from table b.
+ $time = time();
+ $wpdb->query("DELETE a, b FROM $wpdb->sitemeta a, $wpdb->sitemeta b WHERE
+ a.meta_key LIKE '\_site\_transient\_%' AND
+ a.meta_key NOT LIKE '\_site\_transient\_timeout\_%' AND
+ b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )
+ AND b.meta_value < $time");
+ }
+
+ // 2.8
+ if ( $wp_current_db_version < 11549 ) {
+ $wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' );
+ $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
+ if ( $wpmu_sitewide_plugins ) {
+ if ( !$active_sitewide_plugins )
+ $sitewide_plugins = (array) $wpmu_sitewide_plugins;
+ else
+ $sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins );
+
+ update_site_option( 'active_sitewide_plugins', $sitewide_plugins );
+ }
+ delete_site_option( 'wpmu_sitewide_plugins' );
+ delete_site_option( 'deactivated_sitewide_plugins' );
+
+ $start = 0;
+ while( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) {
+ foreach( $rows as $row ) {
+ $value = $row->meta_value;
+ if ( !@unserialize( $value ) )
+ $value = stripslashes( $value );
+ if ( $value !== $row->meta_value ) {
+ update_site_option( $row->meta_key, $value );
+ }
+ }
+ $start += 20;
+ }
+ }
+
+ // 3.0
+ if ( $wp_current_db_version < 13576 )
+ update_site_option( 'global_terms_enabled', '1' );
+
+ // 3.3
+ if ( $wp_current_db_version < 19390 )
+ update_site_option( 'initial_db_version', $wp_current_db_version );
+
+ if ( $wp_current_db_version < 19470 ) {
+ if ( false === get_site_option( 'active_sitewide_plugins' ) )
+ update_site_option( 'active_sitewide_plugins', array() );
+ }
+
+ // 3.4
+ if ( $wp_current_db_version < 20148 ) {
+ // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
+ $allowedthemes = get_site_option( 'allowedthemes' );
+ $allowed_themes = get_site_option( 'allowed_themes' );
+ if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) {
+ $converted = array();
+ $themes = wp_get_themes();
+ foreach ( $themes as $stylesheet => $theme_data ) {
+ if ( isset( $allowed_themes[ $theme_data->get('Name') ] ) )
+ $converted[ $stylesheet ] = true;
+ }
+ update_site_option( 'allowedthemes', $converted );
+ delete_site_option( 'allowed_themes' );
+ }
+ }
+
+ // 3.5
+ if ( $wp_current_db_version < 21823 )
+ update_site_option( 'ms_files_rewriting', '1' );
+
+ // 3.5.2
+ if ( $wp_current_db_version < 24448 ) {
+ $illegal_names = get_site_option( 'illegal_names' );
+ if ( is_array( $illegal_names ) && count( $illegal_names ) === 1 ) {
+ $illegal_name = reset( $illegal_names );
+ $illegal_names = explode( ' ', $illegal_name );
+ update_site_option( 'illegal_names', $illegal_names );
+ }