+ $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
+ *
+ * @global int $wp_current_db_version
+ * @global wpdb $wpdb
+ */
+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 && wp_should_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
+ *
+ * @global int $wp_current_db_version
+ * @global wpdb $wpdb
+ */
+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 && wp_should_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
+ *
+ * @global int $wp_current_db_version
+ */
+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
+ *
+ * @global int $wp_current_db_version
+ */
+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
+ *
+ * @global int $wp_current_db_version
+ */
+function upgrade_380() {
+ global $wp_current_db_version;
+ if ( $wp_current_db_version < 26691 ) {
+ deactivate_plugins( array( 'mp6/mp6.php' ), true );
+ }
+}
+
+/**
+ * Execute changes made in WordPress 4.0.0.
+ *
+ * @since 4.0.0
+ *
+ * @global int $wp_current_db_version
+ */
+function upgrade_400() {
+ global $wp_current_db_version;
+ if ( $wp_current_db_version < 29630 ) {
+ if ( ! is_multisite() && false === get_option( 'WPLANG' ) ) {
+ if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages() ) ) {
+ update_option( 'WPLANG', WPLANG );
+ } else {
+ update_option( 'WPLANG', '' );
+ }
+ }
+ }
+}
+
+/**
+ * Execute changes made in WordPress 4.2.0.
+ *
+ * @since 4.2.0
+ *
+ * @global int $wp_current_db_version
+ * @global wpdb $wpdb
+ */
+function upgrade_420() {}
+
+/**
+ * Executes changes made in WordPress 4.3.0.
+ *
+ * @since 4.3.0
+ *
+ * @global int $wp_current_db_version Current version.
+ * @global wpdb $wpdb WordPress database abstraction object.
+ */
+function upgrade_430() {
+ global $wp_current_db_version, $wpdb;
+
+ if ( $wp_current_db_version < 32364 ) {
+ upgrade_430_fix_comments();
+ }
+
+ // Shared terms are split in a separate process.
+ if ( $wp_current_db_version < 32814 ) {
+ update_option( 'finished_splitting_shared_terms', 0 );
+ wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' );
+ }
+
+ if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
+ if ( is_multisite() ) {
+ $tables = $wpdb->tables( 'blog' );
+ } else {
+ $tables = $wpdb->tables( 'all' );
+ if ( ! wp_should_upgrade_global_tables() ) {
+ $global_tables = $wpdb->tables( 'global' );
+ $tables = array_diff_assoc( $tables, $global_tables );
+ }
+ }
+
+ foreach ( $tables as $table ) {
+ maybe_convert_table_to_utf8mb4( $table );
+ }
+ }
+}
+
+/**
+ * Executes comments changes made in WordPress 4.3.0.
+ *
+ * @since 4.3.0
+ *
+ * @global int $wp_current_db_version Current version.
+ * @global wpdb $wpdb WordPress database abstraction object.
+ */
+function upgrade_430_fix_comments() {
+ global $wp_current_db_version, $wpdb;
+
+ $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );
+
+ if ( is_wp_error( $content_length ) ) {
+ return;
+ }
+
+ if ( false === $content_length ) {
+ $content_length = array(
+ 'type' => 'byte',
+ 'length' => 65535,
+ );
+ } elseif ( ! is_array( $content_length ) ) {
+ $length = (int) $content_length > 0 ? (int) $content_length : 65535;
+ $content_length = array(
+ 'type' => 'byte',
+ 'length' => $length
+ );
+ }
+
+ if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) {
+ // Sites with malformed DB schemas are on their own.
+ return;
+ }
+
+ $allowed_length = intval( $content_length['length'] ) - 10;
+
+ $comments = $wpdb->get_results(
+ "SELECT `comment_ID` FROM `{$wpdb->comments}`
+ WHERE `comment_date_gmt` > '2015-04-26'
+ AND LENGTH( `comment_content` ) >= {$allowed_length}
+ AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )"
+ );
+
+ foreach ( $comments as $comment ) {
+ wp_delete_comment( $comment->comment_ID, true );
+ }
+}
+
+/**
+ * Executes changes made in WordPress 4.3.1.
+ *
+ * @since 4.3.1
+ */
+function upgrade_431() {
+ // Fix incorrect cron entries for term splitting
+ $cron_array = _get_cron_array();
+ if ( isset( $cron_array['wp_batch_split_terms'] ) ) {
+ unset( $cron_array['wp_batch_split_terms'] );
+ _set_cron_array( $cron_array );