upgrade_210

Definition:
function upgrade_210() {}

Execute changes made in WordPress 2.1.

Source code

function upgrade_210() {

	global $wpdb, $wp_current_db_version;



	if ( $wp_current_db_version < 3506 ) {

		// Update status and type.

		$posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts");



		if ( ! empty($posts) ) foreach ($posts as $post) {

			$status = $post->post_status;

			$type = 'post';



			if ( 'static' == $status ) {

				$status = 'publish';

				$type = 'page';

			} else if ( 'attachment' == $status ) {

				$status = 'inherit';

				$type = 'attachment';

			}



			$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID) );

		}

	}



	if ( $wp_current_db_version < 3845 ) {

		populate_roles_210();

	}



	if ( $wp_current_db_version < 3531 ) {

		// Give future posts a post_status of future.

		$now = gmdate('Y-m-d H:i:59');

		$wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'");



		$posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'");

		if ( !empty($posts) )

			foreach ( $posts as $post )

				wp_schedule_single_event(mysql2date('U', $post->post_date, false), 'publish_future_post', array($post->ID));

	}

}

3229

upgrade_160

Definition:
function upgrade_160() {}

Execute changes made in WordPress 2.0.

Source code

function upgrade_160() {

	global $wpdb, $wp_current_db_version;



	populate_roles_160();



	$users = $wpdb->get_results("SELECT * FROM $wpdb->users");

	foreach ( $users as $user ) :

		if ( !empty( $user->user_firstname ) )

			update_user_meta( $user->ID, 'first_name', $wpdb->escape($user->user_firstname) );

		if ( !empty( $user->user_lastname ) )

			update_user_meta( $user->ID, 'last_name', $wpdb->escape($user->user_lastname) );

		if ( !empty( $user->user_nickname ) )

			update_user_meta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) );

		if ( !empty( $user->user_level ) )

			update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );

		if ( !empty( $user->user_icq ) )

			update_user_meta( $user->ID, 'icq', $wpdb->escape($user->user_icq) );

		if ( !empty( $user->user_aim ) )

			update_user_meta( $user->ID, 'aim', $wpdb->escape($user->user_aim) );

		if ( !empty( $user->user_msn ) )

			update_user_meta( $user->ID, 'msn', $wpdb->escape($user->user_msn) );

		if ( !empty( $user->user_yim ) )

			update_user_meta( $user->ID, 'yim', $wpdb->escape($user->user_icq) );

		if ( !empty( $user->user_description ) )

			update_user_meta( $user->ID, 'description', $wpdb->escape($user->user_description) );



		if ( isset( $user->user_idmode ) ):

			$idmode = $user->user_idmode;

			if ($idmode == 'nickname') $id = $user->user_nickname;

			if ($idmode == 'login') $id = $user->user_login;

			if ($idmode == 'firstname') $id = $user->user_firstname;

			if ($idmode == 'lastname') $id = $user->user_lastname;

			if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname;

			if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname;

			if (!$idmode) $id = $user->user_nickname;

			$wpdb->update( $wpdb->users, array('display_name' => $id), array('ID' => $user->ID) );

		endif;



		// FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.

		$caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities');

		if ( empty($caps) || defined('RESET_CAPS') ) {

			$level = get_user_meta($user->ID, $wpdb->prefix . 'user_level', true);

			$role = translate_level_to_role($level);

			update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) );

		}



	endforeach;

	$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' );

	$wpdb->hide_errors();

	foreach ( $old_user_fields as $old )

		$wpdb->query("ALTER TABLE $wpdb->users DROP $old");

	$wpdb->show_errors();



	// populate comment_count field of posts table

	$comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );

	if ( is_array( $comments ) )

		foreach ($comments as $comment)

			$wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) );



	// Some alpha versions used a post status of object instead of attachment and put

	// the mime type in post_type instead of post_mime_type.

	if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {

		$objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'");

		foreach ($objects as $object) {

			$wpdb->update( $wpdb->posts, array(	'post_status' => 'attachment',

												'post_mime_type' => $object->post_type,

												'post_type' => ''),

										 array( 'ID' => $object->ID ) );



			$meta = get_post_meta($object->ID, 'imagedata', true);

			if ( ! empty($meta['file']) )

				update_attached_file( $object->ID, $meta['file'] );

		}

	}

}

3227

upgrade_130

Definition:
function upgrade_130() {}

Execute changes made in WordPress 1.5.

Source code

function upgrade_130() {

	global $wpdb;



	// Remove extraneous backslashes.

	$posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts");

	if ($posts) {

		foreach($posts as $post) {

			$post_content = addslashes(deslash($post->post_content));

			$post_title = addslashes(deslash($post->post_title));

			$post_excerpt = addslashes(deslash($post->post_excerpt));

			if ( empty($post->guid) )

				$guid = get_permalink($post->ID);

			else

				$guid = $post->guid;



			$wpdb->update( $wpdb->posts, compact('post_title', 'post_content', 'post_excerpt', 'guid'), array('ID' => $post->ID) );



		}

	}



	// Remove extraneous backslashes.

	$comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments");

	if ($comments) {

		foreach($comments as $comment) {

			$comment_content = deslash($comment->comment_content);

			$comment_author = deslash($comment->comment_author);



			$wpdb->update($wpdb->comments, compact('comment_content', 'comment_author'), array('comment_ID' => $comment->comment_ID) );

		}

	}



	// Remove extraneous backslashes.

	$links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM $wpdb->links");

	if ($links) {

		foreach($links as $link) {

			$link_name = deslash($link->link_name);

			$link_description = deslash($link->link_description);



			$wpdb->update( $wpdb->links, compact('link_name', 'link_description'), array('link_id' => $link->link_id) );

		}

	}



	$active_plugins = __get_option('active_plugins');



	// If plugins are not stored in an array, they're stored in the old

	// newline separated format.  Convert to new format.

	if ( !is_array( $active_plugins ) ) {

		$active_plugins = explode("\n", trim($active_plugins));

		update_option('active_plugins', $active_plugins);

	}



	// Obsolete tables

	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues');

	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes');

	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups');

	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options');



	// Update comments table to use comment_type

	$wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'");

	$wpdb->query("UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'");



	// Some versions have multiple duplicate option_name rows with the same values

	$options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name");

	foreach ( $options as $option ) {

		if ( 1 != $option->dupes ) { // Could this be done in the query?

			$limit = $option->dupes - 1;

			$dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) );

			if ( $dupe_ids ) {

				$dupe_ids = join($dupe_ids, ',');

				$wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");

			}

		}

	}



	make_site_theme();

}

3225

upgrade_110

Definition:
function upgrade_110() {}

Execute changes made in WordPress 1.2.

Source code

function upgrade_110() {

	global $wpdb;



	// Set user_nicename.

	$users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users");

	foreach ($users as $user) {

		if ('' == $user->user_nicename) {

			$newname = sanitize_title($user->user_nickname);

			$wpdb->update( $wpdb->users, array('user_nicename' => $newname), array('ID' => $user->ID) );

		}

	}



	$users = $wpdb->get_results("SELECT ID, user_pass from $wpdb->users");

	foreach ($users as $row) {

		if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) {

			$wpdb->update( $wpdb->users, array('user_pass' => md5($row->user_pass)), array('ID' => $row->ID) );

		}

	}



	// Get the GMT offset, we'll use that later on

	$all_options = get_alloptions_110();



	$time_difference = $all_options->time_difference;



	$server_time = time()+date('Z');

	$weblogger_time = $server_time + $time_difference*3600;

	$gmt_time = time();



	$diff_gmt_server = ($gmt_time - $server_time) / 3600;

	$diff_weblogger_server = ($weblogger_time - $server_time) / 3600;

	$diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;

	$gmt_offset = -$diff_gmt_weblogger;



	// Add a gmt_offset option, with value $gmt_offset

	add_option('gmt_offset', $gmt_offset);



	// Check if we already set the GMT fields (if we did, then

	// MAX(post_date_gmt) can't be '0000-00-00 00:00:00'

	// <michel_v> I just slapped myself silly for not thinking about it earlier

	$got_gmt_fields = ! ($wpdb->get_var("SELECT MAX(post_date_gmt) FROM $wpdb->posts") == '0000-00-00 00:00:00');



	if (!$got_gmt_fields) {



		// Add or substract time to all dates, to get GMT dates

		$add_hours = intval($diff_gmt_weblogger);

		$add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours));

		$wpdb->query("UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");

		$wpdb->query("UPDATE $wpdb->posts SET post_modified = post_date");

		$wpdb->query("UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'");

		$wpdb->query("UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");

		$wpdb->query("UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");

	}



}

3223

upgrade_101

Definition:
function upgrade_101() {}

Execute changes made in WordPress 1.0.1.

Source code

function upgrade_101() {

	global $wpdb;



	// Clean up indices, add a few

	add_clean_index($wpdb->posts, 'post_name');

	add_clean_index($wpdb->posts, 'post_status');

	add_clean_index($wpdb->categories, 'category_nicename');

	add_clean_index($wpdb->comments, 'comment_approved');

	add_clean_index($wpdb->comments, 'comment_post_ID');

	add_clean_index($wpdb->links , 'link_category');

	add_clean_index($wpdb->links , 'link_visible');

}

3221