web/wp-admin/includes/upgrade.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
    22 /**
    22 /**
    23  * Installs the blog
    23  * Installs the blog
    24  *
    24  *
    25  * {@internal Missing Long Description}}
    25  * {@internal Missing Long Description}}
    26  *
    26  *
    27  * @since unknown
    27  * @since 2.1.0
    28  *
    28  *
    29  * @param string $blog_title Blog title.
    29  * @param string $blog_title Blog title.
    30  * @param string $user_name User's username.
    30  * @param string $user_name User's username.
    31  * @param string $user_email User's email.
    31  * @param string $user_email User's email.
    32  * @param bool $public Whether blog is public.
    32  * @param bool $public Whether blog is public.
    33  * @param null $deprecated Optional. Not used.
    33  * @param null $deprecated Optional. Not used.
       
    34  * @param string $user_password Optional. User's chosen password. Will default to a random password.
    34  * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
    35  * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
    35  */
    36  */
    36 function wp_install($blog_title, $user_name, $user_email, $public, $deprecated='') {
    37 function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '' ) {
    37 	global $wp_rewrite;
    38 	if ( !empty( $deprecated ) )
       
    39 		_deprecated_argument( __FUNCTION__, '2.6' );
    38 
    40 
    39 	wp_check_mysql_version();
    41 	wp_check_mysql_version();
    40 	wp_cache_flush();
    42 	wp_cache_flush();
    41 	make_db_current_silent();
    43 	make_db_current_silent();
    42 	populate_options();
    44 	populate_options();
    52 
    54 
    53 	// If not a public blog, don't ping.
    55 	// If not a public blog, don't ping.
    54 	if ( ! $public )
    56 	if ( ! $public )
    55 		update_option('default_pingback_flag', 0);
    57 		update_option('default_pingback_flag', 0);
    56 
    58 
    57 	// Create default user.  If the user already exists, the user tables are
    59 	// Create default user. If the user already exists, the user tables are
    58 	// being shared among blogs.  Just set the role in that case.
    60 	// being shared among blogs. Just set the role in that case.
    59 	$user_id = username_exists($user_name);
    61 	$user_id = username_exists($user_name);
    60 	if ( !$user_id ) {
    62 	$user_password = trim($user_password);
    61 		$random_password = wp_generate_password();
    63 	$email_password = false;
       
    64 	if ( !$user_id && empty($user_password) ) {
       
    65 		$user_password = wp_generate_password( 12, false );
    62 		$message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
    66 		$message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
    63 		$user_id = wp_create_user($user_name, $random_password, $user_email);
    67 		$user_id = wp_create_user($user_name, $user_password, $user_email);
    64 		update_usermeta($user_id, 'default_password_nag', true);
    68 		update_user_option($user_id, 'default_password_nag', true, true);
       
    69 		$email_password = true;
       
    70 	} else if ( !$user_id ) {
       
    71 		// Password has been provided
       
    72 		$message = '<em>'.__('Your chosen password.').'</em>';
       
    73 		$user_id = wp_create_user($user_name, $user_password, $user_email);
    65 	} else {
    74 	} else {
    66 		$random_password = '';
    75 		$message = __('User already exists. Password inherited.');
    67 		$message =  __('User already exists.  Password inherited.');
       
    68 	}
    76 	}
    69 
    77 
    70 	$user = new WP_User($user_id);
    78 	$user = new WP_User($user_id);
    71 	$user->set_role('administrator');
    79 	$user->set_role('administrator');
    72 
    80 
    73 	wp_install_defaults($user_id);
    81 	wp_install_defaults($user_id);
    74 
    82 
    75 	$wp_rewrite->flush_rules();
    83 	flush_rewrite_rules();
    76 
    84 
    77 	wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password);
    85 	wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.') ) );
    78 
    86 
    79 	wp_cache_flush();
    87 	wp_cache_flush();
    80 
    88 
    81 	return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password, 'password_message' => $message);
    89 	return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
    82 }
    90 }
    83 endif;
    91 endif;
    84 
    92 
    85 if ( !function_exists('wp_install_defaults') ) :
    93 if ( !function_exists('wp_install_defaults') ) :
    86 /**
    94 /**
    87  * {@internal Missing Short Description}}
    95  * {@internal Missing Short Description}}
    88  *
    96  *
    89  * {@internal Missing Long Description}}
    97  * {@internal Missing Long Description}}
    90  *
    98  *
    91  * @since unknown
    99  * @since 2.1.0
    92  *
   100  *
    93  * @param int $user_id User ID.
   101  * @param int $user_id User ID.
    94  */
   102  */
    95 function wp_install_defaults($user_id) {
   103 function wp_install_defaults($user_id) {
    96 	global $wpdb;
   104 	global $wpdb, $wp_rewrite, $current_site, $table_prefix;
    97 
   105 
    98 	// Default category
   106 	// Default category
    99 	$cat_name = __('Uncategorized');
   107 	$cat_name = __('Uncategorized');
   100 	/* translators: Default category slug */
   108 	/* translators: Default category slug */
   101 	$cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
   109 	$cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
   102 
   110 
   103 	$wpdb->insert( $wpdb->terms, array('name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
   111 	if ( global_terms_enabled() ) {
   104 	$wpdb->insert( $wpdb->term_taxonomy, array('term_id' => '1', 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
   112 		$cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
       
   113 		if ( $cat_id == null ) {
       
   114 			$wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) );
       
   115 			$cat_id = $wpdb->insert_id;
       
   116 		}
       
   117 		update_option('default_category', $cat_id);
       
   118 	} else {
       
   119 		$cat_id = 1;
       
   120 	}
       
   121 
       
   122 	$wpdb->insert( $wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
       
   123 	$wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
       
   124 	$cat_tt_id = $wpdb->insert_id;
   105 
   125 
   106 	// Default link category
   126 	// Default link category
   107 	$cat_name = __('Blogroll');
   127 	$cat_name = __('Blogroll');
   108 	/* translators: Default link category slug */
   128 	/* translators: Default link category slug */
   109 	$cat_slug = sanitize_title(_x('Blogroll', 'Default link category slug'));
   129 	$cat_slug = sanitize_title(_x('Blogroll', 'Default link category slug'));
   110 
   130 
   111 	$wpdb->insert( $wpdb->terms, array('name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
   131 	if ( global_terms_enabled() ) {
   112 	$wpdb->insert( $wpdb->term_taxonomy, array('term_id' => '2', 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7));
   132 		$blogroll_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
       
   133 		if ( $blogroll_id == null ) {
       
   134 			$wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) );
       
   135 			$blogroll_id = $wpdb->insert_id;
       
   136 		}
       
   137 		update_option('default_link_category', $blogroll_id);
       
   138 	} else {
       
   139 		$blogroll_id = 2;
       
   140 	}
       
   141 
       
   142 	$wpdb->insert( $wpdb->terms, array('term_id' => $blogroll_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
       
   143 	$wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $blogroll_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7));
       
   144 	$blogroll_tt_id = $wpdb->insert_id;
   113 
   145 
   114 	// Now drop in some default links
   146 	// Now drop in some default links
   115 	$default_links = array();
   147 	$default_links = array();
   116 	$default_links[] = array(	'link_url' => 'http://codex.wordpress.org/',
   148 	$default_links[] = array(	'link_url' => __( 'http://codex.wordpress.org/' ),
   117 								'link_name' => 'Documentation',
   149 								'link_name' => __( 'Documentation' ),
   118 								'link_rss' => '',
   150 								'link_rss' => '',
   119 								'link_notes' => '');
   151 								'link_notes' => '');
   120 
   152 
   121 	$default_links[] = array(	'link_url' => 'http://wordpress.org/development/',
   153 	$default_links[] = array(	'link_url' => __( 'http://wordpress.org/news/' ),
   122 								'link_name' => 'Development Blog',
   154 								'link_name' => __( 'WordPress Blog' ),
   123 								'link_rss' => 'http://wordpress.org/development/feed/',
   155 								'link_rss' => __( 'http://wordpress.org/news/feed/' ),
   124 								'link_notes' => '');
   156 								'link_notes' => '');
   125 
   157 
   126 	$default_links[] = array(	'link_url' => 'http://wordpress.org/extend/ideas/',
   158 	$default_links[] = array(	'link_url' => __( 'http://wordpress.org/support/' ),
   127 								'link_name' => 'Suggest Ideas',
   159 								'link_name' => _x( 'Support Forums', 'default link' ),
   128 								'link_rss' => '',
   160 								'link_rss' => '',
   129 								'link_notes' =>'');
   161 								'link_notes' =>'');
   130 
   162 
   131 	$default_links[] = array(	'link_url' => 'http://wordpress.org/support/',
   163 	$default_links[] = array(	'link_url' => 'http://wordpress.org/extend/plugins/',
   132 								'link_name' => 'Support Forum',
   164 								'link_name' => _x( 'Plugins', 'Default link to wordpress.org/extend/plugins/' ),
   133 								'link_rss' => '',
   165 								'link_rss' => '',
   134 								'link_notes' =>'');
   166 								'link_notes' =>'');
   135 
   167 
   136 	$default_links[] = array(	'link_url' => 'http://wordpress.org/extend/plugins/',
   168 	$default_links[] = array(	'link_url' => 'http://wordpress.org/extend/themes/',
   137 								'link_name' => 'Plugins',
   169 								'link_name' => _x( 'Themes', 'Default link to wordpress.org/extend/themes/' ),
   138 								'link_rss' => '',
   170 								'link_rss' => '',
   139 								'link_notes' =>'');
   171 								'link_notes' =>'');
   140 
   172 
   141 	$default_links[] = array(	'link_url' => 'http://wordpress.org/extend/themes/',
   173 	$default_links[] = array(	'link_url' => __( 'http://wordpress.org/support/forum/requests-and-feedback' ),
   142 								'link_name' => 'Themes',
   174 								'link_name' => __( 'Feedback' ),
   143 								'link_rss' => '',
   175 								'link_rss' => '',
   144 								'link_notes' =>'');
   176 								'link_notes' =>'');
   145 
   177 
   146 	$default_links[] = array(	'link_url' => 'http://planet.wordpress.org/',
   178 	$default_links[] = array(	'link_url' => __( 'http://planet.wordpress.org/' ),
   147 								'link_name' => 'WordPress Planet',
   179 								'link_name' => __( 'WordPress Planet' ),
   148 								'link_rss' => '',
   180 								'link_rss' => '',
   149 								'link_notes' =>'');
   181 								'link_notes' =>'');
   150 
   182 
   151 	foreach ( $default_links as $link ) {
   183 	foreach ( $default_links as $link ) {
   152 		$wpdb->insert( $wpdb->links, $link);
   184 		$wpdb->insert( $wpdb->links, $link);
   153 		$wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => 2, 'object_id' => $wpdb->insert_id) );
   185 		$wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $blogroll_tt_id, 'object_id' => $wpdb->insert_id) );
   154 	}
   186 	}
   155 
   187 
   156 	// First post
   188 	// First post
   157 	$now = date('Y-m-d H:i:s');
   189 	$now = date('Y-m-d H:i:s');
   158 	$now_gmt = gmdate('Y-m-d H:i:s');
   190 	$now_gmt = gmdate('Y-m-d H:i:s');
   159 	$first_post_guid = get_option('home') . '/?p=1';
   191 	$first_post_guid = get_option('home') . '/?p=1';
   160 
   192 
       
   193 	if ( is_multisite() ) {
       
   194 		$first_post = get_site_option( 'first_post' );
       
   195 
       
   196 		if ( empty($first_post) )
       
   197 			$first_post = stripslashes( __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ) );
       
   198 
       
   199 		$first_post = str_replace( "SITE_URL", esc_url( network_home_url() ), $first_post );
       
   200 		$first_post = str_replace( "SITE_NAME", $current_site->site_name, $first_post );
       
   201 	} else {
       
   202 		$first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
       
   203 	}
       
   204 
   161 	$wpdb->insert( $wpdb->posts, array(
   205 	$wpdb->insert( $wpdb->posts, array(
   162 								'post_author' => $user_id,
   206 								'post_author' => $user_id,
   163 								'post_date' => $now,
   207 								'post_date' => $now,
   164 								'post_date_gmt' => $now_gmt,
   208 								'post_date_gmt' => $now_gmt,
   165 								'post_content' => __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'),
   209 								'post_content' => $first_post,
   166 								'post_excerpt' => '',
   210 								'post_excerpt' => '',
   167 								'post_title' => __('Hello world!'),
   211 								'post_title' => __('Hello world!'),
   168 								/* translators: Default post slug */
   212 								/* translators: Default post slug */
   169 								'post_name' => _x('hello-world', 'Default post slug'),
   213 								'post_name' => sanitize_title( _x('hello-world', 'Default post slug') ),
   170 								'post_modified' => $now,
   214 								'post_modified' => $now,
   171 								'post_modified_gmt' => $now_gmt,
   215 								'post_modified_gmt' => $now_gmt,
   172 								'guid' => $first_post_guid,
   216 								'guid' => $first_post_guid,
   173 								'comment_count' => 1,
   217 								'comment_count' => 1,
   174 								'to_ping' => '',
   218 								'to_ping' => '',
   175 								'pinged' => '',
   219 								'pinged' => '',
   176 								'post_content_filtered' => ''
   220 								'post_content_filtered' => ''
   177 								));
   221 								));
   178 	$wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => 1, 'object_id' => 1) );
   222 	$wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) );
   179 
   223 
   180 	// Default comment
   224 	// Default comment
       
   225 	$first_comment_author = __('Mr WordPress');
       
   226 	$first_comment_url = 'http://wordpress.org/';
       
   227 	$first_comment = __('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
       
   228 	if ( is_multisite() ) {
       
   229 		$first_comment_author = get_site_option( 'first_comment_author', $first_comment_author );
       
   230 		$first_comment_url = get_site_option( 'first_comment_url', network_home_url() );
       
   231 		$first_comment = get_site_option( 'first_comment', $first_comment );
       
   232 	}
   181 	$wpdb->insert( $wpdb->comments, array(
   233 	$wpdb->insert( $wpdb->comments, array(
   182 								'comment_post_ID' => 1,
   234 								'comment_post_ID' => 1,
   183 								'comment_author' => __('Mr WordPress'),
   235 								'comment_author' => $first_comment_author,
   184 								'comment_author_email' => '',
   236 								'comment_author_email' => '',
   185 								'comment_author_url' => 'http://wordpress.org/',
   237 								'comment_author_url' => $first_comment_url,
   186 								'comment_date' => $now,
   238 								'comment_date' => $now,
   187 								'comment_date_gmt' => $now_gmt,
   239 								'comment_date_gmt' => $now_gmt,
   188 								'comment_content' => __('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.')
   240 								'comment_content' => $first_comment
   189 								));
   241 								));
       
   242 
   190 	// First Page
   243 	// First Page
       
   244 	$first_page = sprintf( __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:
       
   245 
       
   246 <blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>
       
   247 
       
   248 ...or something like this:
       
   249 
       
   250 <blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickies to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>
       
   251 
       
   252 As a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!" ), admin_url() );
       
   253 	if ( is_multisite() )
       
   254 		$first_page = get_site_option( 'first_page', $first_page );
   191 	$first_post_guid = get_option('home') . '/?page_id=2';
   255 	$first_post_guid = get_option('home') . '/?page_id=2';
   192 	$wpdb->insert( $wpdb->posts, array(
   256 	$wpdb->insert( $wpdb->posts, array(
   193 								'post_author' => $user_id,
   257 								'post_author' => $user_id,
   194 								'post_date' => $now,
   258 								'post_date' => $now,
   195 								'post_date_gmt' => $now_gmt,
   259 								'post_date_gmt' => $now_gmt,
   196 								'post_content' => __('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'),
   260 								'post_content' => $first_page,
   197 								'post_excerpt' => '',
   261 								'post_excerpt' => '',
   198 								'post_title' => __('About'),
   262 								'post_title' => __( 'Sample Page' ),
   199 								/* translators: Default page slug */
   263 								/* translators: Default page slug */
   200 								'post_name' => _x('about', 'Default page slug'),
   264 								'post_name' => __( 'sample-page' ),
   201 								'post_modified' => $now,
   265 								'post_modified' => $now,
   202 								'post_modified_gmt' => $now_gmt,
   266 								'post_modified_gmt' => $now_gmt,
   203 								'guid' => $first_post_guid,
   267 								'guid' => $first_post_guid,
   204 								'post_type' => 'page',
   268 								'post_type' => 'page',
   205 								'to_ping' => '',
   269 								'to_ping' => '',
   206 								'pinged' => '',
   270 								'pinged' => '',
   207 								'post_content_filtered' => ''
   271 								'post_content_filtered' => ''
   208 								));
   272 								));
       
   273 	$wpdb->insert( $wpdb->postmeta, array( 'post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default' ) );
       
   274 
       
   275 	// Set up default widgets for default theme.
       
   276 	update_option( 'widget_search', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) );
       
   277 	update_option( 'widget_recent-posts', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) );
       
   278 	update_option( 'widget_recent-comments', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) );
       
   279 	update_option( 'widget_archives', array ( 2 => array ( 'title' => '', 'count' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) );
       
   280 	update_option( 'widget_categories', array ( 2 => array ( 'title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) );
       
   281 	update_option( 'widget_meta', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) );
       
   282 	update_option( 'sidebars_widgets', array ( 'wp_inactive_widgets' => array ( ), 'sidebar-1' => array ( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2', ), 'sidebar-2' => array ( ), 'sidebar-3' => array ( ), 'sidebar-4' => array ( ), 'sidebar-5' => array ( ), 'array_version' => 3 ) );
       
   283 
       
   284 	if ( ! is_multisite() )
       
   285 		update_user_meta( $user_id, 'show_welcome_panel', 1 );
       
   286 	elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) )
       
   287 		update_user_meta( $user_id, 'show_welcome_panel', 2 );
       
   288 
       
   289 	if ( is_multisite() ) {
       
   290 		// Flush rules to pick up the new page.
       
   291 		$wp_rewrite->init();
       
   292 		$wp_rewrite->flush_rules();
       
   293 
       
   294 		$user = new WP_User($user_id);
       
   295 		$wpdb->update( $wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email') );
       
   296 
       
   297 		// Remove all perms except for the login user.
       
   298 		$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'user_level') );
       
   299 		$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'capabilities') );
       
   300 
       
   301 		// Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
       
   302 		if ( !is_super_admin( $user_id ) && $user_id != 1 )
       
   303 			$wpdb->delete( $wpdb->usermeta, array( 'user_id' => $user_id , 'meta_key' => $wpdb->base_prefix.'1_capabilities' ) );
       
   304 	}
   209 }
   305 }
   210 endif;
   306 endif;
   211 
   307 
   212 if ( !function_exists('wp_new_blog_notification') ) :
   308 if ( !function_exists('wp_new_blog_notification') ) :
   213 /**
   309 /**
   214  * {@internal Missing Short Description}}
   310  * {@internal Missing Short Description}}
   215  *
   311  *
   216  * {@internal Missing Long Description}}
   312  * {@internal Missing Long Description}}
   217  *
   313  *
   218  * @since unknown
   314  * @since 2.1.0
   219  *
   315  *
   220  * @param string $blog_title Blog title.
   316  * @param string $blog_title Blog title.
   221  * @param string $blog_url Blog url.
   317  * @param string $blog_url Blog url.
   222  * @param int $user_id User ID.
   318  * @param int $user_id User ID.
   223  * @param string $password User's Password.
   319  * @param string $password User's Password.
   224  */
   320  */
   225 function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
   321 function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
   226 	$user = new WP_User($user_id);
   322 	$user = new WP_User($user_id);
   227 	$email = $user->user_email;
   323 	$email = $user->user_email;
   228 	$name = $user->user_login;
   324 	$name = $user->user_login;
   229 	$message = sprintf(__("Your new WordPress blog has been successfully set up at:
   325 	$message = sprintf(__("Your new WordPress site has been successfully set up at:
   230 
   326 
   231 %1\$s
   327 %1\$s
   232 
   328 
   233 You can log in to the administrator account with the following information:
   329 You can log in to the administrator account with the following information:
   234 
   330 
   235 Username: %2\$s
   331 Username: %2\$s
   236 Password: %3\$s
   332 Password: %3\$s
   237 
   333 
   238 We hope you enjoy your new blog. Thanks!
   334 We hope you enjoy your new site. Thanks!
   239 
   335 
   240 --The WordPress Team
   336 --The WordPress Team
   241 http://wordpress.org/
   337 http://wordpress.org/
   242 "), $blog_url, $name, $password);
   338 "), $blog_url, $name, $password);
   243 
   339 
   244 	@wp_mail($email, __('New WordPress Blog'), $message);
   340 	@wp_mail($email, __('New WordPress Site'), $message);
   245 }
   341 }
   246 endif;
   342 endif;
   247 
   343 
   248 if ( !function_exists('wp_upgrade') ) :
   344 if ( !function_exists('wp_upgrade') ) :
   249 /**
   345 /**
   250  * Run WordPress Upgrade functions.
   346  * Run WordPress Upgrade functions.
   251  *
   347  *
   252  * {@internal Missing Long Description}}
   348  * {@internal Missing Long Description}}
   253  *
   349  *
   254  * @since unknown
   350  * @since 2.1.0
   255  *
   351  *
   256  * @return null
   352  * @return null
   257  */
   353  */
   258 function wp_upgrade() {
   354 function wp_upgrade() {
   259 	global $wp_current_db_version, $wp_db_version;
   355 	global $wp_current_db_version, $wp_db_version, $wpdb;
   260 
   356 
   261 	$wp_current_db_version = __get_option('db_version');
   357 	$wp_current_db_version = __get_option('db_version');
   262 
   358 
   263 	// We are up-to-date.  Nothing to do.
   359 	// We are up-to-date. Nothing to do.
   264 	if ( $wp_db_version == $wp_current_db_version )
   360 	if ( $wp_db_version == $wp_current_db_version )
   265 		return;
   361 		return;
   266 
   362 
   267 	if( ! is_blog_installed() )
   363 	if ( ! is_blog_installed() )
   268 		return;
   364 		return;
   269 
   365 
   270 	wp_check_mysql_version();
   366 	wp_check_mysql_version();
   271 	wp_cache_flush();
   367 	wp_cache_flush();
   272 	pre_schema_upgrade();
   368 	pre_schema_upgrade();
   273 	make_db_current_silent();
   369 	make_db_current_silent();
   274 	upgrade_all();
   370 	upgrade_all();
       
   371 	if ( is_multisite() && is_main_site() )
       
   372 		upgrade_network();
   275 	wp_cache_flush();
   373 	wp_cache_flush();
       
   374 
       
   375 	if ( is_multisite() ) {
       
   376 		if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'" ) )
       
   377 			$wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" );
       
   378 		else
       
   379 			$wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" );
       
   380 	}
   276 }
   381 }
   277 endif;
   382 endif;
   278 
   383 
   279 /**
   384 /**
   280  * Functions to be called in install and upgrade scripts.
   385  * Functions to be called in install and upgrade scripts.
   281  *
   386  *
   282  * {@internal Missing Long Description}}
   387  * {@internal Missing Long Description}}
   283  *
   388  *
   284  * @since unknown
   389  * @since 1.0.1
   285  */
   390  */
   286 function upgrade_all() {
   391 function upgrade_all() {
   287 	global $wp_current_db_version, $wp_db_version, $wp_rewrite;
   392 	global $wp_current_db_version, $wp_db_version;
   288 	$wp_current_db_version = __get_option('db_version');
   393 	$wp_current_db_version = __get_option('db_version');
   289 
   394 
   290 	// We are up-to-date.  Nothing to do.
   395 	// We are up-to-date. Nothing to do.
   291 	if ( $wp_db_version == $wp_current_db_version )
   396 	if ( $wp_db_version == $wp_current_db_version )
   292 		return;
   397 		return;
   293 
   398 
   294 	// If the version is not set in the DB, try to guess the version.
   399 	// If the version is not set in the DB, try to guess the version.
   295 	if ( empty($wp_current_db_version) ) {
   400 	if ( empty($wp_current_db_version) ) {
   329 		upgrade_230_old_tables();
   434 		upgrade_230_old_tables();
   330 
   435 
   331 	if ( $wp_current_db_version < 7499 )
   436 	if ( $wp_current_db_version < 7499 )
   332 		upgrade_250();
   437 		upgrade_250();
   333 
   438 
   334 	if ( $wp_current_db_version < 7796 )
       
   335 		upgrade_251();
       
   336 
       
   337 	if ( $wp_current_db_version < 7935 )
   439 	if ( $wp_current_db_version < 7935 )
   338 		upgrade_252();
   440 		upgrade_252();
   339 
   441 
   340 	if ( $wp_current_db_version < 8201 )
   442 	if ( $wp_current_db_version < 8201 )
   341 		upgrade_260();
   443 		upgrade_260();
   346 	if ( $wp_current_db_version < 10360 )
   448 	if ( $wp_current_db_version < 10360 )
   347 		upgrade_280();
   449 		upgrade_280();
   348 
   450 
   349 	if ( $wp_current_db_version < 11958 )
   451 	if ( $wp_current_db_version < 11958 )
   350 		upgrade_290();
   452 		upgrade_290();
       
   453 
       
   454 	if ( $wp_current_db_version < 15260 )
       
   455 		upgrade_300();
       
   456 
       
   457 	if ( $wp_current_db_version < 19389 )
       
   458 		upgrade_330();
       
   459 
       
   460 	if ( $wp_current_db_version < 20080 )
       
   461 		upgrade_340();
   351 
   462 
   352 	maybe_disable_automattic_widgets();
   463 	maybe_disable_automattic_widgets();
   353 
   464 
   354 	update_option( 'db_version', $wp_db_version );
   465 	update_option( 'db_version', $wp_db_version );
   355 	update_option( 'db_upgraded', true );
   466 	update_option( 'db_upgraded', true );
   453 	// Get the GMT offset, we'll use that later on
   564 	// Get the GMT offset, we'll use that later on
   454 	$all_options = get_alloptions_110();
   565 	$all_options = get_alloptions_110();
   455 
   566 
   456 	$time_difference = $all_options->time_difference;
   567 	$time_difference = $all_options->time_difference;
   457 
   568 
   458 	$server_time = time()+date('Z');
   569 		$server_time = time()+date('Z');
   459 	$weblogger_time = $server_time + $time_difference*3600;
   570 	$weblogger_time = $server_time + $time_difference*3600;
   460 	$gmt_time = time();
   571 	$gmt_time = time();
   461 
   572 
   462 	$diff_gmt_server = ($gmt_time - $server_time) / 3600;
   573 	$diff_gmt_server = ($gmt_time - $server_time) / 3600;
   463 	$diff_weblogger_server = ($weblogger_time - $server_time) / 3600;
   574 	$diff_weblogger_server = ($weblogger_time - $server_time) / 3600;
   468 	add_option('gmt_offset', $gmt_offset);
   579 	add_option('gmt_offset', $gmt_offset);
   469 
   580 
   470 	// Check if we already set the GMT fields (if we did, then
   581 	// Check if we already set the GMT fields (if we did, then
   471 	// MAX(post_date_gmt) can't be '0000-00-00 00:00:00'
   582 	// MAX(post_date_gmt) can't be '0000-00-00 00:00:00'
   472 	// <michel_v> I just slapped myself silly for not thinking about it earlier
   583 	// <michel_v> I just slapped myself silly for not thinking about it earlier
   473 	$got_gmt_fields = ($wpdb->get_var("SELECT MAX(post_date_gmt) FROM $wpdb->posts") == '0000-00-00 00:00:00') ? false : true;
   584 	$got_gmt_fields = ! ($wpdb->get_var("SELECT MAX(post_date_gmt) FROM $wpdb->posts") == '0000-00-00 00:00:00');
   474 
   585 
   475 	if (!$got_gmt_fields) {
   586 	if (!$got_gmt_fields) {
   476 
   587 
   477 		// Add or substract time to all dates, to get GMT dates
   588 		// Add or subtract time to all dates, to get GMT dates
   478 		$add_hours = intval($diff_gmt_weblogger);
   589 		$add_hours = intval($diff_gmt_weblogger);
   479 		$add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours));
   590 		$add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours));
   480 		$wpdb->query("UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
   591 		$wpdb->query("UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
   481 		$wpdb->query("UPDATE $wpdb->posts SET post_modified = post_date");
   592 		$wpdb->query("UPDATE $wpdb->posts SET post_modified = post_date");
   482 		$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'");
   593 		$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'");
   534 	}
   645 	}
   535 
   646 
   536 	$active_plugins = __get_option('active_plugins');
   647 	$active_plugins = __get_option('active_plugins');
   537 
   648 
   538 	// If plugins are not stored in an array, they're stored in the old
   649 	// If plugins are not stored in an array, they're stored in the old
   539 	// newline separated format.  Convert to new format.
   650 	// newline separated format. Convert to new format.
   540 	if ( !is_array( $active_plugins ) ) {
   651 	if ( !is_array( $active_plugins ) ) {
   541 		$active_plugins = explode("\n", trim($active_plugins));
   652 		$active_plugins = explode("\n", trim($active_plugins));
   542 		update_option('active_plugins', $active_plugins);
   653 		update_option('active_plugins', $active_plugins);
   543 	}
   654 	}
   544 
   655 
   579 	populate_roles_160();
   690 	populate_roles_160();
   580 
   691 
   581 	$users = $wpdb->get_results("SELECT * FROM $wpdb->users");
   692 	$users = $wpdb->get_results("SELECT * FROM $wpdb->users");
   582 	foreach ( $users as $user ) :
   693 	foreach ( $users as $user ) :
   583 		if ( !empty( $user->user_firstname ) )
   694 		if ( !empty( $user->user_firstname ) )
   584 			update_usermeta( $user->ID, 'first_name', $wpdb->escape($user->user_firstname) );
   695 			update_user_meta( $user->ID, 'first_name', $wpdb->escape($user->user_firstname) );
   585 		if ( !empty( $user->user_lastname ) )
   696 		if ( !empty( $user->user_lastname ) )
   586 			update_usermeta( $user->ID, 'last_name', $wpdb->escape($user->user_lastname) );
   697 			update_user_meta( $user->ID, 'last_name', $wpdb->escape($user->user_lastname) );
   587 		if ( !empty( $user->user_nickname ) )
   698 		if ( !empty( $user->user_nickname ) )
   588 			update_usermeta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) );
   699 			update_user_meta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) );
   589 		if ( !empty( $user->user_level ) )
   700 		if ( !empty( $user->user_level ) )
   590 			update_usermeta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
   701 			update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
   591 		if ( !empty( $user->user_icq ) )
   702 		if ( !empty( $user->user_icq ) )
   592 			update_usermeta( $user->ID, 'icq', $wpdb->escape($user->user_icq) );
   703 			update_user_meta( $user->ID, 'icq', $wpdb->escape($user->user_icq) );
   593 		if ( !empty( $user->user_aim ) )
   704 		if ( !empty( $user->user_aim ) )
   594 			update_usermeta( $user->ID, 'aim', $wpdb->escape($user->user_aim) );
   705 			update_user_meta( $user->ID, 'aim', $wpdb->escape($user->user_aim) );
   595 		if ( !empty( $user->user_msn ) )
   706 		if ( !empty( $user->user_msn ) )
   596 			update_usermeta( $user->ID, 'msn', $wpdb->escape($user->user_msn) );
   707 			update_user_meta( $user->ID, 'msn', $wpdb->escape($user->user_msn) );
   597 		if ( !empty( $user->user_yim ) )
   708 		if ( !empty( $user->user_yim ) )
   598 			update_usermeta( $user->ID, 'yim', $wpdb->escape($user->user_icq) );
   709 			update_user_meta( $user->ID, 'yim', $wpdb->escape($user->user_icq) );
   599 		if ( !empty( $user->user_description ) )
   710 		if ( !empty( $user->user_description ) )
   600 			update_usermeta( $user->ID, 'description', $wpdb->escape($user->user_description) );
   711 			update_user_meta( $user->ID, 'description', $wpdb->escape($user->user_description) );
   601 
   712 
   602 		if ( isset( $user->user_idmode ) ):
   713 		if ( isset( $user->user_idmode ) ):
   603 			$idmode = $user->user_idmode;
   714 			$idmode = $user->user_idmode;
   604 			if ($idmode == 'nickname') $id = $user->user_nickname;
   715 			if ($idmode == 'nickname') $id = $user->user_nickname;
   605 			if ($idmode == 'login') $id = $user->user_login;
   716 			if ($idmode == 'login') $id = $user->user_login;
   610 			if (!$idmode) $id = $user->user_nickname;
   721 			if (!$idmode) $id = $user->user_nickname;
   611 			$wpdb->update( $wpdb->users, array('display_name' => $id), array('ID' => $user->ID) );
   722 			$wpdb->update( $wpdb->users, array('display_name' => $id), array('ID' => $user->ID) );
   612 		endif;
   723 		endif;
   613 
   724 
   614 		// FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
   725 		// FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
   615 		$caps = get_usermeta( $user->ID, $wpdb->prefix . 'capabilities');
   726 		$caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities');
   616 		if ( empty($caps) || defined('RESET_CAPS') ) {
   727 		if ( empty($caps) || defined('RESET_CAPS') ) {
   617 			$level = get_usermeta($user->ID, $wpdb->prefix . 'user_level');
   728 			$level = get_user_meta($user->ID, $wpdb->prefix . 'user_level', true);
   618 			$role = translate_level_to_role($level);
   729 			$role = translate_level_to_role($level);
   619 			update_usermeta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) );
   730 			update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) );
   620 		}
   731 		}
   621 
   732 
   622 	endforeach;
   733 	endforeach;
   623 	$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' );
   734 	$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' );
   624 	$wpdb->hide_errors();
   735 	$wpdb->hide_errors();
   626 		$wpdb->query("ALTER TABLE $wpdb->users DROP $old");
   737 		$wpdb->query("ALTER TABLE $wpdb->users DROP $old");
   627 	$wpdb->show_errors();
   738 	$wpdb->show_errors();
   628 
   739 
   629 	// populate comment_count field of posts table
   740 	// populate comment_count field of posts table
   630 	$comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
   741 	$comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
   631 	if( is_array( $comments ) )
   742 	if ( is_array( $comments ) )
   632 		foreach ($comments as $comment)
   743 		foreach ($comments as $comment)
   633 			$wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) );
   744 			$wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) );
   634 
   745 
   635 	// Some alpha versions used a post status of object instead of attachment and put
   746 	// Some alpha versions used a post status of object instead of attachment and put
   636 	// the mime type in post_type instead of post_mime_type.
   747 	// the mime type in post_type instead of post_mime_type.
   786 			continue;
   897 			continue;
   787 
   898 
   788 		$wpdb->insert( $wpdb->term_relationships, array('object_id' => $post_id, 'term_taxonomy_id' => $tt_id) );
   899 		$wpdb->insert( $wpdb->term_relationships, array('object_id' => $post_id, 'term_taxonomy_id' => $tt_id) );
   789 	}
   900 	}
   790 
   901 
   791 	// < 3570 we used linkcategories.  >= 3570 we used categories and link2cat.
   902 	// < 3570 we used linkcategories. >= 3570 we used categories and link2cat.
   792 	if ( $wp_current_db_version < 3570 ) {
   903 	if ( $wp_current_db_version < 3570 ) {
   793 		// Create link_category terms for link categories.  Create a map of link cat IDs
   904 		// Create link_category terms for link categories. Create a map of link cat IDs
   794 		// to link_category terms.
   905 		// to link_category terms.
   795 		$link_cat_id_map = array();
   906 		$link_cat_id_map = array();
   796 		$default_link_cat = 0;
   907 		$default_link_cat = 0;
   797 		$tt_ids = array();
   908 		$tt_ids = array();
   798 		$link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb->prefix . 'linkcategories');
   909 		$link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb->prefix . 'linkcategories');
   917 	}
  1028 	}
   918 
  1029 
   919 }
  1030 }
   920 
  1031 
   921 /**
  1032 /**
   922  * Execute changes made in WordPress 2.5.1.
       
   923  *
       
   924  * @since 2.5.1
       
   925  */
       
   926 function upgrade_251() {
       
   927 	global $wp_current_db_version;
       
   928 
       
   929 	// Make the secret longer
       
   930 	update_option('secret', wp_generate_password(64));
       
   931 }
       
   932 
       
   933 /**
       
   934  * Execute changes made in WordPress 2.5.2.
  1033  * Execute changes made in WordPress 2.5.2.
   935  *
  1034  *
   936  * @since 2.5.2
  1035  * @since 2.5.2
   937  */
  1036  */
   938 function upgrade_252() {
  1037 function upgrade_252() {
   978  * Execute changes made in WordPress 2.8.
  1077  * Execute changes made in WordPress 2.8.
   979  *
  1078  *
   980  * @since 2.8.0
  1079  * @since 2.8.0
   981  */
  1080  */
   982 function upgrade_280() {
  1081 function upgrade_280() {
   983 	global $wp_current_db_version;
  1082 	global $wp_current_db_version, $wpdb;
   984 
  1083 
   985 	if ( $wp_current_db_version < 10360 )
  1084 	if ( $wp_current_db_version < 10360 )
   986 		populate_roles_280();
  1085 		populate_roles_280();
       
  1086 	if ( is_multisite() ) {
       
  1087 		$start = 0;
       
  1088 		while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
       
  1089 			foreach( $rows as $row ) {
       
  1090 				$value = $row->option_value;
       
  1091 				if ( !@unserialize( $value ) )
       
  1092 					$value = stripslashes( $value );
       
  1093 				if ( $value !== $row->option_value ) {
       
  1094 					update_option( $row->option_name, $value );
       
  1095 				}
       
  1096 			}
       
  1097 			$start += 20;
       
  1098 		}
       
  1099 		refresh_blog_details( $wpdb->blogid );
       
  1100 	}
   987 }
  1101 }
   988 
  1102 
   989 /**
  1103 /**
   990  * Execute changes made in WordPress 2.9.
  1104  * Execute changes made in WordPress 2.9.
   991  *
  1105  *
  1001 			update_option( 'thread_comments', 0 );
  1115 			update_option( 'thread_comments', 0 );
  1002 		}
  1116 		}
  1003 	}
  1117 	}
  1004 }
  1118 }
  1005 
  1119 
       
  1120 /**
       
  1121  * Execute changes made in WordPress 3.0.
       
  1122  *
       
  1123  * @since 3.0.0
       
  1124  */
       
  1125 function upgrade_300() {
       
  1126 	global $wp_current_db_version, $wpdb;
       
  1127 
       
  1128 	if ( $wp_current_db_version < 15093 )
       
  1129 		populate_roles_300();
       
  1130 
       
  1131 	if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false )
       
  1132 		add_site_option( 'siteurl', '' );
       
  1133 
       
  1134 	// 3.0 screen options key name changes.
       
  1135 	if ( is_main_site() && !defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
       
  1136 		$prefix = like_escape($wpdb->base_prefix);
       
  1137 		$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE '{$prefix}%meta-box-hidden%' OR meta_key LIKE '{$prefix}%closedpostboxes%' OR meta_key LIKE '{$prefix}%manage-%-columns-hidden%' OR meta_key LIKE '{$prefix}%meta-box-order%' OR meta_key LIKE '{$prefix}%metaboxorder%' OR meta_key LIKE '{$prefix}%screen_layout%'
       
  1138 					 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'" );
       
  1139 	}
       
  1140 
       
  1141 }
       
  1142 
       
  1143 /**
       
  1144  * Execute changes made in WordPress 3.3.
       
  1145  *
       
  1146  * @since 3.3.0
       
  1147  */
       
  1148 function upgrade_330() {
       
  1149 	global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets;
       
  1150 
       
  1151 	if ( $wp_current_db_version < 19061 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
       
  1152 		$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" );
       
  1153 	}
       
  1154 
       
  1155 	if ( $wp_current_db_version >= 11548 )
       
  1156 		return;
       
  1157 
       
  1158 	$sidebars_widgets = get_option( 'sidebars_widgets', array() );
       
  1159 	$_sidebars_widgets = array();
       
  1160 
       
  1161 	if ( isset($sidebars_widgets['wp_inactive_widgets']) || empty($sidebars_widgets) )
       
  1162 		$sidebars_widgets['array_version'] = 3;
       
  1163 	elseif ( !isset($sidebars_widgets['array_version']) )
       
  1164 		$sidebars_widgets['array_version'] = 1;
       
  1165 
       
  1166 	switch ( $sidebars_widgets['array_version'] ) {
       
  1167 		case 1 :
       
  1168 			foreach ( (array) $sidebars_widgets as $index => $sidebar )
       
  1169 			if ( is_array($sidebar) )
       
  1170 			foreach ( (array) $sidebar as $i => $name ) {
       
  1171 				$id = strtolower($name);
       
  1172 				if ( isset($wp_registered_widgets[$id]) ) {
       
  1173 					$_sidebars_widgets[$index][$i] = $id;
       
  1174 					continue;
       
  1175 				}
       
  1176 				$id = sanitize_title($name);
       
  1177 				if ( isset($wp_registered_widgets[$id]) ) {
       
  1178 					$_sidebars_widgets[$index][$i] = $id;
       
  1179 					continue;
       
  1180 				}
       
  1181 
       
  1182 				$found = false;
       
  1183 
       
  1184 				foreach ( $wp_registered_widgets as $widget_id => $widget ) {
       
  1185 					if ( strtolower($widget['name']) == strtolower($name) ) {
       
  1186 						$_sidebars_widgets[$index][$i] = $widget['id'];
       
  1187 						$found = true;
       
  1188 						break;
       
  1189 					} elseif ( sanitize_title($widget['name']) == sanitize_title($name) ) {
       
  1190 						$_sidebars_widgets[$index][$i] = $widget['id'];
       
  1191 						$found = true;
       
  1192 						break;
       
  1193 					}
       
  1194 				}
       
  1195 
       
  1196 				if ( $found )
       
  1197 					continue;
       
  1198 
       
  1199 				unset($_sidebars_widgets[$index][$i]);
       
  1200 			}
       
  1201 			$_sidebars_widgets['array_version'] = 2;
       
  1202 			$sidebars_widgets = $_sidebars_widgets;
       
  1203 			unset($_sidebars_widgets);
       
  1204 
       
  1205 		case 2 :
       
  1206 			$sidebars_widgets = retrieve_widgets();
       
  1207 			$sidebars_widgets['array_version'] = 3;
       
  1208 			update_option( 'sidebars_widgets', $sidebars_widgets );
       
  1209 	}
       
  1210 }
       
  1211 
       
  1212 /**
       
  1213  * Execute changes made in WordPress 3.4.
       
  1214  *
       
  1215  * @since 3.4.0
       
  1216  */
       
  1217 function upgrade_340() {
       
  1218 	global $wp_current_db_version, $wpdb;
       
  1219 
       
  1220 	if ( $wp_current_db_version < 19798 ) {
       
  1221 		$wpdb->hide_errors();
       
  1222 		$wpdb->query( "ALTER TABLE $wpdb->options DROP COLUMN blog_id" );
       
  1223 		$wpdb->show_errors();
       
  1224 	}
       
  1225 
       
  1226 	if ( $wp_current_db_version < 19799 ) {
       
  1227 		$wpdb->hide_errors();
       
  1228 		$wpdb->query("ALTER TABLE $wpdb->comments DROP INDEX comment_approved");
       
  1229 		$wpdb->show_errors();
       
  1230 	}
       
  1231 
       
  1232 	if ( $wp_current_db_version < 20022 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
       
  1233 		$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" );
       
  1234 	}
       
  1235 
       
  1236 	if ( $wp_current_db_version < 20080 ) {
       
  1237 		if ( 'yes' == $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
       
  1238 			$uninstall_plugins = get_option( 'uninstall_plugins' );
       
  1239 			delete_option( 'uninstall_plugins' );
       
  1240 			add_option( 'uninstall_plugins', $uninstall_plugins, null, 'no' );
       
  1241 		}
       
  1242 	}
       
  1243 }
       
  1244 
       
  1245 /**
       
  1246  * Execute network level changes
       
  1247  *
       
  1248  * @since 3.0.0
       
  1249  */
       
  1250 function upgrade_network() {
       
  1251 	global $wp_current_db_version, $wpdb;
       
  1252 	// 2.8
       
  1253 	if ( $wp_current_db_version < 11549 ) {
       
  1254 		$wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' );
       
  1255 		$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
       
  1256 		if ( $wpmu_sitewide_plugins ) {
       
  1257 			if ( !$active_sitewide_plugins )
       
  1258 				$sitewide_plugins = (array) $wpmu_sitewide_plugins;
       
  1259 			else
       
  1260 				$sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins );
       
  1261 
       
  1262 			update_site_option( 'active_sitewide_plugins', $sitewide_plugins );
       
  1263 		}
       
  1264 		delete_site_option( 'wpmu_sitewide_plugins' );
       
  1265 		delete_site_option( 'deactivated_sitewide_plugins' );
       
  1266 
       
  1267 		$start = 0;
       
  1268 		while( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) {
       
  1269 			foreach( $rows as $row ) {
       
  1270 				$value = $row->meta_value;
       
  1271 				if ( !@unserialize( $value ) )
       
  1272 					$value = stripslashes( $value );
       
  1273 				if ( $value !== $row->meta_value ) {
       
  1274 					update_site_option( $row->meta_key, $value );
       
  1275 				}
       
  1276 			}
       
  1277 			$start += 20;
       
  1278 		}
       
  1279 	}
       
  1280 
       
  1281 	// 3.0
       
  1282 	if ( $wp_current_db_version < 13576 )
       
  1283 		update_site_option( 'global_terms_enabled', '1' );
       
  1284 
       
  1285 	// 3.3
       
  1286 	if ( $wp_current_db_version < 19390 )
       
  1287 		update_site_option( 'initial_db_version', $wp_current_db_version );
       
  1288 
       
  1289 	if ( $wp_current_db_version < 19470 ) {
       
  1290 		if ( false === get_site_option( 'active_sitewide_plugins' ) )
       
  1291 			update_site_option( 'active_sitewide_plugins', array() );
       
  1292 	}
       
  1293 
       
  1294 	// 3.4
       
  1295 	if ( $wp_current_db_version < 20148 ) {
       
  1296 		// 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
       
  1297 		$allowedthemes  = get_site_option( 'allowedthemes'  );
       
  1298 		$allowed_themes = get_site_option( 'allowed_themes' );
       
  1299 		if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) {
       
  1300 			$converted = array();
       
  1301 			$themes = wp_get_themes();
       
  1302 			foreach ( $themes as $stylesheet => $theme_data ) {
       
  1303 				if ( isset( $allowed_themes[ $theme_data->get('Name') ] ) )
       
  1304 					$converted[ $stylesheet ] = true;
       
  1305 			}
       
  1306 			update_site_option( 'allowedthemes', $converted );
       
  1307 			delete_site_option( 'allowed_themes' );
       
  1308 		}
       
  1309 	}
       
  1310 }
  1006 
  1311 
  1007 // The functions we use to actually do stuff
  1312 // The functions we use to actually do stuff
  1008 
  1313 
  1009 // General
  1314 // General
  1010 
  1315 
  1011 /**
  1316 /**
  1012  * {@internal Missing Short Description}}
  1317  * {@internal Missing Short Description}}
  1013  *
  1318  *
  1014  * {@internal Missing Long Description}}
  1319  * {@internal Missing Long Description}}
  1015  *
  1320  *
  1016  * @since unknown
  1321  * @since 1.0.0
  1017  *
  1322  *
  1018  * @param string $table_name Database table name to create.
  1323  * @param string $table_name Database table name to create.
  1019  * @param string $create_ddl SQL statement to create table.
  1324  * @param string $create_ddl SQL statement to create table.
  1020  * @return bool If table already exists or was created by function.
  1325  * @return bool If table already exists or was created by function.
  1021  */
  1326  */
  1034 /**
  1339 /**
  1035  * {@internal Missing Short Description}}
  1340  * {@internal Missing Short Description}}
  1036  *
  1341  *
  1037  * {@internal Missing Long Description}}
  1342  * {@internal Missing Long Description}}
  1038  *
  1343  *
  1039  * @since unknown
  1344  * @since 1.0.1
  1040  *
  1345  *
  1041  * @param string $table Database table name.
  1346  * @param string $table Database table name.
  1042  * @param string $index Index name to drop.
  1347  * @param string $index Index name to drop.
  1043  * @return bool True, when finished.
  1348  * @return bool True, when finished.
  1044  */
  1349  */
  1057 /**
  1362 /**
  1058  * {@internal Missing Short Description}}
  1363  * {@internal Missing Short Description}}
  1059  *
  1364  *
  1060  * {@internal Missing Long Description}}
  1365  * {@internal Missing Long Description}}
  1061  *
  1366  *
  1062  * @since unknown
  1367  * @since 1.0.1
  1063  *
  1368  *
  1064  * @param string $table Database table name.
  1369  * @param string $table Database table name.
  1065  * @param string $index Database table index column.
  1370  * @param string $index Database table index column.
  1066  * @return bool True, when done with execution.
  1371  * @return bool True, when done with execution.
  1067  */
  1372  */
  1077  ** Add column to db table if it doesn't exist.
  1382  ** Add column to db table if it doesn't exist.
  1078  ** Returns:  true if already exists or on successful completion
  1383  ** Returns:  true if already exists or on successful completion
  1079  **           false on error
  1384  **           false on error
  1080  */
  1385  */
  1081 function maybe_add_column($table_name, $column_name, $create_ddl) {
  1386 function maybe_add_column($table_name, $column_name, $create_ddl) {
  1082 	global $wpdb, $debug;
  1387 	global $wpdb;
  1083 	foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
  1388 	foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
  1084 		if ($debug) echo("checking $column == $column_name<br />");
       
  1085 		if ($column == $column_name) {
  1389 		if ($column == $column_name) {
  1086 			return true;
  1390 			return true;
  1087 		}
  1391 		}
  1088 	}
  1392 	}
  1089 	//didn't find it try to create it.
  1393 	//didn't find it try to create it.
  1104  *
  1408  *
  1105  * @return array List of options.
  1409  * @return array List of options.
  1106  */
  1410  */
  1107 function get_alloptions_110() {
  1411 function get_alloptions_110() {
  1108 	global $wpdb;
  1412 	global $wpdb;
  1109 	if ($options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options")) {
  1413 	$all_options = new stdClass;
  1110 		foreach ($options as $option) {
  1414 	if ( $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ) ) {
  1111 			// "When trying to design a foolproof system,
  1415 		foreach ( $options as $option ) {
  1112 			//  never underestimate the ingenuity of the fools :)" -- Dougal
  1416 			if ( 'siteurl' == $option->option_name || 'home' == $option->option_name || 'category_base' == $option->option_name )
  1113 			if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
  1417 				$option->option_value = untrailingslashit( $option->option_value );
  1114 			if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
  1418 			$all_options->{$option->option_name} = stripslashes( $option->option_value );
  1115 			if ('category_base' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
       
  1116 			$all_options->{$option->option_name} = stripslashes($option->option_value);
       
  1117 		}
  1419 		}
  1118 	}
  1420 	}
  1119 	return $all_options;
  1421 	return $all_options;
  1120 }
  1422 }
  1121 
  1423 
  1122 /**
  1424 /**
  1123  * Version of get_option that is private to install/upgrade.
  1425  * Version of get_option that is private to install/upgrade.
  1124  *
  1426  *
  1125  * @since unknown
  1427  * @since 1.5.1
  1126  * @access private
  1428  * @access private
  1127  *
  1429  *
  1128  * @param string $setting Option name.
  1430  * @param string $setting Option name.
  1129  * @return mixed
  1431  * @return mixed
  1130  */
  1432  */
  1131 function __get_option($setting) {
  1433 function __get_option($setting) {
  1132 	global $wpdb;
  1434 	global $wpdb;
  1133 
  1435 
  1134 	if ( $setting == 'home' && defined( 'WP_HOME' ) ) {
  1436 	if ( $setting == 'home' && defined( 'WP_HOME' ) )
  1135 		return preg_replace( '|/+$|', '', constant( 'WP_HOME' ) );
  1437 		return untrailingslashit( WP_HOME );
  1136 	}
  1438 
  1137 
  1439 	if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) )
  1138 	if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) ) {
  1440 		return untrailingslashit( WP_SITEURL );
  1139 		return preg_replace( '|/+$|', '', constant( 'WP_SITEURL' ) );
  1441 
  1140 	}
  1442 	$option = $wpdb->get_var( $wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) );
  1141 
       
  1142 	$option = $wpdb->get_var( $wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting) );
       
  1143 
  1443 
  1144 	if ( 'home' == $setting && '' == $option )
  1444 	if ( 'home' == $setting && '' == $option )
  1145 		return __get_option('siteurl');
  1445 		return __get_option( 'siteurl' );
  1146 
  1446 
  1147 	if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
  1447 	if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting || 'tag_base' == $setting )
  1148 		$option = preg_replace('|/+$|', '', $option);
  1448 		$option = untrailingslashit( $option );
  1149 
  1449 
  1150 	@ $kellogs = unserialize($option);
  1450 	@ $kellogs = unserialize( $option );
  1151 	if ($kellogs !== FALSE)
  1451 	if ( $kellogs !== false )
  1152 		return $kellogs;
  1452 		return $kellogs;
  1153 	else
  1453 	else
  1154 		return $option;
  1454 		return $option;
  1155 }
  1455 }
  1156 
  1456 
  1157 /**
  1457 /**
  1158  * {@internal Missing Short Description}}
  1458  * {@internal Missing Short Description}}
  1159  *
  1459  *
  1160  * {@internal Missing Long Description}}
  1460  * {@internal Missing Long Description}}
  1161  *
  1461  *
  1162  * @since unknown
  1462  * @since 1.5.0
  1163  *
  1463  *
  1164  * @param string $content
  1464  * @param string $content
  1165  * @return string
  1465  * @return string
  1166  */
  1466  */
  1167 function deslash($content) {
  1467 function deslash($content) {
  1184 /**
  1484 /**
  1185  * {@internal Missing Short Description}}
  1485  * {@internal Missing Short Description}}
  1186  *
  1486  *
  1187  * {@internal Missing Long Description}}
  1487  * {@internal Missing Long Description}}
  1188  *
  1488  *
  1189  * @since unknown
  1489  * @since 1.5.0
  1190  *
  1490  *
  1191  * @param unknown_type $queries
  1491  * @param unknown_type $queries
  1192  * @param unknown_type $execute
  1492  * @param unknown_type $execute
  1193  * @return unknown
  1493  * @return unknown
  1194  */
  1494  */
  1195 function dbDelta($queries, $execute = true) {
  1495 function dbDelta( $queries = '', $execute = true ) {
  1196 	global $wpdb;
  1496 	global $wpdb;
  1197 
  1497 
       
  1498 	if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) )
       
  1499 	    $queries = wp_get_db_schema( $queries );
       
  1500 
  1198 	// Separate individual queries into an array
  1501 	// Separate individual queries into an array
  1199 	if( !is_array($queries) ) {
  1502 	if ( !is_array($queries) ) {
  1200 		$queries = explode( ';', $queries );
  1503 		$queries = explode( ';', $queries );
  1201 		if('' == $queries[count($queries) - 1]) array_pop($queries);
  1504 		$queries = array_filter( $queries );
  1202 	}
  1505 	}
       
  1506 	$queries = apply_filters( 'dbdelta_queries', $queries );
  1203 
  1507 
  1204 	$cqueries = array(); // Creation Queries
  1508 	$cqueries = array(); // Creation Queries
  1205 	$iqueries = array(); // Insertion Queries
  1509 	$iqueries = array(); // Insertion Queries
  1206 	$for_update = array();
  1510 	$for_update = array();
  1207 
  1511 
  1208 	// Create a tablename index for an array ($cqueries) of queries
  1512 	// Create a tablename index for an array ($cqueries) of queries
  1209 	foreach($queries as $qry) {
  1513 	foreach($queries as $qry) {
  1210 		if(preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
  1514 		if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
  1211 			$cqueries[trim( strtolower($matches[1]), '`' )] = $qry;
  1515 			$cqueries[ trim( $matches[1], '`' ) ] = $qry;
  1212 			$for_update[$matches[1]] = 'Created table '.$matches[1];
  1516 			$for_update[$matches[1]] = 'Created table '.$matches[1];
  1213 		}
  1517 		} else if (preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
  1214 		else if(preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
       
  1215 			array_unshift($cqueries, $qry);
  1518 			array_unshift($cqueries, $qry);
  1216 		}
  1519 		} else if (preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
  1217 		else if(preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
       
  1218 			$iqueries[] = $qry;
  1520 			$iqueries[] = $qry;
  1219 		}
  1521 		} else if (preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {
  1220 		else if(preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {
       
  1221 			$iqueries[] = $qry;
  1522 			$iqueries[] = $qry;
  1222 		}
  1523 		} else {
  1223 		else {
       
  1224 			// Unrecognized query type
  1524 			// Unrecognized query type
  1225 		}
  1525 		}
  1226 	}
  1526 	}
  1227 
  1527 	$cqueries = apply_filters( 'dbdelta_create_queries', $cqueries );
  1228 	// Check to see which tables and fields exist
  1528 	$iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
  1229 	if($tables = $wpdb->get_col('SHOW TABLES;')) {
  1529 
  1230 		// For every table in the database
  1530 	$global_tables = $wpdb->tables( 'global' );
  1231 		foreach($tables as $table) {
  1531 	foreach ( $cqueries as $table => $qry ) {
  1232 			// If a table query exists for the database table...
  1532 		// Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined.
  1233 			if( array_key_exists(strtolower($table), $cqueries) ) {
  1533 		if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) )
  1234 				// Clear the field and index arrays
  1534 			continue;
  1235 				unset($cfields);
  1535 
  1236 				unset($indices);
  1536 		// Fetch the table column structure from the database
  1237 				// Get all of the field names in the query from between the parens
  1537 		$wpdb->suppress_errors();
  1238 				preg_match("|\((.*)\)|ms", $cqueries[strtolower($table)], $match2);
  1538 		$tablefields = $wpdb->get_results("DESCRIBE {$table};");
  1239 				$qryline = trim($match2[1]);
  1539 		$wpdb->suppress_errors( false );
  1240 
  1540 
  1241 				// Separate field lines into an array
  1541 		if ( ! $tablefields )
  1242 				$flds = explode("\n", $qryline);
  1542 			continue;
  1243 
  1543 
  1244 				//echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
  1544 		// Clear the field and index arrays
  1245 
  1545 		$cfields = $indices = array();
  1246 				// For every field line specified in the query
  1546 		// Get all of the field names in the query from between the parens
  1247 				foreach($flds as $fld) {
  1547 		preg_match("|\((.*)\)|ms", $qry, $match2);
  1248 					// Extract the field name
  1548 		$qryline = trim($match2[1]);
  1249 					preg_match("|^([^ ]*)|", trim($fld), $fvals);
  1549 
  1250 					$fieldname = trim( $fvals[1], '`' );
  1550 		// Separate field lines into an array
  1251 
  1551 		$flds = explode("\n", $qryline);
  1252 					// Verify the found field name
  1552 
  1253 					$validfield = true;
  1553 		//echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
  1254 					switch(strtolower($fieldname))
  1554 
  1255 					{
  1555 		// For every field line specified in the query
  1256 					case '':
  1556 		foreach ($flds as $fld) {
  1257 					case 'primary':
  1557 			// Extract the field name
  1258 					case 'index':
  1558 			preg_match("|^([^ ]*)|", trim($fld), $fvals);
  1259 					case 'fulltext':
  1559 			$fieldname = trim( $fvals[1], '`' );
  1260 					case 'unique':
  1560 
  1261 					case 'key':
  1561 			// Verify the found field name
  1262 						$validfield = false;
  1562 			$validfield = true;
  1263 						$indices[] = trim(trim($fld), ", \n");
  1563 			switch (strtolower($fieldname)) {
  1264 						break;
  1564 			case '':
  1265 					}
  1565 			case 'primary':
  1266 					$fld = trim($fld);
  1566 			case 'index':
  1267 
  1567 			case 'fulltext':
  1268 					// If it's a valid field, add it to the field array
  1568 			case 'unique':
  1269 					if($validfield) {
  1569 			case 'key':
  1270 						$cfields[strtolower($fieldname)] = trim($fld, ", \n");
  1570 				$validfield = false;
       
  1571 				$indices[] = trim(trim($fld), ", \n");
       
  1572 				break;
       
  1573 			}
       
  1574 			$fld = trim($fld);
       
  1575 
       
  1576 			// If it's a valid field, add it to the field array
       
  1577 			if ($validfield) {
       
  1578 				$cfields[strtolower($fieldname)] = trim($fld, ", \n");
       
  1579 			}
       
  1580 		}
       
  1581 
       
  1582 		// For every field in the table
       
  1583 		foreach ($tablefields as $tablefield) {
       
  1584 			// If the table field exists in the field array...
       
  1585 			if (array_key_exists(strtolower($tablefield->Field), $cfields)) {
       
  1586 				// Get the field type from the query
       
  1587 				preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
       
  1588 				$fieldtype = $matches[1];
       
  1589 
       
  1590 				// Is actual field type different from the field type in query?
       
  1591 				if ($tablefield->Type != $fieldtype) {
       
  1592 					// Add a query to change the column type
       
  1593 					$cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
       
  1594 					$for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
       
  1595 				}
       
  1596 
       
  1597 				// Get the default value from the array
       
  1598 					//echo "{$cfields[strtolower($tablefield->Field)]}<br>";
       
  1599 				if (preg_match("| DEFAULT '(.*)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
       
  1600 					$default_value = $matches[1];
       
  1601 					if ($tablefield->Default != $default_value) {
       
  1602 						// Add a query to change the column's default value
       
  1603 						$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
       
  1604 						$for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
  1271 					}
  1605 					}
  1272 				}
  1606 				}
  1273 
  1607 
  1274 				// Fetch the table column structure from the database
  1608 				// Remove the field from the array (so it's not added)
  1275 				$tablefields = $wpdb->get_results("DESCRIBE {$table};");
  1609 				unset($cfields[strtolower($tablefield->Field)]);
  1276 
  1610 			} else {
  1277 				// For every field in the table
  1611 				// This field exists in the table, but not in the creation queries?
  1278 				foreach($tablefields as $tablefield) {
  1612 			}
  1279 					// If the table field exists in the field array...
  1613 		}
  1280 					if(array_key_exists(strtolower($tablefield->Field), $cfields)) {
  1614 
  1281 						// Get the field type from the query
  1615 		// For every remaining field specified for the table
  1282 						preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
  1616 		foreach ($cfields as $fieldname => $fielddef) {
  1283 						$fieldtype = $matches[1];
  1617 			// Push a query line into $cqueries that adds the field to that table
  1284 
  1618 			$cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
  1285 						// Is actual field type different from the field type in query?
  1619 			$for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
  1286 						if($tablefield->Type != $fieldtype) {
  1620 		}
  1287 							// Add a query to change the column type
  1621 
  1288 							$cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
  1622 		// Index stuff goes here
  1289 							$for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
  1623 		// Fetch the table index structure from the database
  1290 						}
  1624 		$tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
  1291 
  1625 
  1292 						// Get the default value from the array
  1626 		if ($tableindices) {
  1293 							//echo "{$cfields[strtolower($tablefield->Field)]}<br>";
  1627 			// Clear the index array
  1294 						if(preg_match("| DEFAULT '(.*)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
  1628 			unset($index_ary);
  1295 							$default_value = $matches[1];
  1629 
  1296 							if($tablefield->Default != $default_value)
  1630 			// For every index in the table
  1297 							{
  1631 			foreach ($tableindices as $tableindex) {
  1298 								// Add a query to change the column's default value
  1632 				// Add the index to the index data array
  1299 								$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
  1633 				$keyname = $tableindex->Key_name;
  1300 								$for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
  1634 				$index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
  1301 							}
  1635 				$index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
  1302 						}
  1636 			}
  1303 
  1637 
  1304 						// Remove the field from the array (so it's not added)
  1638 			// For each actual index in the index array
  1305 						unset($cfields[strtolower($tablefield->Field)]);
  1639 			foreach ($index_ary as $index_name => $index_data) {
  1306 					}
  1640 				// Build a create string to compare to the query
  1307 					else {
  1641 				$index_string = '';
  1308 						// This field exists in the table, but not in the creation queries?
  1642 				if ($index_name == 'PRIMARY') {
       
  1643 					$index_string .= 'PRIMARY ';
       
  1644 				} else if($index_data['unique']) {
       
  1645 					$index_string .= 'UNIQUE ';
       
  1646 				}
       
  1647 				$index_string .= 'KEY ';
       
  1648 				if ($index_name != 'PRIMARY') {
       
  1649 					$index_string .= $index_name;
       
  1650 				}
       
  1651 				$index_columns = '';
       
  1652 				// For each column in the index
       
  1653 				foreach ($index_data['columns'] as $column_data) {
       
  1654 					if ($index_columns != '') $index_columns .= ',';
       
  1655 					// Add the field to the column list string
       
  1656 					$index_columns .= $column_data['fieldname'];
       
  1657 					if ($column_data['subpart'] != '') {
       
  1658 						$index_columns .= '('.$column_data['subpart'].')';
  1309 					}
  1659 					}
  1310 				}
  1660 				}
  1311 
  1661 				// Add the column list to the index create string
  1312 				// For every remaining field specified for the table
  1662 				$index_string .= ' ('.$index_columns.')';
  1313 				foreach($cfields as $fieldname => $fielddef) {
  1663 				if (!(($aindex = array_search($index_string, $indices)) === false)) {
  1314 					// Push a query line into $cqueries that adds the field to that table
  1664 					unset($indices[$aindex]);
  1315 					$cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
  1665 					//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
  1316 					$for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
       
  1317 				}
  1666 				}
  1318 
  1667 				//else echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br /><b>Did not find index:</b>".$index_string."<br />".print_r($indices, true)."</pre>\n";
  1319 				// Index stuff goes here
       
  1320 				// Fetch the table index structure from the database
       
  1321 				$tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
       
  1322 
       
  1323 				if($tableindices) {
       
  1324 					// Clear the index array
       
  1325 					unset($index_ary);
       
  1326 
       
  1327 					// For every index in the table
       
  1328 					foreach($tableindices as $tableindex) {
       
  1329 						// Add the index to the index data array
       
  1330 						$keyname = $tableindex->Key_name;
       
  1331 						$index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
       
  1332 						$index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
       
  1333 					}
       
  1334 
       
  1335 					// For each actual index in the index array
       
  1336 					foreach($index_ary as $index_name => $index_data) {
       
  1337 						// Build a create string to compare to the query
       
  1338 						$index_string = '';
       
  1339 						if($index_name == 'PRIMARY') {
       
  1340 							$index_string .= 'PRIMARY ';
       
  1341 						}
       
  1342 						else if($index_data['unique']) {
       
  1343 							$index_string .= 'UNIQUE ';
       
  1344 						}
       
  1345 						$index_string .= 'KEY ';
       
  1346 						if($index_name != 'PRIMARY') {
       
  1347 							$index_string .= $index_name;
       
  1348 						}
       
  1349 						$index_columns = '';
       
  1350 						// For each column in the index
       
  1351 						foreach($index_data['columns'] as $column_data) {
       
  1352 							if($index_columns != '') $index_columns .= ',';
       
  1353 							// Add the field to the column list string
       
  1354 							$index_columns .= $column_data['fieldname'];
       
  1355 							if($column_data['subpart'] != '') {
       
  1356 								$index_columns .= '('.$column_data['subpart'].')';
       
  1357 							}
       
  1358 						}
       
  1359 						// Add the column list to the index create string
       
  1360 						$index_string .= ' ('.$index_columns.')';
       
  1361 						if(!(($aindex = array_search($index_string, $indices)) === false)) {
       
  1362 							unset($indices[$aindex]);
       
  1363 							//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
       
  1364 						}
       
  1365 						//else echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br /><b>Did not find index:</b>".$index_string."<br />".print_r($indices, true)."</pre>\n";
       
  1366 					}
       
  1367 				}
       
  1368 
       
  1369 				// For every remaining index specified for the table
       
  1370 				foreach ( (array) $indices as $index ) {
       
  1371 					// Push a query line into $cqueries that adds the index to that table
       
  1372 					$cqueries[] = "ALTER TABLE {$table} ADD $index";
       
  1373 					$for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index;
       
  1374 				}
       
  1375 
       
  1376 				// Remove the original table creation query from processing
       
  1377 				unset($cqueries[strtolower($table)]);
       
  1378 				unset($for_update[strtolower($table)]);
       
  1379 			} else {
       
  1380 				// This table exists in the database, but not in the creation queries?
       
  1381 			}
  1668 			}
  1382 		}
  1669 		}
       
  1670 
       
  1671 		// For every remaining index specified for the table
       
  1672 		foreach ( (array) $indices as $index ) {
       
  1673 			// Push a query line into $cqueries that adds the index to that table
       
  1674 			$cqueries[] = "ALTER TABLE {$table} ADD $index";
       
  1675 			$for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index;
       
  1676 		}
       
  1677 
       
  1678 		// Remove the original table creation query from processing
       
  1679 		unset( $cqueries[ $table ], $for_update[ $table ] );
  1383 	}
  1680 	}
  1384 
  1681 
  1385 	$allqueries = array_merge($cqueries, $iqueries);
  1682 	$allqueries = array_merge($cqueries, $iqueries);
  1386 	if($execute) {
  1683 	if ($execute) {
  1387 		foreach($allqueries as $query) {
  1684 		foreach ($allqueries as $query) {
  1388 			//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($query, true)."</pre>\n";
  1685 			//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($query, true)."</pre>\n";
  1389 			$wpdb->query($query);
  1686 			$wpdb->query($query);
  1390 		}
  1687 		}
  1391 	}
  1688 	}
  1392 
  1689 
  1396 /**
  1693 /**
  1397  * {@internal Missing Short Description}}
  1694  * {@internal Missing Short Description}}
  1398  *
  1695  *
  1399  * {@internal Missing Long Description}}
  1696  * {@internal Missing Long Description}}
  1400  *
  1697  *
  1401  * @since unknown
  1698  * @since 1.5.0
  1402  */
  1699  */
  1403 function make_db_current() {
  1700 function make_db_current( $tables = 'all' ) {
  1404 	global $wp_queries;
  1701 	$alterations = dbDelta( $tables );
  1405 
       
  1406 	$alterations = dbDelta($wp_queries);
       
  1407 	echo "<ol>\n";
  1702 	echo "<ol>\n";
  1408 	foreach($alterations as $alteration) echo "<li>$alteration</li>\n";
  1703 	foreach($alterations as $alteration) echo "<li>$alteration</li>\n";
  1409 	echo "</ol>\n";
  1704 	echo "</ol>\n";
  1410 }
  1705 }
  1411 
  1706 
  1412 /**
  1707 /**
  1413  * {@internal Missing Short Description}}
  1708  * {@internal Missing Short Description}}
  1414  *
  1709  *
  1415  * {@internal Missing Long Description}}
  1710  * {@internal Missing Long Description}}
  1416  *
  1711  *
  1417  * @since unknown
  1712  * @since 1.5.0
  1418  */
  1713  */
  1419 function make_db_current_silent() {
  1714 function make_db_current_silent( $tables = 'all' ) {
  1420 	global $wp_queries;
  1715 	$alterations = dbDelta( $tables );
  1421 
       
  1422 	$alterations = dbDelta($wp_queries);
       
  1423 }
  1716 }
  1424 
  1717 
  1425 /**
  1718 /**
  1426  * {@internal Missing Short Description}}
  1719  * {@internal Missing Short Description}}
  1427  *
  1720  *
  1428  * {@internal Missing Long Description}}
  1721  * {@internal Missing Long Description}}
  1429  *
  1722  *
  1430  * @since unknown
  1723  * @since 1.5.0
  1431  *
  1724  *
  1432  * @param unknown_type $theme_name
  1725  * @param unknown_type $theme_name
  1433  * @param unknown_type $template
  1726  * @param unknown_type $template
  1434  * @return unknown
  1727  * @return unknown
  1435  */
  1728  */
  1439 
  1732 
  1440 	if (! file_exists("$home_path/index.php"))
  1733 	if (! file_exists("$home_path/index.php"))
  1441 		return false;
  1734 		return false;
  1442 
  1735 
  1443 	// Copy files from the old locations to the site theme.
  1736 	// Copy files from the old locations to the site theme.
  1444 	// TODO: This does not copy arbitarary include dependencies.  Only the
  1737 	// TODO: This does not copy arbitrary include dependencies. Only the
  1445 	// standard WP files are copied.
  1738 	// standard WP files are copied.
  1446 	$files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
  1739 	$files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
  1447 
  1740 
  1448 	foreach ($files as $oldfile => $newfile) {
  1741 	foreach ($files as $oldfile => $newfile) {
  1449 		if ($oldfile == 'index.php')
  1742 		if ($oldfile == 'index.php')
  1452 			$oldpath = ABSPATH;
  1745 			$oldpath = ABSPATH;
  1453 
  1746 
  1454 		if ($oldfile == 'index.php') { // Check to make sure it's not a new index
  1747 		if ($oldfile == 'index.php') { // Check to make sure it's not a new index
  1455 			$index = implode('', file("$oldpath/$oldfile"));
  1748 			$index = implode('', file("$oldpath/$oldfile"));
  1456 			if (strpos($index, 'WP_USE_THEMES') !== false) {
  1749 			if (strpos($index, 'WP_USE_THEMES') !== false) {
  1457 				if (! @copy(WP_CONTENT_DIR . '/themes/default/index.php', "$site_dir/$newfile"))
  1750 				if (! @copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile"))
  1458 					return false;
  1751 					return false;
  1459 				continue; // Don't copy anything
  1752 				continue; // Don't copy anything
  1460 				}
  1753 				}
  1461 		}
  1754 		}
  1462 
  1755 
  1485 			fclose($f);
  1778 			fclose($f);
  1486 		}
  1779 		}
  1487 	}
  1780 	}
  1488 
  1781 
  1489 	// Add a theme header.
  1782 	// Add a theme header.
  1490 	$header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option('siteurl') . "\nDescription: A theme automatically created by the upgrade.\nVersion: 1.0\nAuthor: Moi\n*/\n";
  1783 	$header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option('siteurl') . "\nDescription: A theme automatically created by the update.\nVersion: 1.0\nAuthor: Moi\n*/\n";
  1491 
  1784 
  1492 	$stylelines = file_get_contents("$site_dir/style.css");
  1785 	$stylelines = file_get_contents("$site_dir/style.css");
  1493 	if ($stylelines) {
  1786 	if ($stylelines) {
  1494 		$f = fopen("$site_dir/style.css", 'w');
  1787 		$f = fopen("$site_dir/style.css", 'w');
  1495 
  1788 
  1504 /**
  1797 /**
  1505  * {@internal Missing Short Description}}
  1798  * {@internal Missing Short Description}}
  1506  *
  1799  *
  1507  * {@internal Missing Long Description}}
  1800  * {@internal Missing Long Description}}
  1508  *
  1801  *
  1509  * @since unknown
  1802  * @since 1.5.0
  1510  *
  1803  *
  1511  * @param unknown_type $theme_name
  1804  * @param unknown_type $theme_name
  1512  * @param unknown_type $template
  1805  * @param unknown_type $template
  1513  * @return unknown
  1806  * @return unknown
  1514  */
  1807  */
  1515 function make_site_theme_from_default($theme_name, $template) {
  1808 function make_site_theme_from_default($theme_name, $template) {
  1516 	$site_dir = WP_CONTENT_DIR . "/themes/$template";
  1809 	$site_dir = WP_CONTENT_DIR . "/themes/$template";
  1517 	$default_dir = WP_CONTENT_DIR . '/themes/default';
  1810 	$default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
  1518 
  1811 
  1519 	// Copy files from the default theme to the site theme.
  1812 	// Copy files from the default theme to the site theme.
  1520 	//$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
  1813 	//$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
  1521 
  1814 
  1522 	$theme_dir = @ opendir("$default_dir");
  1815 	$theme_dir = @ opendir($default_dir);
  1523 	if ($theme_dir) {
  1816 	if ($theme_dir) {
  1524 		while(($theme_file = readdir( $theme_dir )) !== false) {
  1817 		while(($theme_file = readdir( $theme_dir )) !== false) {
  1525 			if (is_dir("$default_dir/$theme_file"))
  1818 			if (is_dir("$default_dir/$theme_file"))
  1526 				continue;
  1819 				continue;
  1527 			if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file"))
  1820 			if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file"))
  1570 /**
  1863 /**
  1571  * {@internal Missing Short Description}}
  1864  * {@internal Missing Short Description}}
  1572  *
  1865  *
  1573  * {@internal Missing Long Description}}
  1866  * {@internal Missing Long Description}}
  1574  *
  1867  *
  1575  * @since unknown
  1868  * @since 1.5.0
  1576  *
  1869  *
  1577  * @return unknown
  1870  * @return unknown
  1578  */
  1871  */
  1579 function make_site_theme() {
  1872 function make_site_theme() {
  1580 	// Name the theme after the blog.
  1873 	// Name the theme after the blog.
  1597 		return false;
  1890 		return false;
  1598 	}
  1891 	}
  1599 
  1892 
  1600 	if (file_exists(ABSPATH . 'wp-layout.css')) {
  1893 	if (file_exists(ABSPATH . 'wp-layout.css')) {
  1601 		if (! make_site_theme_from_oldschool($theme_name, $template)) {
  1894 		if (! make_site_theme_from_oldschool($theme_name, $template)) {
  1602 			// TODO:  rm -rf the site theme directory.
  1895 			// TODO: rm -rf the site theme directory.
  1603 			return false;
  1896 			return false;
  1604 		}
  1897 		}
  1605 	} else {
  1898 	} else {
  1606 		if (! make_site_theme_from_default($theme_name, $template))
  1899 		if (! make_site_theme_from_default($theme_name, $template))
  1607 			// TODO:  rm -rf the site theme directory.
  1900 			// TODO: rm -rf the site theme directory.
  1608 			return false;
  1901 			return false;
  1609 	}
  1902 	}
  1610 
  1903 
  1611 	// Make the new site theme active.
  1904 	// Make the new site theme active.
  1612 	$current_template = __get_option('template');
  1905 	$current_template = __get_option('template');
  1613 	if ($current_template == 'default') {
  1906 	if ($current_template == WP_DEFAULT_THEME) {
  1614 		update_option('template', $template);
  1907 		update_option('template', $template);
  1615 		update_option('stylesheet', $template);
  1908 		update_option('stylesheet', $template);
  1616 	}
  1909 	}
  1617 	return $template;
  1910 	return $template;
  1618 }
  1911 }
  1619 
  1912 
  1620 /**
  1913 /**
  1621  * Translate user level to user role name.
  1914  * Translate user level to user role name.
  1622  *
  1915  *
  1623  * @since unknown
  1916  * @since 2.0.0
  1624  *
  1917  *
  1625  * @param int $level User level.
  1918  * @param int $level User level.
  1626  * @return string User role name.
  1919  * @return string User role name.
  1627  */
  1920  */
  1628 function translate_level_to_role($level) {
  1921 function translate_level_to_role($level) {
  1649 /**
  1942 /**
  1650  * {@internal Missing Short Description}}
  1943  * {@internal Missing Short Description}}
  1651  *
  1944  *
  1652  * {@internal Missing Long Description}}
  1945  * {@internal Missing Long Description}}
  1653  *
  1946  *
  1654  * @since unknown
  1947  * @since 2.1.0
  1655  */
  1948  */
  1656 function wp_check_mysql_version() {
  1949 function wp_check_mysql_version() {
  1657 	global $wpdb;
  1950 	global $wpdb;
  1658 	$result = $wpdb->check_database_version();
  1951 	$result = $wpdb->check_database_version();
  1659 	if ( is_wp_error( $result ) )
  1952 	if ( is_wp_error( $result ) )
  1663 /**
  1956 /**
  1664  * {@internal Missing Short Description}}
  1957  * {@internal Missing Short Description}}
  1665  *
  1958  *
  1666  * {@internal Missing Long Description}}
  1959  * {@internal Missing Long Description}}
  1667  *
  1960  *
  1668  * @since unknown
  1961  * @since 2.2.0
  1669  */
  1962  */
  1670 function maybe_disable_automattic_widgets() {
  1963 function maybe_disable_automattic_widgets() {
  1671 	$plugins = __get_option( 'active_plugins' );
  1964 	$plugins = __get_option( 'active_plugins' );
  1672 
  1965 
  1673 	foreach ( (array) $plugins as $plugin ) {
  1966 	foreach ( (array) $plugins as $plugin ) {
  1679 	}
  1972 	}
  1680 }
  1973 }
  1681 
  1974 
  1682 /**
  1975 /**
  1683  * Runs before the schema is upgraded.
  1976  * Runs before the schema is upgraded.
       
  1977  *
       
  1978  * @since 2.9.0
  1684  */
  1979  */
  1685 function pre_schema_upgrade() {
  1980 function pre_schema_upgrade() {
  1686 	global $wp_current_db_version, $wp_db_version, $wpdb;
  1981 	global $wp_current_db_version, $wp_db_version, $wpdb;
  1687 
  1982 
  1688 	// Upgrade versions prior to 2.9
  1983 	// Upgrade versions prior to 2.9
  1689 	if ( $wp_current_db_version < 11557 ) {
  1984 	if ( $wp_current_db_version < 11557 ) {
  1690 		// Delete duplicate options.  Keep the option with the highest option_id.
  1985 		// Delete duplicate options. Keep the option with the highest option_id.
  1691 		$wpdb->query("DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id");
  1986 		$wpdb->query("DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id");
  1692 
  1987 
  1693 		// Drop the old primary key and add the new.
  1988 		// Drop the old primary key and add the new.
  1694 		$wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)");
  1989 		$wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)");
  1695 
  1990 
  1697 		$wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name");
  1992 		$wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name");
  1698 	}
  1993 	}
  1699 
  1994 
  1700 }
  1995 }
  1701 
  1996 
  1702 ?>
  1997 /**
       
  1998  * Install global terms.
       
  1999  *
       
  2000  * @since 3.0.0
       
  2001  *
       
  2002  */
       
  2003 if ( !function_exists( 'install_global_terms' ) ) :
       
  2004 function install_global_terms() {
       
  2005 	global $wpdb, $charset_collate;
       
  2006 	$ms_queries = "
       
  2007 CREATE TABLE $wpdb->sitecategories (
       
  2008   cat_ID bigint(20) NOT NULL auto_increment,
       
  2009   cat_name varchar(55) NOT NULL default '',
       
  2010   category_nicename varchar(200) NOT NULL default '',
       
  2011   last_updated timestamp NOT NULL,
       
  2012   PRIMARY KEY  (cat_ID),
       
  2013   KEY category_nicename (category_nicename),
       
  2014   KEY last_updated (last_updated)
       
  2015 ) $charset_collate;
       
  2016 ";
       
  2017 // now create tables
       
  2018 	dbDelta( $ms_queries );
       
  2019 }
       
  2020 endif;