upgrade_100

Execute changes made in WordPress 1.0.

Description

upgrade_100(); 

Usage

  1. if ( !function_exists( 'upgrade_100' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = upgrade_100(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/upgrade.php  
  1. function upgrade_100() { 
  2. global $wpdb; 
  3.  
  4. // Get the title and ID of every post, post_name to check if it already has a value 
  5. $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''"); 
  6. if ($posts) { 
  7. foreach ($posts as $post) { 
  8. if ('' == $post->post_name) { 
  9. $newtitle = sanitize_title($post->post_title); 
  10. $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID) ); 
  11.  
  12. $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories"); 
  13. foreach ($categories as $category) { 
  14. if ('' == $category->category_nicename) { 
  15. $newtitle = sanitize_title($category->cat_name); 
  16. $wpdb->update( $wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID) ); 
  17.  
  18. $sql = "UPDATE $wpdb->options 
  19. SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/') 
  20. WHERE option_name LIKE %s 
  21. AND option_value LIKE %s"; 
  22. $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( 'links_rating_image' ) . '%', $wpdb->esc_like( 'wp-links/links-images/' ) . '%' ) ); 
  23.  
  24. $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $wpdb->post2cat"); 
  25. if ($done_ids) : 
  26. $done_posts = array(); 
  27. foreach ($done_ids as $done_id) : 
  28. $done_posts[] = $done_id->post_id; 
  29. endforeach; 
  30. $catwhere = ' AND ID NOT IN (' . implode(', ', $done_posts) . ')'; 
  31. else: 
  32. $catwhere = ''; 
  33. endif; 
  34.  
  35. $allposts = $wpdb->get_results("SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere"); 
  36. if ($allposts) : 
  37. foreach ($allposts as $post) { 
  38. // Check to see if it's already been imported 
  39. $cat = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category) ); 
  40. if (!$cat && 0 != $post->post_category) { // If there's no result 
  41. $wpdb->insert( $wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category) ); 
  42. endif;