upgrade_160

Execute changes made in WordPress 2.0.

Description

upgrade_160(); 

Usage

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

Defined (1)

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

/wp-admin/includes/upgrade.php  
  1. function upgrade_160() { 
  2. global $wpdb, $wp_current_db_version; 
  3.  
  4.  
  5. $users = $wpdb->get_results("SELECT * FROM $wpdb->users"); 
  6. foreach ( $users as $user ) : 
  7. if ( !empty( $user->user_firstname ) ) 
  8. update_user_meta( $user->ID, 'first_name', wp_slash($user->user_firstname) ); 
  9. if ( !empty( $user->user_lastname ) ) 
  10. update_user_meta( $user->ID, 'last_name', wp_slash($user->user_lastname) ); 
  11. if ( !empty( $user->user_nickname ) ) 
  12. update_user_meta( $user->ID, 'nickname', wp_slash($user->user_nickname) ); 
  13. if ( !empty( $user->user_level ) ) 
  14. update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level ); 
  15. if ( !empty( $user->user_icq ) ) 
  16. update_user_meta( $user->ID, 'icq', wp_slash($user->user_icq) ); 
  17. if ( !empty( $user->user_aim ) ) 
  18. update_user_meta( $user->ID, 'aim', wp_slash($user->user_aim) ); 
  19. if ( !empty( $user->user_msn ) ) 
  20. update_user_meta( $user->ID, 'msn', wp_slash($user->user_msn) ); 
  21. if ( !empty( $user->user_yim ) ) 
  22. update_user_meta( $user->ID, 'yim', wp_slash($user->user_icq) ); 
  23. if ( !empty( $user->user_description ) ) 
  24. update_user_meta( $user->ID, 'description', wp_slash($user->user_description) ); 
  25.  
  26. if ( isset( $user->user_idmode ) ): 
  27. $idmode = $user->user_idmode; 
  28. if ($idmode == 'nickname') $id = $user->user_nickname; 
  29. if ($idmode == 'login') $id = $user->user_login; 
  30. if ($idmode == 'firstname') $id = $user->user_firstname; 
  31. if ($idmode == 'lastname') $id = $user->user_lastname; 
  32. if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname; 
  33. if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname; 
  34. if (!$idmode) $id = $user->user_nickname; 
  35. $wpdb->update( $wpdb->users, array('display_name' => $id), array('ID' => $user->ID) ); 
  36. endif; 
  37.  
  38. // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set. 
  39. $caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities'); 
  40. if ( empty($caps) || defined('RESET_CAPS') ) { 
  41. $level = get_user_meta($user->ID, $wpdb->prefix . 'user_level', true); 
  42. $role = translate_level_to_role($level); 
  43. update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) ); 
  44.  
  45. endforeach; 
  46. $old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' ); 
  47. $wpdb->hide_errors(); 
  48. foreach ( $old_user_fields as $old ) 
  49. $wpdb->query("ALTER TABLE $wpdb->users DROP $old"); 
  50. $wpdb->show_errors(); 
  51.  
  52. // Populate comment_count field of posts table. 
  53. $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" ); 
  54. if ( is_array( $comments ) ) 
  55. foreach ($comments as $comment) 
  56. $wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) ); 
  57.  
  58. /** 
  59. * Some alpha versions used a post status of object instead of attachment 
  60. * and put the mime type in post_type instead of post_mime_type. 
  61. */ 
  62. if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) { 
  63. $objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'"); 
  64. foreach ($objects as $object) { 
  65. $wpdb->update( $wpdb->posts, array( 'post_status' => 'attachment',  
  66. 'post_mime_type' => $object->post_type,  
  67. 'post_type' => ''),  
  68. array( 'ID' => $object->ID ) ); 
  69.  
  70. $meta = get_post_meta($object->ID, 'imagedata', true); 
  71. if ( ! empty($meta['file']) ) 
  72. update_attached_file( $object->ID, $meta['file'] );