'term_taxonomy_id' => $tt_id,
if ( $wp_current_db_version < 4772 ) {
// Obsolete linkcategories table.
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories' );
// Recalculate all counts.
$terms = $wpdb->get_results( "SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy" );
foreach ( (array) $terms as $term ) {
if ( 'post_tag' === $term->taxonomy || 'category' === $term->taxonomy ) {
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id ) );
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id ) );
$wpdb->update( $wpdb->term_taxonomy, array( 'count' => $count ), array( 'term_taxonomy_id' => $term->term_taxonomy_id ) );
* Remove old options from the database.
* @global wpdb $wpdb WordPress database abstraction object.
function upgrade_230_options_table() {
$old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' );
foreach ( $old_options_fields as $old ) {
$wpdb->query( "ALTER TABLE $wpdb->options DROP $old" );
* Remove old categories, link2cat, and post2cat database tables.
* @global wpdb $wpdb WordPress database abstraction object.
function upgrade_230_old_tables() {
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories' );
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat' );
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat' );
* Upgrade old slugs made in version 2.2.
* @global wpdb $wpdb WordPress database abstraction object.
function upgrade_old_slugs() {
// Upgrade people who were using the Redirect Old Slugs plugin.
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'" );
* Execute changes made in WordPress 2.5.0.
* @global int $wp_current_db_version The old (current) database version.
global $wp_current_db_version;
if ( $wp_current_db_version < 6689 ) {
* Execute changes made in WordPress 2.5.2.
* @global wpdb $wpdb WordPress database abstraction object.
$wpdb->query( "UPDATE $wpdb->users SET user_activation_key = ''" );
* Execute changes made in WordPress 2.6.
* @global int $wp_current_db_version The old (current) database version.
global $wp_current_db_version;
if ( $wp_current_db_version < 8000 ) {
* Execute changes made in WordPress 2.7.
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 8980 ) {
// Update post_date for unpublished posts with empty timestamp.
if ( $wp_current_db_version < 8921 ) {
$wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" );
* Execute changes made in WordPress 2.8.
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 10360 ) {
while ( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
foreach ( $rows as $row ) {
$value = maybe_unserialize( $row->option_value );
if ( $value === $row->option_value ) {
$value = stripslashes( $value );
if ( $value !== $row->option_value ) {
update_option( $row->option_name, $value );
clean_blog_cache( get_current_blog_id() );
* Execute changes made in WordPress 2.9.
* @global int $wp_current_db_version The old (current) database version.
global $wp_current_db_version;
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.
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 15093 ) {
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 ( wp_should_upgrade_global_tables() ) {
$sql = "DELETE FROM $wpdb->usermeta
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'";
$prefix = $wpdb->esc_like( $wpdb->base_prefix );
$prefix . '%' . $wpdb->esc_like( 'meta-box-hidden' ) . '%',
$prefix . '%' . $wpdb->esc_like( 'closedpostboxes' ) . '%',
$prefix . '%' . $wpdb->esc_like( 'manage-' ) . '%' . $wpdb->esc_like( '-columns-hidden' ) . '%',
$prefix . '%' . $wpdb->esc_like( 'meta-box-order' ) . '%',
$prefix . '%' . $wpdb->esc_like( 'metaboxorder' ) . '%',
$prefix . '%' . $wpdb->esc_like( 'screen_layout' ) . '%'
* Execute changes made in WordPress 3.3.
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
* @global array $wp_registered_widgets
* @global array $sidebars_widgets
global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets;
if ( $wp_current_db_version < 19061 && wp_should_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 ) {
$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'] ) {
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;
$id = sanitize_title( $name );
if ( isset( $wp_registered_widgets[ $id ] ) ) {
$_sidebars_widgets[ $index ][ $i ] = $id;
foreach ( $wp_registered_widgets as $widget_id => $widget ) {
if ( strtolower( $widget['name'] ) == strtolower( $name ) ) {
$_sidebars_widgets[ $index ][ $i ] = $widget['id'];
} elseif ( sanitize_title( $widget['name'] ) == sanitize_title( $name ) ) {
$_sidebars_widgets[ $index ][ $i ] = $widget['id'];
unset( $_sidebars_widgets[ $index ][ $i ] );
$_sidebars_widgets['array_version'] = 2;
$sidebars_widgets = $_sidebars_widgets;
unset( $_sidebars_widgets );
// Intentional fall-through to upgrade to the next version.
$sidebars_widgets = retrieve_widgets();
$sidebars_widgets['array_version'] = 3;
update_option( 'sidebars_widgets', $sidebars_widgets );
* Execute changes made in WordPress 3.4.
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 19798 ) {
$wpdb->query( "ALTER TABLE $wpdb->options DROP COLUMN blog_id" );
if ( $wp_current_db_version < 19799 ) {
$wpdb->query( "ALTER TABLE $wpdb->comments DROP INDEX comment_approved" );
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.
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
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() ) {
foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) {
if ( false !== strpos( $name, '-' ) ) {
$meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page';
$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.
* @global int $wp_current_db_version The old (current) database version.
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.
* @global int $wp_current_db_version The old (current) database version.
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.
* @global int $wp_current_db_version The old (current) database version.
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.
* @global int $wp_current_db_version The old (current) database version.
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(), true ) ) {
update_option( 'WPLANG', WPLANG );
update_option( 'WPLANG', '' );
* Execute changes made in WordPress 4.2.0.
function upgrade_420() {}
* Executes changes made in WordPress 4.3.0.
* @global int $wp_current_db_version The old (current) database version.
* @global wpdb $wpdb WordPress database abstraction object.
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' );