upgrade_100

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

WordPress Version: 5.5

/**
 * Execute changes made in WordPress 1.0.
 *
 * @ignore
 * @since 1.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 */
function upgrade_100()
{
    global $wpdb;
    // Get the title and ID of every post, post_name to check if it already has a value.
    $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM {$wpdb->posts} WHERE post_name = ''");
    if ($posts) {
        foreach ($posts as $post) {
            if ('' === $post->post_name) {
                $newtitle = sanitize_title($post->post_title);
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_name = %s WHERE ID = %d", $newtitle, $post->ID));
            }
        }
    }
    $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM {$wpdb->categories}");
    foreach ($categories as $category) {
        if ('' === $category->category_nicename) {
            $newtitle = sanitize_title($category->cat_name);
            $wpdb->update($wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID));
        }
    }
    $sql = "UPDATE {$wpdb->options}\n\t\tSET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')\n\t\tWHERE option_name LIKE %s\n\t\tAND option_value LIKE %s";
    $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('links_rating_image') . '%', $wpdb->esc_like('wp-links/links-images/') . '%'));
    $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM {$wpdb->post2cat}");
    if ($done_ids) {
        $done_posts = array();
        foreach ($done_ids as $done_id) {
            $done_posts[] = $done_id->post_id;
        }
        $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
    } else {
        $catwhere = '';
    }
    $allposts = $wpdb->get_results("SELECT ID, post_category FROM {$wpdb->posts} WHERE post_category != '0' {$catwhere}");
    if ($allposts) {
        foreach ($allposts as $post) {
            // Check to see if it's already been imported.
            $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->post2cat} WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category));
            if (!$cat && 0 != $post->post_category) {
                // If there's no result.
                $wpdb->insert($wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category));
            }
        }
    }
}

WordPress Version: 5.4

/**
 * Execute changes made in WordPress 1.0.
 *
 * @ignore
 * @since 1.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 */
function upgrade_100()
{
    global $wpdb;
    // Get the title and ID of every post, post_name to check if it already has a value.
    $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM {$wpdb->posts} WHERE post_name = ''");
    if ($posts) {
        foreach ($posts as $post) {
            if ('' == $post->post_name) {
                $newtitle = sanitize_title($post->post_title);
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_name = %s WHERE ID = %d", $newtitle, $post->ID));
            }
        }
    }
    $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM {$wpdb->categories}");
    foreach ($categories as $category) {
        if ('' == $category->category_nicename) {
            $newtitle = sanitize_title($category->cat_name);
            $wpdb->update($wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID));
        }
    }
    $sql = "UPDATE {$wpdb->options}\n\t\tSET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')\n\t\tWHERE option_name LIKE %s\n\t\tAND option_value LIKE %s";
    $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('links_rating_image') . '%', $wpdb->esc_like('wp-links/links-images/') . '%'));
    $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM {$wpdb->post2cat}");
    if ($done_ids) {
        $done_posts = array();
        foreach ($done_ids as $done_id) {
            $done_posts[] = $done_id->post_id;
        }
        $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
    } else {
        $catwhere = '';
    }
    $allposts = $wpdb->get_results("SELECT ID, post_category FROM {$wpdb->posts} WHERE post_category != '0' {$catwhere}");
    if ($allposts) {
        foreach ($allposts as $post) {
            // Check to see if it's already been imported.
            $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->post2cat} WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category));
            if (!$cat && 0 != $post->post_category) {
                // If there's no result.
                $wpdb->insert($wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category));
            }
        }
    }
}

WordPress Version: 4.5

/**
 * Execute changes made in WordPress 1.0.
 *
 * @ignore
 * @since 1.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 */
function upgrade_100()
{
    global $wpdb;
    // Get the title and ID of every post, post_name to check if it already has a value
    $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM {$wpdb->posts} WHERE post_name = ''");
    if ($posts) {
        foreach ($posts as $post) {
            if ('' == $post->post_name) {
                $newtitle = sanitize_title($post->post_title);
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_name = %s WHERE ID = %d", $newtitle, $post->ID));
            }
        }
    }
    $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM {$wpdb->categories}");
    foreach ($categories as $category) {
        if ('' == $category->category_nicename) {
            $newtitle = sanitize_title($category->cat_name);
            $wpdb->update($wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID));
        }
    }
    $sql = "UPDATE {$wpdb->options}\n\t\tSET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')\n\t\tWHERE option_name LIKE %s\n\t\tAND option_value LIKE %s";
    $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('links_rating_image') . '%', $wpdb->esc_like('wp-links/links-images/') . '%'));
    $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM {$wpdb->post2cat}");
    if ($done_ids) {
        $done_posts = array();
        foreach ($done_ids as $done_id) {
            $done_posts[] = $done_id->post_id;
        }
        $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
    } else {
        $catwhere = '';
    }
    $allposts = $wpdb->get_results("SELECT ID, post_category FROM {$wpdb->posts} WHERE post_category != '0' {$catwhere}");
    if ($allposts) {
        foreach ($allposts as $post) {
            // Check to see if it's already been imported
            $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->post2cat} WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category));
            if (!$cat && 0 != $post->post_category) {
                // If there's no result
                $wpdb->insert($wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category));
            }
        }
    }
}

WordPress Version: 4.4

/**
 * Execute changes made in WordPress 1.0.
 *
 * @since 1.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 */
function upgrade_100()
{
    global $wpdb;
    // Get the title and ID of every post, post_name to check if it already has a value
    $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM {$wpdb->posts} WHERE post_name = ''");
    if ($posts) {
        foreach ($posts as $post) {
            if ('' == $post->post_name) {
                $newtitle = sanitize_title($post->post_title);
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_name = %s WHERE ID = %d", $newtitle, $post->ID));
            }
        }
    }
    $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM {$wpdb->categories}");
    foreach ($categories as $category) {
        if ('' == $category->category_nicename) {
            $newtitle = sanitize_title($category->cat_name);
            $wpdb->update($wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID));
        }
    }
    $sql = "UPDATE {$wpdb->options}\n\t\tSET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')\n\t\tWHERE option_name LIKE %s\n\t\tAND option_value LIKE %s";
    $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('links_rating_image') . '%', $wpdb->esc_like('wp-links/links-images/') . '%'));
    $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM {$wpdb->post2cat}");
    if ($done_ids) {
        $done_posts = array();
        foreach ($done_ids as $done_id) {
            $done_posts[] = $done_id->post_id;
        }
        $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
    } else {
        $catwhere = '';
    }
    $allposts = $wpdb->get_results("SELECT ID, post_category FROM {$wpdb->posts} WHERE post_category != '0' {$catwhere}");
    if ($allposts) {
        foreach ($allposts as $post) {
            // Check to see if it's already been imported
            $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->post2cat} WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category));
            if (!$cat && 0 != $post->post_category) {
                // If there's no result
                $wpdb->insert($wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category));
            }
        }
    }
}

WordPress Version: 4.3

/**
 * Execute changes made in WordPress 1.0.
 *
 * @since 1.0.0
 *
 * @global wpdb $wpdb
 */
function upgrade_100()
{
    global $wpdb;
    // Get the title and ID of every post, post_name to check if it already has a value
    $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM {$wpdb->posts} WHERE post_name = ''");
    if ($posts) {
        foreach ($posts as $post) {
            if ('' == $post->post_name) {
                $newtitle = sanitize_title($post->post_title);
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_name = %s WHERE ID = %d", $newtitle, $post->ID));
            }
        }
    }
    $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM {$wpdb->categories}");
    foreach ($categories as $category) {
        if ('' == $category->category_nicename) {
            $newtitle = sanitize_title($category->cat_name);
            $wpdb->update($wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID));
        }
    }
    $sql = "UPDATE {$wpdb->options}\n\t\tSET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')\n\t\tWHERE option_name LIKE %s\n\t\tAND option_value LIKE %s";
    $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('links_rating_image') . '%', $wpdb->esc_like('wp-links/links-images/') . '%'));
    $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM {$wpdb->post2cat}");
    if ($done_ids) {
        $done_posts = array();
        foreach ($done_ids as $done_id) {
            $done_posts[] = $done_id->post_id;
        }
        $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
    } else {
        $catwhere = '';
    }
    $allposts = $wpdb->get_results("SELECT ID, post_category FROM {$wpdb->posts} WHERE post_category != '0' {$catwhere}");
    if ($allposts) {
        foreach ($allposts as $post) {
            // Check to see if it's already been imported
            $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->post2cat} WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category));
            if (!$cat && 0 != $post->post_category) {
                // If there's no result
                $wpdb->insert($wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category));
            }
        }
    }
}

WordPress Version: 4.2

/**
 * Execute changes made in WordPress 1.0.
 *
 * @since 1.0.0
 */
function upgrade_100()
{
    global $wpdb;
    // Get the title and ID of every post, post_name to check if it already has a value
    $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM {$wpdb->posts} WHERE post_name = ''");
    if ($posts) {
        foreach ($posts as $post) {
            if ('' == $post->post_name) {
                $newtitle = sanitize_title($post->post_title);
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_name = %s WHERE ID = %d", $newtitle, $post->ID));
            }
        }
    }
    $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM {$wpdb->categories}");
    foreach ($categories as $category) {
        if ('' == $category->category_nicename) {
            $newtitle = sanitize_title($category->cat_name);
            $wpdb->update($wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID));
        }
    }
    $sql = "UPDATE {$wpdb->options}\n\t\tSET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')\n\t\tWHERE option_name LIKE %s\n\t\tAND option_value LIKE %s";
    $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('links_rating_image') . '%', $wpdb->esc_like('wp-links/links-images/') . '%'));
    $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM {$wpdb->post2cat}");
    if ($done_ids) {
        $done_posts = array();
        foreach ($done_ids as $done_id) {
            $done_posts[] = $done_id->post_id;
        }
        $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
    } else {
        $catwhere = '';
    }
    $allposts = $wpdb->get_results("SELECT ID, post_category FROM {$wpdb->posts} WHERE post_category != '0' {$catwhere}");
    if ($allposts) {
        foreach ($allposts as $post) {
            // Check to see if it's already been imported
            $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->post2cat} WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category));
            if (!$cat && 0 != $post->post_category) {
                // If there's no result
                $wpdb->insert($wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category));
            }
        }
    }
}

WordPress Version: 4.0

/**
 * Execute changes made in WordPress 1.0.
 *
 * @since 1.0.0
 */
function upgrade_100()
{
    global $wpdb;
    // Get the title and ID of every post, post_name to check if it already has a value
    $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM {$wpdb->posts} WHERE post_name = ''");
    if ($posts) {
        foreach ($posts as $post) {
            if ('' == $post->post_name) {
                $newtitle = sanitize_title($post->post_title);
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_name = %s WHERE ID = %d", $newtitle, $post->ID));
            }
        }
    }
    $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM {$wpdb->categories}");
    foreach ($categories as $category) {
        if ('' == $category->category_nicename) {
            $newtitle = sanitize_title($category->cat_name);
            $wpdb->update($wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID));
        }
    }
    $sql = "UPDATE {$wpdb->options}\n\t\tSET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')\n\t\tWHERE option_name LIKE %s\n\t\tAND option_value LIKE %s";
    $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('links_rating_image') . '%', $wpdb->esc_like('wp-links/links-images/') . '%'));
    $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM {$wpdb->post2cat}");
    if ($done_ids) {
        foreach ($done_ids as $done_id) {
            $done_posts[] = $done_id->post_id;
        }
        $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
    } else {
        $catwhere = '';
    }
    $allposts = $wpdb->get_results("SELECT ID, post_category FROM {$wpdb->posts} WHERE post_category != '0' {$catwhere}");
    if ($allposts) {
        foreach ($allposts as $post) {
            // Check to see if it's already been imported
            $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->post2cat} WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category));
            if (!$cat && 0 != $post->post_category) {
                // If there's no result
                $wpdb->insert($wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category));
            }
        }
    }
}

WordPress Version: 3.7

/**
 * Execute changes made in WordPress 1.0.
 *
 * @since 1.0.0
 */
function upgrade_100()
{
    global $wpdb;
    // Get the title and ID of every post, post_name to check if it already has a value
    $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM {$wpdb->posts} WHERE post_name = ''");
    if ($posts) {
        foreach ($posts as $post) {
            if ('' == $post->post_name) {
                $newtitle = sanitize_title($post->post_title);
                $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_name = %s WHERE ID = %d", $newtitle, $post->ID));
            }
        }
    }
    $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM {$wpdb->categories}");
    foreach ($categories as $category) {
        if ('' == $category->category_nicename) {
            $newtitle = sanitize_title($category->cat_name);
            $wpdb->update($wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID));
        }
    }
    $wpdb->query("UPDATE {$wpdb->options} SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')\n\tWHERE option_name LIKE 'links_rating_image%'\n\tAND option_value LIKE 'wp-links/links-images/%'");
    $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM {$wpdb->post2cat}");
    if ($done_ids) {
        foreach ($done_ids as $done_id) {
            $done_posts[] = $done_id->post_id;
        }
        $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
    } else {
        $catwhere = '';
    }
    $allposts = $wpdb->get_results("SELECT ID, post_category FROM {$wpdb->posts} WHERE post_category != '0' {$catwhere}");
    if ($allposts) {
        foreach ($allposts as $post) {
            // Check to see if it's already been imported
            $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->post2cat} WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category));
            if (!$cat && 0 != $post->post_category) {
                // If there's no result
                $wpdb->insert($wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category));
            }
        }
    }
}