upgrade_network

The timeline below displays how wordpress function upgrade_network has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

/**
 * Executes network-level upgrade routines.
 *
 * @since 3.0.0
 *
 * @global int  $wp_current_db_version The old (current) database version.
 * @global wpdb $wpdb                  WordPress database abstraction object.
 */
function upgrade_network()
{
    global $wp_current_db_version, $wpdb;
    // Always clear expired transients.
    delete_expired_transients(true);
    // 2.8.0
    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.0
    if ($wp_current_db_version < 13576) {
        update_site_option('global_terms_enabled', '1');
    }
    // 3.3.0
    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.0
    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.0
    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);
        }
    }
    // 4.2.0
    if ($wp_current_db_version < 31351 && 'utf8mb4' === $wpdb->charset) {
        if (wp_should_upgrade_global_tables()) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 4.3.0
    if ($wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset) {
        if (wp_should_upgrade_global_tables()) {
            $upgrade = false;
            $indexes = $wpdb->get_results("SHOW INDEXES FROM {$wpdb->signups}");
            foreach ($indexes as $index) {
                if ('domain_path' === $index->Key_name && 'domain' === $index->Column_name && 140 != $index->Sub_part) {
                    $upgrade = true;
                    break;
                }
            }
            if ($upgrade) {
                $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            }
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 5.1.0
    if ($wp_current_db_version < 44467) {
        $network_id = get_main_network_id();
        delete_network_option($network_id, 'site_meta_supported');
        is_site_meta_supported();
    }
}

WordPress Version: 5.4

/**
 * Executes network-level upgrade routines.
 *
 * @since 3.0.0
 *
 * @global int  $wp_current_db_version The old (current) database version.
 * @global wpdb $wpdb                  WordPress database abstraction object.
 */
function upgrade_network()
{
    global $wp_current_db_version, $wpdb;
    // Always clear expired transients.
    delete_expired_transients(true);
    // 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);
        }
    }
    // 4.2
    if ($wp_current_db_version < 31351 && 'utf8mb4' === $wpdb->charset) {
        if (wp_should_upgrade_global_tables()) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 4.3
    if ($wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset) {
        if (wp_should_upgrade_global_tables()) {
            $upgrade = false;
            $indexes = $wpdb->get_results("SHOW INDEXES FROM {$wpdb->signups}");
            foreach ($indexes as $index) {
                if ('domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part) {
                    $upgrade = true;
                    break;
                }
            }
            if ($upgrade) {
                $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            }
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 5.1
    if ($wp_current_db_version < 44467) {
        $network_id = get_main_network_id();
        delete_network_option($network_id, 'site_meta_supported');
        is_site_meta_supported();
    }
}

WordPress Version: 5.3

/**
 * Executes network-level upgrade routines.
 *
 * @since 3.0.0
 *
 * @global int  $wp_current_db_version The old (current) database version.
 * @global wpdb $wpdb                  WordPress database abstraction object.
 */
function upgrade_network()
{
    global $wp_current_db_version, $wpdb;
    // Always clear expired transients
    delete_expired_transients(true);
    // 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);
        }
    }
    // 4.2
    if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') {
        if (wp_should_upgrade_global_tables()) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 4.3
    if ($wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset) {
        if (wp_should_upgrade_global_tables()) {
            $upgrade = false;
            $indexes = $wpdb->get_results("SHOW INDEXES FROM {$wpdb->signups}");
            foreach ($indexes as $index) {
                if ('domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part) {
                    $upgrade = true;
                    break;
                }
            }
            if ($upgrade) {
                $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            }
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 5.1
    if ($wp_current_db_version < 44467) {
        $network_id = get_main_network_id();
        delete_network_option($network_id, 'site_meta_supported');
        is_site_meta_supported();
    }
}

WordPress Version: 5.1

/**
 * Executes network-level upgrade routines.
 *
 * @since 3.0.0
 *
 * @global int   $wp_current_db_version
 * @global wpdb  $wpdb
 */
function upgrade_network()
{
    global $wp_current_db_version, $wpdb;
    // Always clear expired transients
    delete_expired_transients(true);
    // 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);
        }
    }
    // 4.2
    if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') {
        if (wp_should_upgrade_global_tables()) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 4.3
    if ($wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset) {
        if (wp_should_upgrade_global_tables()) {
            $upgrade = false;
            $indexes = $wpdb->get_results("SHOW INDEXES FROM {$wpdb->signups}");
            foreach ($indexes as $index) {
                if ('domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part) {
                    $upgrade = true;
                    break;
                }
            }
            if ($upgrade) {
                $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            }
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 5.1
    if ($wp_current_db_version < 44467) {
        $network_id = get_main_network_id();
        delete_network_option($network_id, 'site_meta_supported');
        is_site_meta_supported();
    }
}

WordPress Version: 4.9

/**
 * Executes network-level upgrade routines.
 *
 * @since 3.0.0
 *
 * @global int   $wp_current_db_version
 * @global wpdb  $wpdb
 */
function upgrade_network()
{
    global $wp_current_db_version, $wpdb;
    // Always clear expired transients
    delete_expired_transients(true);
    // 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);
        }
    }
    // 4.2
    if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') {
        if (wp_should_upgrade_global_tables()) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 4.3
    if ($wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset) {
        if (wp_should_upgrade_global_tables()) {
            $upgrade = false;
            $indexes = $wpdb->get_results("SHOW INDEXES FROM {$wpdb->signups}");
            foreach ($indexes as $index) {
                if ('domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part) {
                    $upgrade = true;
                    break;
                }
            }
            if ($upgrade) {
                $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            }
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
}

WordPress Version: 4.3

/**
 * Executes network-level upgrade routines.
 *
 * @since 3.0.0
 *
 * @global int   $wp_current_db_version
 * @global wpdb  $wpdb
 */
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();
        $sql = "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b\n\t\t\tWHERE a.meta_key LIKE %s\n\t\t\tAND a.meta_key NOT LIKE %s\n\t\t\tAND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )\n\t\t\tAND b.meta_value < %d";
        $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', $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);
        }
    }
    // 4.2
    if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') {
        if (wp_should_upgrade_global_tables()) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 4.3
    if ($wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset) {
        if (wp_should_upgrade_global_tables()) {
            $upgrade = false;
            $indexes = $wpdb->get_results("SHOW INDEXES FROM {$wpdb->signups}");
            foreach ($indexes as $index) {
                if ('domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part) {
                    $upgrade = true;
                    break;
                }
            }
            if ($upgrade) {
                $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            }
            $tables = $wpdb->tables('global');
            // sitecategories may not exist.
            if (!$wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) {
                unset($tables['sitecategories']);
            }
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
}

WordPress Version: .20

/**
 * Executes network-level upgrade routines.
 *
 * @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();
        $sql = "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b\n\t\t\tWHERE a.meta_key LIKE %s\n\t\t\tAND a.meta_key NOT LIKE %s\n\t\t\tAND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )\n\t\t\tAND b.meta_value < %d";
        $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', $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);
        }
    }
    // 4.2
    if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') {
        if (!defined('DO_NOT_UPGRADE_GLOBAL_TABLES')) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 4.2.2
    if ($wp_current_db_version < 31535 && 'utf8mb4' === $wpdb->charset) {
        if (!defined('DO_NOT_UPGRADE_GLOBAL_TABLES')) {
            $upgrade = false;
            $indexes = $wpdb->get_results("SHOW INDEXES FROM {$wpdb->signups}");
            foreach ($indexes as $index) {
                if ('domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part) {
                    $upgrade = true;
                    break;
                }
            }
            if ($upgrade) {
                $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            }
        }
    }
    // 4.2.3
    if ($wp_current_db_version < 31536 && $wpdb->charset === 'utf8mb4') {
        if (!defined('DO_NOT_UPGRADE_GLOBAL_TABLES')) {
            $tables = $wpdb->tables('global');
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
}

WordPress Version: 2.2

/**
 * Executes network-level upgrade routines.
 *
 * @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();
        $sql = "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b\n\t\t\tWHERE a.meta_key LIKE %s\n\t\t\tAND a.meta_key NOT LIKE %s\n\t\t\tAND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )\n\t\t\tAND b.meta_value < %d";
        $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', $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);
        }
    }
    // 4.2
    if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') {
        if (!(defined('DO_NOT_UPGRADE_GLOBAL_TABLES') && DO_NOT_UPGRADE_GLOBAL_TABLES)) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 4.2.2
    if ($wp_current_db_version < 31535 && 'utf8mb4' === $wpdb->charset) {
        if (!(defined('DO_NOT_UPGRADE_GLOBAL_TABLES') && DO_NOT_UPGRADE_GLOBAL_TABLES)) {
            $upgrade = false;
            $indexes = $wpdb->get_results("SHOW INDEXES FROM {$wpdb->signups}");
            foreach ($indexes as $index) {
                if ('domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part) {
                    $upgrade = true;
                    break;
                }
            }
            if ($upgrade) {
                $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            }
        }
    }
}

WordPress Version: .10

/**
 * Executes network-level upgrade routines.
 *
 * @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();
        $sql = "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b\n\t\t\tWHERE a.meta_key LIKE %s\n\t\t\tAND a.meta_key NOT LIKE %s\n\t\t\tAND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )\n\t\t\tAND b.meta_value < %d";
        $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', $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);
        }
    }
    // 4.2
    if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') {
        if (!defined('DO_NOT_UPGRADE_GLOBAL_TABLES')) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
    // 4.2.2
    if ($wp_current_db_version < 31535 && 'utf8mb4' === $wpdb->charset) {
        if (!defined('DO_NOT_UPGRADE_GLOBAL_TABLES')) {
            $upgrade = false;
            $indexes = $wpdb->get_results("SHOW INDEXES FROM {$wpdb->signups}");
            foreach ($indexes as $index) {
                if ('domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part) {
                    $upgrade = true;
                    break;
                }
            }
            if ($upgrade) {
                $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))");
            }
        }
    }
    // 4.2.3
    if ($wp_current_db_version < 31536 && $wpdb->charset === 'utf8mb4') {
        if (!defined('DO_NOT_UPGRADE_GLOBAL_TABLES')) {
            $tables = $wpdb->tables('global');
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
}

WordPress Version: 4.2

/**
 * Executes network-level upgrade routines.
 *
 * @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();
        $sql = "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b\n\t\t\tWHERE a.meta_key LIKE %s\n\t\t\tAND a.meta_key NOT LIKE %s\n\t\t\tAND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )\n\t\t\tAND b.meta_value < %d";
        $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', $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);
        }
    }
    // 4.2
    if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') {
        if (!(defined('DO_NOT_UPGRADE_GLOBAL_TABLES') && DO_NOT_UPGRADE_GLOBAL_TABLES)) {
            $wpdb->query("ALTER TABLE {$wpdb->usermeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->site} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $wpdb->query("ALTER TABLE {$wpdb->sitemeta} DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))");
            $wpdb->query("ALTER TABLE {$wpdb->signups} DROP INDEX domain, ADD INDEX domain(domain(140),path(51))");
            $tables = $wpdb->tables('global');
            foreach ($tables as $table) {
                maybe_convert_table_to_utf8mb4($table);
            }
        }
    }
}

WordPress Version: 4.0

/**
 * 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();
        $sql = "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b\n\t\t\tWHERE a.meta_key LIKE %s\n\t\t\tAND a.meta_key NOT LIKE %s\n\t\t\tAND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )\n\t\t\tAND b.meta_value < %d";
        $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', $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);
        }
    }
}

WordPress Version: 3.7

/**
 * 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\n\t\t\ta.meta_key LIKE '\\_site\\_transient\\_%' AND\n\t\t\ta.meta_key NOT LIKE '\\_site\\_transient\\_timeout\\_%' AND\n\t\t\tb.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )\n\t\t\tAND 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);
        }
    }
}