Make WordPress Core

source: trunk/wp-admin/upgrade-functions.php @ 1575

Last change on this file since 1575 was 1575, checked in by saxmatt, 21 years ago

Vanquishing the terror of iso-8859-1.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 83.0 KB
Line 
1<?php
2// Functions to be called in install and upgrade scripts
3
4// First let's set up the tables:
5
6$wp_queries="CREATE TABLE $wpdb->categories (
7  cat_ID int(4) NOT NULL auto_increment,
8  cat_name varchar(55) NOT NULL default '',
9  category_nicename varchar(200) NOT NULL default '',
10  category_description text NOT NULL,
11  category_parent int(4) NOT NULL default '0',
12  PRIMARY KEY  (cat_ID),
13  UNIQUE KEY cat_name (cat_name),
14  KEY category_nicename (category_nicename)
15);
16CREATE TABLE $wpdb->comments (
17  comment_ID int(11) unsigned NOT NULL auto_increment,
18  comment_post_ID int(11) NOT NULL default '0',
19  comment_author tinytext NOT NULL,
20  comment_author_email varchar(100) NOT NULL default '',
21  comment_author_url varchar(200) NOT NULL default '',
22  comment_author_IP varchar(100) NOT NULL default '',
23  comment_date datetime NOT NULL default '0000-00-00 00:00:00',
24  comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
25  comment_content text NOT NULL,
26  comment_karma int(11) NOT NULL default '0',
27  comment_approved enum('0','1') NOT NULL default '1',
28  user_id int(11) NOT NULL default '0',
29  PRIMARY KEY  (comment_ID),
30  KEY comment_approved (comment_approved),
31  KEY comment_post_ID (comment_post_ID)
32);
33CREATE TABLE $wpdb->linkcategories (
34  cat_id int(11) NOT NULL auto_increment,
35  cat_name tinytext NOT NULL,
36  auto_toggle enum('Y','N') NOT NULL default 'N',
37  show_images enum('Y','N') NOT NULL default 'Y',
38  show_description enum('Y','N') NOT NULL default 'N',
39  show_rating enum('Y','N') NOT NULL default 'Y',
40  show_updated enum('Y','N') NOT NULL default 'Y',
41  sort_order varchar(64) NOT NULL default 'name',
42  sort_desc enum('Y','N') NOT NULL default 'N',
43  text_before_link varchar(128) NOT NULL default '<li>',
44  text_after_link varchar(128) NOT NULL default '<br />',
45  text_after_all varchar(128) NOT NULL default '</li>',
46  list_limit int(11) NOT NULL default '-1',
47  PRIMARY KEY  (cat_id)
48);
49CREATE TABLE $wpdb->links (
50  link_id int(11) NOT NULL auto_increment,
51  link_url varchar(255) NOT NULL default '',
52  link_name varchar(255) NOT NULL default '',
53  link_image varchar(255) NOT NULL default '',
54  link_target varchar(25) NOT NULL default '',
55  link_category int(11) NOT NULL default '0',
56  link_description varchar(255) NOT NULL default '',
57  link_visible enum('Y','N') NOT NULL default 'Y',
58  link_owner int(11) NOT NULL default '1',
59  link_rating int(11) NOT NULL default '0',
60  link_updated datetime NOT NULL default '0000-00-00 00:00:00',
61  link_rel varchar(255) NOT NULL default '',
62  link_notes mediumtext NOT NULL,
63  link_rss varchar(255) NOT NULL default '',
64  PRIMARY KEY  (link_id),
65  KEY link_category (link_category),
66  KEY link_visible (link_visible)
67);
68CREATE TABLE $wpdb->optiongroup_options (
69  group_id int(11) NOT NULL default '0',
70  option_id int(11) NOT NULL default '0',
71  seq int(11) NOT NULL default '0',
72  PRIMARY KEY  (group_id,option_id)
73);
74CREATE TABLE $wpdb->optiongroups (
75  group_id int(11) NOT NULL auto_increment,
76  group_name varchar(64) NOT NULL default '',
77  group_desc varchar(255) default NULL,
78  group_longdesc tinytext,
79  PRIMARY KEY  (group_id)
80);
81CREATE TABLE $wpdb->options (
82  option_id int(11) NOT NULL auto_increment,
83  blog_id int(11) NOT NULL default '0',
84  option_name varchar(64) NOT NULL default '',
85  option_can_override enum('Y','N') NOT NULL default 'Y',
86  option_type int(11) NOT NULL default '1',
87  option_value text NOT NULL,
88  option_width int(11) NOT NULL default '20',
89  option_height int(11) NOT NULL default '8',
90  option_description tinytext NOT NULL,
91  option_admin_level int(11) NOT NULL default '1',
92  autoload enum('yes','no') NOT NULL default 'yes',
93  PRIMARY KEY  (option_id,blog_id,option_name)
94);
95CREATE TABLE $wpdb->optiontypes (
96  optiontype_id int(11) NOT NULL auto_increment,
97  optiontype_name varchar(64) NOT NULL default '',
98  PRIMARY KEY  (optiontype_id)
99);
100CREATE TABLE $wpdb->optionvalues (
101  option_id int(11) NOT NULL default '0',
102  optionvalue tinytext,
103  optionvalue_desc varchar(255) default NULL,
104  optionvalue_max int(11) default NULL,
105  optionvalue_min int(11) default NULL,
106  optionvalue_seq int(11) default NULL,
107  UNIQUE KEY option_id (option_id,optionvalue(255)),
108  KEY option_id_2 (option_id,optionvalue_seq)
109);
110CREATE TABLE $wpdb->post2cat (
111  rel_id int(11) NOT NULL auto_increment,
112  post_id int(11) NOT NULL default '0',
113  category_id int(11) NOT NULL default '0',
114  PRIMARY KEY  (rel_id),
115  KEY post_id (post_id,category_id)
116);
117CREATE TABLE $wpdb->postmeta (
118  meta_id int(11) NOT NULL auto_increment,
119  post_id int(11) NOT NULL default '0',
120  meta_key varchar(255) default NULL,
121  meta_value text,
122  PRIMARY KEY  (meta_id),
123  KEY post_id (post_id),
124  KEY meta_key (meta_key)
125);
126CREATE TABLE $wpdb->posts (
127  ID int(10) unsigned NOT NULL auto_increment,
128  post_author int(4) NOT NULL default '0',
129  post_date datetime NOT NULL default '0000-00-00 00:00:00',
130  post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
131  post_content text NOT NULL,
132  post_title text NOT NULL,
133  post_category int(4) NOT NULL default '0',
134  post_excerpt text NOT NULL,
135  post_lat float default NULL,
136  post_lon float default NULL,
137  post_status enum('publish','draft','private','static') NOT NULL default 'publish',
138  comment_status enum('open','closed','registered_only') NOT NULL default 'open',
139  ping_status enum('open','closed') NOT NULL default 'open',
140  post_password varchar(20) NOT NULL default '',
141  post_name varchar(200) NOT NULL default '',
142  to_ping text NOT NULL,
143  pinged text NOT NULL,
144  post_modified datetime NOT NULL default '0000-00-00 00:00:00',
145  post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
146  post_content_filtered text NOT NULL,
147  post_parent int(11) NOT NULL default '0',
148  PRIMARY KEY  (ID),
149  KEY post_date (post_date),
150  KEY post_date_gmt (post_date_gmt),
151  KEY post_name (post_name),
152  KEY post_status (post_status)
153);
154CREATE TABLE $wpdb->users (
155  ID int(10) unsigned NOT NULL auto_increment,
156  user_login varchar(20) NOT NULL default '',
157  user_pass varchar(64) NOT NULL default '',
158  user_firstname varchar(50) NOT NULL default '',
159  user_lastname varchar(50) NOT NULL default '',
160  user_nickname varchar(50) NOT NULL default '',
161  user_nicename varchar(50) NOT NULL default '',
162  user_icq int(10) unsigned NOT NULL default '0',
163  user_email varchar(100) NOT NULL default '',
164  user_url varchar(100) NOT NULL default '',
165  user_ip varchar(15) NOT NULL default '',
166  user_domain varchar(200) NOT NULL default '',
167  user_browser varchar(200) NOT NULL default '',
168  dateYMDhour datetime NOT NULL default '0000-00-00 00:00:00',
169  user_level int(2) unsigned NOT NULL default '0',
170  user_aim varchar(50) NOT NULL default '',
171  user_msn varchar(100) NOT NULL default '',
172  user_yim varchar(50) NOT NULL default '',
173  user_idmode varchar(20) NOT NULL default '',
174  user_activation_key varchar(60) NOT NULL default '',
175  user_status int(11) NOT NULL default '0',
176  PRIMARY KEY  (ID),
177  UNIQUE KEY user_login (user_login)
178);";
179
180
181
182function upgrade_all() {
183        upgrade_071();
184        upgrade_072();
185        upgrade_100();
186        upgrade_101();
187        upgrade_110();
188        upgrade_130();
189
190        // Options that should not exist
191        $obs_options = array('');
192}
193
194
195// .71 stuff
196
197function upgrade_071() {
198        global $wpdb;
199        maybe_add_column($wpdb->posts, 'post_status', "ALTER TABLE $wpdb->posts ADD `post_status` ENUM('publish','draft','private') NOT NULL");
200        maybe_add_column($wpdb->posts, 'comment_status', "ALTER TABLE $wpdb->posts ADD `comment_status` ENUM('open','closed') NOT NULL");
201        maybe_add_column($wpdb->posts, 'ping_status', "ALTER TABLE $wpdb->posts ADD `ping_status` ENUM('open','closed') NOT NULL");
202        maybe_add_column($wpdb->posts, 'post_password', "ALTER TABLE $wpdb->posts ADD post_password varchar(20) NOT NULL");
203}
204
205function upgrade_072() {
206        global $wpdb;
207        maybe_add_column($wpdb->links, 'link_notes', "ALTER TABLE $wpdb->links ADD COLUMN link_notes MEDIUMTEXT NOT NULL DEFAULT '' ");
208        maybe_add_column($wpdb->linkcategories, 'show_images', "ALTER TABLE $wpdb->linkcategories ADD COLUMN show_images enum('Y','N') NOT NULL default 'Y'");
209        maybe_add_column($wpdb->linkcategories, 'show_description', "ALTER TABLE $wpdb->linkcategories ADD COLUMN show_description enum('Y','N') NOT NULL default 'Y'");
210        maybe_add_column($wpdb->linkcategories, 'show_rating', "ALTER TABLE $wpdb->linkcategories ADD COLUMN show_rating enum('Y','N') NOT NULL default 'Y'");
211        maybe_add_column($wpdb->linkcategories, 'show_updated', "ALTER TABLE $wpdb->linkcategories ADD COLUMN show_updated enum('Y','N') NOT NULL default 'Y'");
212        maybe_add_column($wpdb->linkcategories, 'sort_order', "ALTER TABLE $wpdb->linkcategories ADD COLUMN sort_order varchar(64) NOT NULL default 'name'");
213        maybe_add_column($wpdb->linkcategories, 'sort_desc', "ALTER TABLE $wpdb->linkcategories ADD COLUMN sort_desc enum('Y','N') NOT NULL default 'N'");
214        maybe_add_column($wpdb->linkcategories, 'text_before_link', "ALTER TABLE $wpdb->linkcategories ADD COLUMN text_before_link varchar(128) not null default '<li>'");
215        maybe_add_column($wpdb->linkcategories, 'text_after_link', "ALTER TABLE $wpdb->linkcategories ADD COLUMN text_after_link  varchar(128) not null default '<br />'");
216        maybe_add_column($wpdb->linkcategories, 'text_after_all', "ALTER TABLE $wpdb->linkcategories ADD COLUMN text_after_all  varchar(128) not null default '</li>'");
217        maybe_add_column($wpdb->linkcategories, 'list_limit', "ALTER TABLE $wpdb->linkcategories ADD COLUMN list_limit int not null default -1");
218        maybe_add_column($wpdb->posts, 'post_lon', "ALTER TABLE $wpdb->posts ADD COLUMN post_lon float");
219        maybe_add_column($wpdb->posts, 'post_lat', "ALTER TABLE $wpdb->posts ADD COLUMN post_lat float ");
220        maybe_create_table($wpdb->options, "
221        CREATE TABLE $wpdb->options (
222          option_id int(11) NOT NULL auto_increment,
223          blog_id int(11) NOT NULL default 0,
224          option_name varchar(64) NOT NULL default '',
225          option_can_override enum('Y','N') NOT NULL default 'Y',
226          option_type int(11) NOT NULL default 1,
227          option_value varchar(255) NOT NULL default '',
228          option_width int NOT NULL default 20,
229          option_height int NOT NULL default 8,
230          option_description tinytext NOT NULL default '',
231          option_admin_level int NOT NULL DEFAULT '1',
232          PRIMARY KEY (option_id, blog_id, option_name)
233        )
234        ");
235        maybe_create_table($wpdb->optiontypes, "
236        CREATE TABLE $wpdb->optiontypes (
237          optiontype_id int(11) NOT NULL auto_increment,
238          optiontype_name varchar(64) NOT NULL,
239          PRIMARY KEY (optiontype_id)
240        )
241        ");
242        maybe_create_table($wpdb->optiongroups, "
243        CREATE TABLE $wpdb->optiongroups (
244          group_id int(11) NOT NULL auto_increment,
245          group_name varchar(64) not null,
246          group_desc varchar(255),
247          group_longdesc tinytext,
248          PRIMARY KEY (group_id)
249        )
250        ");
251        maybe_create_table($wpdb->optiongroup_options, "
252        CREATE TABLE $wpdb->optiongroup_options (
253          group_id int(11) NOT NULL,
254          option_id int(11) NOT NULL,
255          seq int(11) NOT NULL,
256          PRIMARY KEY (group_id, option_id)
257        )
258        ");
259        maybe_create_table($wpdb->optionvalues, "
260        CREATE TABLE $wpdb->optionvalues (
261          option_id int(11) NOT NULL,
262          optionvalue tinytext,
263          optionvalue_desc varchar(255),
264          optionvalue_max int(11),
265          optionvalue_min int(11),
266          optionvalue_seq int(11),
267          UNIQUE (option_id, optionvalue(255)),
268          INDEX (option_id, optionvalue_seq)
269        )
270        ");
271       
272        // TODO: REWRITE THIS
273        $option_types = array(
274                "1" => "INSERT INTO $wpdb->optiontypes (optiontype_id, optiontype_name) VALUES ('1', 'integer')",
275                "2" => "INSERT INTO $wpdb->optiontypes (optiontype_id, optiontype_name) VALUES ('2', 'boolean')",
276                "3" => "INSERT INTO $wpdb->optiontypes (optiontype_id, optiontype_name) VALUES ('3', 'string')",
277                "4" => "INSERT INTO $wpdb->optiontypes (optiontype_id, optiontype_name) VALUES ('4', 'date')",
278                "5" => "INSERT INTO $wpdb->optiontypes (optiontype_id, optiontype_name) VALUES ('5', 'select')",
279                "6" => "INSERT INTO $wpdb->optiontypes (optiontype_id, optiontype_name) VALUES ('6', 'range')",
280                "7" => "INSERT INTO $wpdb->optiontypes (optiontype_id, optiontype_name) VALUES ('7', 'sqlselect')");
281
282        foreach ($option_types as $option_id => $query) {
283                if(!$wpdb->get_var("SELECT * FROM $wpdb->optiontypes WHERE optiontype_id = '$option_id'")) {
284                        $wpdb->query($query);
285                }
286        }
287
288        // Guess a site URI
289$guessurl = preg_replace('|/wp-admin/.*|i', '', 'http://' . $HTTP_HOST . $REQUEST_URI);
290        $option_data = array(           //base options from b2cofig
291                "1" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (1,'siteurl', 3, '$guessurl', 'siteurl is your blog\'s URL: for example, \'http://example.com/wordpress\'', 8, 30)",
292                "2" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (2,'blogfilename', 3, 'index.php', 'blogfilename is the name of the default file for your blog', 8, 20)",
293                "3" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (3,'blogname', 3, 'my weblog', 'blogname is the name of your blog', 8, 20)",
294                "4" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (4,'blogdescription', 3, 'babblings!', 'blogdescription is the description of your blog', 8, 40)",
295                //"INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (6,'search_engine_friendly_urls', 2, '0', 'Querystring Configuration ** (don\'t change if you don\'t know what you\'re doing)', 8, 20)",
296                "7" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (7,'new_users_can_blog', 2, '0', 'whether you want new users to be able to post entries once they have registered', 8, 20)",
297                "8" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (8,'users_can_register', 2, '1', 'whether you want to allow users to register on your blog', 8, 20)",
298                "54" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (54,'admin_email', 3, '[email protected]', 'Your email (obvious eh?)', 8, 20)",
299                // general blog setup
300                "9" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (9 ,'start_of_week', 5, '1', 'day at the start of the week', 8, 20)",
301                //"INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (10,'use_preview', 2, '1', 'Do you want to use the \'preview\' function', 8, 20)",
302                "14" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (14,'use_htmltrans', 2, '1', 'IMPORTANT! set this to false if you are using Chinese, Japanese, Korean, or other double-bytes languages', 8, 20)",
303                "15" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (15,'use_balanceTags', 2, '1', 'this could help balance your HTML code. if it gives bad results, set it to false', 8, 20)",
304                "16" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (16,'use_smilies', 2, '1', 'set this to true to enable smiley conversion in posts (note: this makes smiley conversion in ALL posts)', 8, 20)",
305                "17" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (17,'smilies_directory', 3, 'http://example.com/wp-images/smilies', 'the directory where your smilies are (no trailing slash)', 8, 40)",
306                "18" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (18,'require_name_email', 2, '0', 'set this to true to require e-mail and name, or false to allow comments without e-mail/name', 8, 20)",
307                "20" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (20,'comments_notify', 2, '1', 'set this to true to let every author be notified about comments on their posts', 8, 20)",
308                //rss/rdf feeds
309                "21" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (21,'posts_per_rss', 1, '10', 'number of last posts to syndicate', 8, 20)",
310                "22" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (22,'rss_language', 3, 'en', 'the language of your blog ( see this: http://backend.userland.com/stories/storyReader$16 )', 8, 20)",
311                "23" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (23,'rss_encoded_html', 2, '0', 'for b2rss.php: allow encoded HTML in &lt;description> tag?', 8, 20)",
312                "24" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (24,'rss_excerpt_length', 1, '50', 'length (in words) of excerpts in the RSS feed? 0=unlimited note: in b2rss.php, this will be set to 0 if you use encoded HTML', 8, 20)",
313                "25" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (25,'rss_use_excerpt', 2, '1', 'use the excerpt field for rss feed.', 8, 20)",
314                "29" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (29,'use_trackback', 2, '1', 'set this to false or true, whether you want to allow your posts to be trackback\'able or not note: setting it to false would also disable sending trackbacks', 8, 20)",
315                "30" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (30,'use_pingback', 2, '1', 'set this to false or true, whether you want to allow your posts to be pingback\'able or not note: setting it to false would also disable sending pingbacks', 8, 20)",
316                //file upload
317                "31" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (31,'use_fileupload', 2, '0', 'set this to false to disable file upload, or true to enable it', 8, 20)",
318                "32" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (32,'fileupload_realpath', 3, '/home/your/site/wordpress/images', 'enter the real path of the directory where you\'ll upload the pictures \nif you\'re unsure about what your real path is, please ask your host\'s support staff \nnote that the  directory must be writable by the webserver (chmod 766) \nnote for windows-servers users: use forwardslashes instead of backslashes', 8, 40)",
319                "33" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (33,'fileupload_url', 3, 'http://example.com/images', 'enter the URL of that directory (it\'s used to generate the links to the uploded files)', 8, 40)",
320                "34" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (34,'fileupload_allowedtypes', 3, ' jpg gif png ', 'accepted file types, separated by spaces. example: \'jpg gif png\'', 8, 20)",
321                "35" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (35,'fileupload_maxk', 1, '96', 'by default, most servers limit the size of uploads to 2048 KB, if you want to set it to a lower value, here it is (you cannot set a higher value than your server limit)', 8, 20)",
322                "36" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (36,'fileupload_minlevel', 1, '1', 'you may not want all users to upload pictures/files, so you can set a minimum level for this', 8, 20)",
323                "37" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (37,'fileupload_allowedusers', 3, '', '...or you may authorize only some users. enter their logins here, separated by spaces. if you leave this variable blank, all users who have the minimum level are authorized to upload. example: \'barbara anne george\'', 8, 30)",
324                // email settings
325                "38" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (38,'mailserver_url', 3, 'mail.example.com', 'mailserver settings', 8, 20)",
326                "39" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (39,'mailserver_login', 3, '[email protected]', 'mailserver settings', 8, 20)",
327                "40" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (40,'mailserver_pass', 3, 'password', 'mailserver settings', 8, 20)",
328                "41" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (41,'mailserver_port', 1, '110', 'mailserver settings', 8, 20)",
329                "42" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (42,'default_category', 1, '1', 'by default posts will have this category', 8, 20)",
330                "46" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (46,'use_phoneemail', 2, '0', 'some mobile phone email services will send identical subject & content on the same line if you use such a service, set use_phoneemail to true, and indicate a separator string', 8, 20)",
331               
332                // default post stuff
333               
334                "55" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(55,'default_post_status',    5, 'publish', 'The default state of each new post', 8, 20)",
335                "56" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(56,'default_comment_status', 5, 'open', 'The default state of comments for each new post', 8, 20)",
336                "57" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(57,'default_ping_status',    5, 'open', 'The default ping state for each new post', 8, 20)",
337                "58" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(58,'default_pingback_flag',  5, '1', 'Whether the \'PingBack the URLs in this post\' checkbox should be checked by default', 8, 20)",
338                "59" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(59,'default_post_category',  7, '1', 'The default category for each new post', 8, 20)",
339                "83" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(83,'default_post_edit_rows', 1, '9', 'The number of rows in the edit post form (min 3, max 100)', 8, 5)",
340
341                // original options from options page
342                "48" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (48,'posts_per_page', 1, '20','How many posts/days to show on the index page.', 4, 20)",
343                "49" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (49,'what_to_show', 5, 'posts','Posts or days', 4, 20)",
344                "50" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (50,'archive_mode', 5, 'monthly','Which \'unit\' to use for archives.', 4, 20)",
345                "51" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (51,'time_difference', 6, '0', 'if you\'re not on the timezone of your server', 4, 20)",
346                "52" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (52,'date_format', 3, 'n/j/Y', 'see note for format characters', 4, 20)",
347                "53" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (53,'time_format', 3, 'g:i a', 'see note for format characters', 4, 20)",          "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (84,'use_geo_positions', 2, '0', 'Turns on the geo url features of WordPress', 8, 20)",
348                "85" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (85,'use_default_geourl', 2, '1','enables placement of default GeoURL ICBM location even when no other specified', 8, 20)",
349                "86" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (86,'default_geourl_lat ', 8, 0.0, 'The default Latitude ICBM value - <a href=\"http://www.geourl.org/resources.html\" target=\"_blank\">see here</a>', 8, 20)",
350                "87" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (87,'default_geourl_lon', 8, 0.0, 'The default Longitude ICBM value', 8, 20)",
351                "60" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (60,'links_minadminlevel',             1, '5', 'The minimum admin level to edit links', 8, 10)",
352                "61" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (61,'links_use_adminlevels',           2, '1', 'set this to false to have all links visible and editable to everyone in the link manager', 8, 20)",
353                "62" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (62,'links_rating_type',               5, 'image', 'Set this to the type of rating indication you wish to use', 8, 10)",
354                "63" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (63,'links_rating_char',               3, '*', 'If we are set to \'char\' which char to use.', 8, 5)",
355                "64" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (64,'links_rating_ignore_zero',        2, '1', 'What do we do with a value of zero? set this to true to output nothing, 0 to output as normal (number/image)', 8, 20)",
356                "65" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (65,'links_rating_single_image',       2, '1', 'Use the same image for each rating point? (Uses links_rating_image[0])', 8, 20)",
357                "66" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (66,'links_rating_image0',             3, 'wp-links/links-images/tick.png', 'Image for rating 0 (and for single image)', 8, 40)",
358                "67" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (67,'links_rating_image1',             3, 'wp-links/links-images/rating-1.gif', 'Image for rating 1', 8, 40)",
359                "68" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (68,'links_rating_image2',             3, 'wp-links/links-images/rating-2.gif', 'Image for rating 2', 8, 40)",
360                "69" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (69,'links_rating_image3',             3, 'wp-links/links-images/rating-3.gif', 'Image for rating 3', 8, 40)",
361                "70" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (70,'links_rating_image4',             3, 'wp-links/links-images/rating-4.gif', 'Image for rating 4', 8, 40)",
362                "71" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (71,'links_rating_image5',             3, 'wp-links/links-images/rating-5.gif', 'Image for rating 5', 8, 40)",
363                "72" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (72,'links_rating_image6',             3, 'wp-links/links-images/rating-6.gif', 'Image for rating 6', 8, 40)",
364                "73" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (73,'links_rating_image7',             3, 'wp-links/links-images/rating-7.gif', 'Image for rating 7', 8, 40)",
365                "74" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (74,'links_rating_image8',             3, 'wp-links/links-images/rating-8.gif', 'Image for rating 8', 8, 40)",
366                "75" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (75,'links_rating_image9',             3, 'wp-links/links-images/rating-9.gif', 'Image for rating 9', 8, 40)",
367                "77" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (77,'weblogs_xml_url',                 3, 'http://www.weblogs.com/changes.xml', 'Which file to grab from weblogs.com', 8, 40)",
368                "78" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (78,'weblogs_cacheminutes',            1, '60', 'cache time in minutes (if it is older than this get a new copy)', 8, 10)",
369                "79" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (79,'links_updated_date_format',       3, 'd/m/Y h:i', 'The date format for the updated tooltip', 8, 25)",
370                "80" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (80,'links_recently_updated_prepend',  3, '&gt;&gt;', 'The text to prepend to a recently updated link', 8, 10)",
371                "81" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (81,'links_recently_updated_append',   3, '&lt;&lt;', 'The text to append to a recently updated link', 8, 20)",
372                "82" => "INSERT INTO $wpdb->options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES (82,'links_recently_updated_time',     1, '120', 'The time in minutes to consider a link recently updated', 8, 20)"
373                );
374
375        foreach ($option_data as $option_id => $query) {
376                if(!$wpdb->get_var("SELECT * FROM $wpdb->options WHERE option_id = '$option_id'")) {
377                        $wpdb->query($query);
378                }
379        }
380       
381        $option_groups = array(
382        "INSERT INTO $wpdb->optiongroups (group_id,  group_name, group_desc) VALUES (1, 'Other Options', 'Posts per page etc. Original options page')",
383        "INSERT INTO $wpdb->optiongroups (group_id,  group_name, group_desc) VALUES (2, 'General blog settings', 'Things you\'ll probably want to tweak')",
384        "INSERT INTO $wpdb->optiongroups (group_id,  group_name, group_desc) VALUES (3, 'RSS/RDF Feeds, Track/Ping-backs', 'Settings for RSS/RDF Feeds, Track/ping-backs')",
385        "INSERT INTO $wpdb->optiongroups (group_id,  group_name, group_desc) VALUES (4, 'File uploads', 'Settings for file uploads')",
386        "INSERT INTO $wpdb->optiongroups (group_id,  group_name, group_desc) VALUES (5, 'Blog-by-Email settings', 'Settings for blogging via email')",
387        "INSERT INTO $wpdb->optiongroups (group_id,  group_name, group_desc) VALUES (6, 'Base settings', 'Basic settings required to get your blog working')",
388        "INSERT INTO $wpdb->optiongroups (group_id,  group_name, group_desc) VALUES (7, 'Default post options', 'Default settings for new posts.')",
389        "INSERT INTO $wpdb->optiongroups (group_id,  group_name, group_desc) VALUES (8, 'Link Manager Settings', 'Various settings for the link manager.')",
390        "INSERT INTO $wpdb->optiongroups (group_id, group_name, group_desc) VALUES (9, 'Geo Options', 'Settings which control the posting and display of Geo Options')");
391
392        foreach ($option_groups as $query) {
393                $option_id = preg_match('|VALUES \(([0-9]+)|', $query, $matches);
394                $option_id = $matches[1];
395                if(!$wpdb->get_var("SELECT * FROM $wpdb->optiongroups WHERE group_id = '$option_id'")) {
396                        $wpdb->query($query);
397                        }
398        }       
399       
400        $optiongroup_options = array (          "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (1,48,1 )",
401                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (1,49,2 )",
402                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (1,50,3 )",
403                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (1,51,4 )",
404                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (1,52,5 )",
405                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (1,53,6 )",
406               
407               
408                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,9 ,1 )",
409                //"INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,10,2 )",
410                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,11,3 )",
411                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,12,4 )",
412                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,13,5 )",
413                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,14,6 )",
414                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,15,7 )",
415                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,16,8 )",
416                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,17,9 )",
417                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,18,10)",
418                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,19,11)",
419                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (2,20,12)",
420               
421               
422                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (3,21,1 )",
423                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (3,22,2 )",
424                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (3,23,3 )",
425                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (3,24,4 )",
426                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (3,25,5 )",
427                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (3,26,6 )",
428                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (3,27,7 )",
429                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (3,28,8 )",
430                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (3,29,9 )",
431                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (3,30,10)",
432               
433               
434                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (4,31,1 )",
435                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (4,32,2 )",
436                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (4,33,3 )",
437                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (4,34,4 )",
438                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (4,35,5 )",
439                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (4,36,6 )",
440                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (4,37,7 )",
441               
442               
443                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (5,38,1 )",
444                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (5,39,2 )",
445                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (5,40,3 )",
446                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (5,41,4 )",
447                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (5,42,5 )",
448                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (5,43,6 )",
449                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (5,44,7 )",
450                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (5,45,8 )",
451                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (5,46,9 )",
452                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (5,47,10)",
453               
454               
455                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (6,1,1)",
456                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (6,2,2)",
457                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (6,3,3)",
458                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (6,4,4)",
459                //"INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (6,6,5)",
460                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (6,7,6)",
461                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (6,8,7)",
462                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (6,54,8)",
463                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (7,55,1 )",
464                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (7,56,2 )",
465                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (7,57,3 )",
466                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (7,58,4 )",
467                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (7,59,5 )",
468                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (7,83,5 )",
469                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,60,1 )",
470                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,61,2 )",
471                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,62,3 )",
472                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,63,4 )",
473                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,64,5 )",
474                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,65,6 )",
475                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,66,7 )",
476                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,67,8 )",
477                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,68,9 )",
478                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,69,10)",
479                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,70,11)",
480                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,71,12)",
481                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,72,13)",
482                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,73,14)",
483                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,74,15)",
484                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,75,16)",
485                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,76,17)",
486                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,77,18)",
487                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,78,19)",
488                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,79,20)",
489                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,80,21)",
490                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,81,22)",
491                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (8,82,23)",
492                        "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (9,84,1)",
493                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (9,85,1)",
494                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (9,86,1)",
495                "INSERT INTO $wpdb->optiongroup_options (group_id, option_id, seq) VALUES (9,87,1)",
496        );
497
498        foreach ($optiongroup_options as $query) {
499                preg_match('|VALUES \([0-9]+,([0-9]+)|', $query, $matches);
500                $option_id = $matches[1];
501                if(!$wpdb->get_var("SELECT * FROM $wpdb->optiongroup_options WHERE option_id = '$option_id'")) {
502                        $wpdb->query($query);
503                        }
504        }       
505       
506        $option_values = array(
507                // select data for what to show
508                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (49, 'days',  'days',        null,null,1)",
509                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (49, 'posts', 'posts',       null,null,2)",
510                // select data for archive mode
511                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (50, 'daily',     'daily',       null,null,1)",
512                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (50, 'weekly',    'weekly',      null,null,2)",
513                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (50, 'monthly',   'monthly',     null,null,3)",
514                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (50, 'postbypost','post by post',null,null,4)",
515                // select data for time diff
516                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (51, 'hours', 'hours', 23, -23, null)",
517                // select data for start of week
518                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (9, '0', 'Sunday',   null,null,1)",
519                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (9, '1', 'Monday',   null,null,2)",
520                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (9, '6', 'Saturday', null,null,3)",
521               
522               
523                // Add in a new page for POST DEFAULTS
524               
525                // default_post_status  select one of publish draft private
526                // default_comment_status select one of open closed
527                // default_ping_status select one of open closed
528                // default_pingback_flag select one of checked unchecked
529                // default_post_category sql_select "SELECT cat_id AS value, cat_name AS label FROM $wpdb->categories order by cat_name"
530               
531       
532
533               
534                // select data for post_status
535                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (55, 'publish', 'Publish', null,null,1)",
536                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (55, 'draft',   'Draft',   null,null,2)",
537                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (55, 'private', 'Private', null,null,3)",
538               
539                // select data for comment_status
540                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (56, 'open', 'Open',   null,null,1)",
541                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (56, 'closed', 'Closed', null,null,2)",
542               
543                // select data for ping_status (aargh duplication!)
544                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (57, 'open', 'Open',   null,null,1)",
545                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (57, 'closed', 'Closed', null,null,2)",
546               
547                // select data for pingback flag
548                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (58, '1', 'Checked',   null,null,1)",
549                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (58, '0', 'Unchecked', null,null,2)",
550               
551                // sql select data for default
552                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (59, 'SELECT cat_id AS value, cat_name AS label FROM $wpdb->categories order by cat_name', '', null,null,1)",
553                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (62, 'number', 'Number',    null,null,1)",
554                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (62, 'char',   'Character', null,null,2)",
555                "INSERT INTO $wpdb->optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (62, 'image',  'Image',     null,null,3)"
556                );
557               
558        foreach ($option_values as $query) {
559                preg_match("|VALUES \(([0-9]+), '([^']+)'|", $query, $matches);
560                $option_id = $matches[1];
561                $value = $matches[2];
562                if(!$wpdb->get_var("SELECT * FROM $wpdb->optionvalues WHERE option_id = '$option_id' AND optionvalue = '$value'")) {
563                        $wpdb->query($query);
564                        }
565        }       
566               
567
568            if (file_exists('../wp-links/links.config.php')) {
569        include('../wp-links/links.config.php');
570   
571        // now update the database with those settings
572        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_minadminlevel           )."' WHERE option_id=60"; $q = $wpdb->query($query);
573        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_use_adminlevels         )."' WHERE option_id=61"; $q = $wpdb->query($query);
574        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_type             )."' WHERE option_id=62"; $q = $wpdb->query($query);
575        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_char             )."' WHERE option_id=63"; $q = $wpdb->query($query);
576        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_ignore_zero      )."' WHERE option_id=64"; $q = $wpdb->query($query);
577        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_single_image     )."' WHERE option_id=65"; $q = $wpdb->query($query);
578        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_image0           )."' WHERE option_id=66"; $q = $wpdb->query($query);
579        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_image1           )."' WHERE option_id=67"; $q = $wpdb->query($query);
580        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_image2           )."' WHERE option_id=68"; $q = $wpdb->query($query);
581        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_image3           )."' WHERE option_id=69"; $q = $wpdb->query($query);
582        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_image4           )."' WHERE option_id=70"; $q = $wpdb->query($query);
583        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_image5           )."' WHERE option_id=71"; $q = $wpdb->query($query);
584        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_image6           )."' WHERE option_id=72"; $q = $wpdb->query($query);
585        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_image7           )."' WHERE option_id=73"; $q = $wpdb->query($query);
586        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_image8           )."' WHERE option_id=74"; $q = $wpdb->query($query);
587        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_rating_image9           )."' WHERE option_id=75"; $q = $wpdb->query($query);
588        $query = "UPDATE $wpdb->options SET option_value='".addslashes($weblogs_cache_file            )."' WHERE option_id=76"; $q = $wpdb->query($query);
589        $query = "UPDATE $wpdb->options SET option_value='".addslashes($weblogs_xml_url               )."' WHERE option_id=77"; $q = $wpdb->query($query);
590        $query = "UPDATE $wpdb->options SET option_value='".addslashes($weblogs_cacheminutes          )."' WHERE option_id=78"; $q = $wpdb->query($query);
591        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_updated_date_format     )."' WHERE option_id=79"; $q = $wpdb->query($query);
592        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_recently_updated_prepend)."' WHERE option_id=80"; $q = $wpdb->query($query);
593        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_recently_updated_append )."' WHERE option_id=81"; $q = $wpdb->query($query);
594        $query = "UPDATE $wpdb->options SET option_value='".addslashes($links_recently_updated_time   )."' WHERE option_id=82"; $q = $wpdb->query($query);
595    // end if links.config.php exists
596    }
597
598}
599
600function upgrade_100() {
601        global $wpdb;
602        maybe_add_column($wpdb->posts, 'post_name', "ALTER TABLE `$wpdb->posts` ADD `post_name` VARCHAR(200) NOT NULL");
603        maybe_add_column($wpdb->posts, 'to_ping', "ALTER TABLE $wpdb->posts ADD `to_ping` TEXT NOT NULL");
604        maybe_add_column($wpdb->posts, 'pinged', "ALTER TABLE $wpdb->posts ADD `pinged` TEXT NOT NULL");
605        maybe_add_column($wpdb->posts, 'post_modified', "ALTER TABLE $wpdb->posts ADD `post_modified` DATETIME NOT NULL");
606        maybe_add_column($wpdb->posts, 'post_content_filtered', "ALTER TABLE $wpdb->posts ADD `post_content_filtered` TEXT NOT NULL");
607        maybe_add_column($wpdb->categories, 'category_nicename', "ALTER TABLE `$wpdb->categories` ADD `category_nicename` VARCHAR(200) NOT NULL");     
608        maybe_add_column($wpdb->categories, 'category_description', "ALTER TABLE `$wpdb->categories` ADD `category_description` TEXT NOT NULL");
609        maybe_add_column($wpdb->categories, 'category_parent', "ALTER TABLE `$wpdb->categories` ADD `category_parent` INT(4) NOT NULL");
610        maybe_add_column($wpdb->links, 'link_rss', "ALTER TABLE `$wpdb->links` ADD `link_rss` VARCHAR( 255 ) NOT NULL;");
611        maybe_add_column($wpdb->users, 'user_description', "ALTER TABLE `$wpdb->users` ADD `user_description` TEXT NOT NULL");
612        maybe_add_column($wpdb->comments, 'comment_approved', "ALTER TABLE $wpdb->comments ADD COLUMN comment_approved ENUM('0', '1') DEFAULT '1' NOT NULL");
613
614        // Create indicies
615        add_clean_index($wpdb->posts, 'post_name');
616        add_clean_index($wpdb->categories, 'category_nicename');
617        add_clean_index($wpdb->comments, 'comment_approved');
618
619
620        // Options stuff
621        if (!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'comment_moderation'")) {
622                $wpdb->query("INSERT INTO $wpdb->options
623                        (option_id, blog_id, option_name, option_can_override, option_type, option_value, option_width, option_height, option_description, option_admin_level)
624                        VALUES
625                        ('0', '0', 'comment_moderation', 'Y', '5',' none', 20, 8, 'If enabled, comments will only be shown after they have been approved.', 8)");
626        }
627
628        $oid = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'comment_moderation'");     
629        $gid = $wpdb->get_var("SELECT group_id FROM $wpdb->optiongroups WHERE group_name = 'General blog settings'");
630        $seq = $wpdb->get_var("SELECT MAX(seq) FROM $wpdb->optiongroup_options WHERE group_id = '$gid'");
631        ++$seq;
632        if (!$wpdb->get_row("SELECT * FROM $wpdb->optiongroup_options WHERE group_id = '$gid' AND option_id = '$oid'")) {
633                $wpdb->query("INSERT INTO $wpdb->optiongroup_options 
634                (group_id, option_id, seq)
635                VALUES
636                ('$gid', '$oid', '$seq')");
637        }
638         
639        if (!$wpdb->get_row("SELECT * FROM $wpdb->optionvalues WHERE option_id = $oid AND optionvalue = 'auto'")) {
640                $wpdb->query("INSERT INTO $wpdb->optionvalues 
641                (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq)
642                VALUES
643                ('$oid','auto', 'Automatic', NULL, NULL, 3)");
644        }
645        if (!$wpdb->get_row("SELECT * FROM $wpdb->optionvalues WHERE option_id = $oid AND optionvalue = 'none'")) {
646                $wpdb->query("INSERT INTO $wpdb->optionvalues 
647                (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq)
648                VALUES
649                ('$oid', 'none', 'None', NULL, NULL, 1)");
650        }
651        if (!$wpdb->get_row("SELECT * FROM $wpdb->optionvalues WHERE option_id = $oid AND optionvalue = 'manual'")) {
652                $wpdb->query("INSERT INTO $wpdb->optionvalues 
653                (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq)
654                VALUES
655                ('$oid', 'manual', 'Manual', NULL, NULL, 2)");
656        }
657       
658        if (!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'moderation_notify'")) {
659                $wpdb->query("INSERT INTO $wpdb->options 
660                        (option_id, blog_id, option_name, option_can_override, option_type, option_value, option_width, option_height, option_description, option_admin_level)
661                        VALUES
662                        ('0', '0', 'moderation_notify' , 'Y', '2', '1', 20, 8, 'Set this to true if you want to be notified about new comments that wait for approval', 8)");
663        }
664       
665        $oid = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'moderation_notify'");     
666        $seq = $wpdb->get_var("SELECT MAX(seq) FROM $wpdb->optiongroup_options WHERE group_id = '$gid'");
667        ++$seq;
668        if (!$wpdb->get_row("SELECT * FROM $wpdb->optiongroup_options WHERE group_id = '$gid' AND option_id = '$oid'")) {
669                $wpdb->query("INSERT INTO $wpdb->optiongroup_options 
670                        (group_id, option_id, seq)
671                        VALUES
672                        ('$gid', '$oid', '$seq')");
673        }
674        // Get the title and ID of every post, post_name to check if it already has a value
675        $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''");
676        if ($posts) {
677                foreach($posts as $post) {
678                        if ('' == $post->post_name) { 
679                                $newtitle = sanitize_title($post->post_title);
680                                $wpdb->query("UPDATE $wpdb->posts SET post_name = '$newtitle' WHERE ID = '$post->ID'");
681                        }
682                }
683        }
684       
685        $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories");
686        foreach ($categories as $category) {
687                if ('' == $category->category_nicename) { 
688                        $newtitle = sanitize_title($category->cat_name);
689                        $wpdb->query("UPDATE $wpdb->categories SET category_nicename = '$newtitle' WHERE cat_ID = '$category->cat_ID'");
690                }
691        }
692       
693        if (!$wpdb->get_var("SELECT option_name FROM $wpdb->options WHERE option_name = 'permalink_structure'")) { // If it's not already there
694                $wpdb->query("INSERT INTO `$wpdb->options`
695                        (`option_id`, `blog_id`, `option_name`, `option_can_override`, `option_type`, `option_value`, `option_width`, `option_height`, `option_description`, `option_admin_level`)
696                        VALUES
697                        ('', '0', 'permalink_structure', 'Y', '3', '', '20', '8', 'How the permalinks for your site are constructed. See <a href=\"options-permalink.php\">permalink options page</a> for necessary mod_rewrite rules and more information.', '8');");
698                }
699               
700        if (!$wpdb->get_var("SELECT option_name FROM $wpdb->options WHERE option_name = 'gzipcompression'")) { // If it's not already there
701                $wpdb->query("INSERT INTO `$wpdb->options`
702                        (`option_id`, `blog_id`, `option_name`, `option_can_override`, `option_type`, `option_value`, `option_width`, `option_height`, `option_description`, `option_admin_level`)
703                        VALUES
704                        ('', '0', 'gzipcompression', 'Y', '2', '0', '20', '8', 'Whether your output should be gzipped or not. Enable this if you don&#8217;t already have mod_gzip running.', '8');");
705                $optionid = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'gzipcompression'");
706                $wpdb->query("INSERT INTO $wpdb->optiongroup_options
707                        (group_id, option_id, seq)
708                        VALUES
709                        (2, $optionid, 5)");
710                }
711        if (!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'hack_file'")) {
712                $wpdb->query("INSERT INTO `$wpdb->options`
713                        ( `option_id` , `blog_id` , `option_name` , `option_can_override` , `option_type` , `option_value` , `option_width` , `option_height` , `option_description` , `option_admin_level` )
714                        VALUES
715                        ('', '0', 'hack_file', 'Y', '2', '0', '20', '8', 'Set this to true if you plan to use a hacks file. This is a place for you to store code hacks that won&#8217;t be overwritten when you upgrade. The file must be in your wordpress root and called <code>my-hacks.php</code>', '8')");
716                $optionid = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'hack_file'");
717                $wpdb->query("INSERT INTO $wpdb->optiongroup_options
718                        (group_id, option_id, seq)
719                        VALUES
720                        (2, $optionid, 5)");
721        }
722
723        $wpdb->query("UPDATE $wpdb->optionvalues SET optionvalue_max = 23 , optionvalue_min = -23 WHERE option_id = 51");
724        // fix upload users description
725        $wpdb->query("UPDATE $wpdb->options SET option_description = '...or you may authorize only some users. enter their logins here, separated by spaces. if you leave this variable blank, all users who have the minimum level are authorized to upload. example: \'barbara anne george\'' WHERE option_id = 37");
726        // and file types
727        $wpdb->query("UPDATE $wpdb->options SET option_description = 'accepted file types, separated by spaces. example: \'jpg gif png\'' WHERE option_id = 34");
728        // add link to php date format. this could be to a wordpress.org page in the future
729        $wpdb->query("UPDATE $wpdb->options SET option_description = 'see <a href=\"http://php.net/date\">help</a> for format characters' WHERE option_id = 52");
730        $wpdb->query("UPDATE $wpdb->options SET option_description = 'see <a href=\"http://php.net/date\">help</a> for format characters' WHERE option_id = 53");
731        $wpdb->query("UPDATE $wpdb->options SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
732                                                      WHERE option_name LIKE 'links_rating_image%'
733                                                      AND option_value LIKE 'wp-links/links-images/%'");
734        $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'comment_allowed_tags'");
735        $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'use_preview'");
736        $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'search_engine_friendly_urls'");
737        // Multiple categories
738        maybe_create_table($wpdb->post2cat, "
739                CREATE TABLE `$wpdb->post2cat` (
740                `rel_id` INT NOT NULL AUTO_INCREMENT ,
741                `post_id` INT NOT NULL ,
742                `category_id` INT NOT NULL ,
743                PRIMARY KEY ( `rel_id` ) ,
744                INDEX ( `post_id` , `category_id` )
745                )
746                ");
747
748        $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $wpdb->post2cat");
749        if ($done_ids) :
750                foreach ($done_ids as $done_id) :
751                        $done_posts[] = $done_id->post_id;
752                endforeach;
753                $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
754        else:
755                $catwhere = '';
756        endif;
757       
758        $allposts = $wpdb->get_results("SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere");
759        if ($allposts) :
760                foreach ($allposts as $post) {
761                        // Check to see if it's already been imported
762                        $cat = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post->ID AND category_id = $post->post_category");
763                        if (!$cat && 0 != $post->post_category) { // If there's no result
764                                $wpdb->query("
765                                        INSERT INTO $wpdb->post2cat
766                                        (post_id, category_id)
767                                        VALUES
768                                        ('$post->ID', '$post->post_category')
769                                        ");
770                        }
771                }
772        endif;
773}
774
775function upgrade_101() {
776        global $wpdb;
777        // Fix possible duplicate problem from CVS, we can REMOVE this later
778        $option59 = $wpdb->get_results("SELECT * FROM $wpdb->optionvalues WHERE option_id  = '59'");
779        if (1 < count($option59)) {
780                $wpdb->query("DELETE FROM $wpdb->optionvalues WHERE option_id = '59' AND optionvalue LIKE('%FROM  order%')");
781        }
782       
783        // Remove 'automatic' option for comment moderation until it actually does something
784        $wpdb->query("DELETE FROM $wpdb->optionvalues WHERE optionvalue = 'auto'");
785        // Less intrusive default
786        $wpdb->query("ALTER TABLE `$wpdb->linkcategories` CHANGE `show_description` `show_description` ENUM( 'Y', 'N' ) DEFAULT 'N' NOT NULL"); 
787       
788        // Clean up indices, add a few
789        add_clean_index($wpdb->posts, 'post_name');
790        add_clean_index($wpdb->posts, 'post_status');
791        add_clean_index($wpdb->categories, 'category_nicename');
792        add_clean_index($wpdb->comments, 'comment_approved');
793        add_clean_index($wpdb->comments, 'comment_post_ID');
794        add_clean_index($wpdb->links , 'link_category');
795        add_clean_index($wpdb->links , 'link_visible');
796}
797
798
799function upgrade_110() {
800  global $wpdb;
801       
802        maybe_add_column($wpdb->comments, 'user_id', "ALTER TABLE `$wpdb->comments` ADD `user_id` INT DEFAULT '0' NOT NULL ;");
803        maybe_add_column($wpdb->users, 'user_activation_key', "ALTER TABLE `$wpdb->users` ADD `user_activation_key` VARCHAR( 60 ) NOT NULL ;");
804        maybe_add_column($wpdb->users, 'user_status', "ALTER TABLE `$wpdb->users` ADD `user_status` INT DEFAULT '0' NOT NULL ;");
805        $wpdb->query("ALTER TABLE `$wpdb->posts` CHANGE `comment_status` `comment_status` ENUM( 'open', 'closed', 'registered_only' ) DEFAULT 'open' NOT NULL");
806
807        maybe_add_column($wpdb->users, 'user_nicename', "ALTER TABLE `$wpdb->users` ADD `user_nicename` VARCHAR(50) DEFAULT '' NOT NULL ;");
808        maybe_add_column($wpdb->posts, 'post_date_gmt', "ALTER TABLE $wpdb->posts ADD post_date_gmt DATETIME NOT NULL AFTER post_date");
809        maybe_add_column($wpdb->posts, 'post_modified_gmt', "ALTER TABLE $wpdb->posts ADD post_modified_gmt DATETIME NOT NULL AFTER post_modified");
810        maybe_add_column($wpdb->comments, 'comment_date_gmt', "ALTER TABLE $wpdb->comments ADD comment_date_gmt DATETIME NOT NULL AFTER comment_date");
811
812    // Set user_nicename.
813        $users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users");
814        foreach ($users as $user) {
815                if ('' == $user->user_nicename) { 
816                        $newname = sanitize_title($user->user_nickname);
817                        $wpdb->query("UPDATE $wpdb->users SET user_nicename = '$newname' WHERE ID = '$user->ID'");
818                }
819        }
820
821        // Convert passwords to MD5 and update table appropiately
822
823        $user_table = $wpdb->get_row("DESCRIBE $wpdb->users user_pass");
824        if ($user_table->Type != 'varchar(32)') {
825                $wpdb->query("ALTER TABLE $wpdb->users MODIFY user_pass varchar(64) not null");
826        }
827       
828        $query = 'SELECT ID, user_pass from '.$wpdb->users;
829        foreach ($wpdb->get_results($query) as $row) {
830                if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) {
831                           $wpdb->query('UPDATE '.$wpdb->users.' SET user_pass = MD5(\''.$row->user_pass.'\') WHERE ID = \''.$row->ID.'\'');
832                }
833        }
834       
835        $wpdb->query("DELETE FROM $wpdb->optiongroups WHERE group_id = 1");
836        $wpdb->query("DELETE FROM $wpdb->optiongroups WHERE group_id = 2");
837        $wpdb->query("DELETE FROM $wpdb->optiongroups WHERE group_id = 3");
838        $wpdb->query("DELETE FROM $wpdb->optiongroups WHERE group_id = 4");
839        $wpdb->query("DELETE FROM $wpdb->optiongroups WHERE group_id = 5");
840        $wpdb->query("DELETE FROM $wpdb->optiongroups WHERE group_id = 6");
841        $wpdb->query("DELETE FROM $wpdb->optiongroups WHERE group_id = 7");
842        $wpdb->query("DELETE FROM $wpdb->optiongroups WHERE group_id = 9");
843
844        $wpdb->query("UPDATE $wpdb->optiongroups SET group_name = 'Link Manager' WHERE group_id = 8");
845
846        // Add blog_charset option
847        if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'blog_charset'")) {
848                $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('blog_charset', 3, 'utf-8', 8)");
849        }
850
851        // Get the GMT offset, we'll use that later on
852        $all_options = get_alloptions_110();
853
854        $time_difference = $all_options->time_difference;
855
856        $server_time = time()+date('Z');
857        $weblogger_time = $server_time + $time_difference*3600;
858        $gmt_time = time();
859
860        $diff_gmt_server = ($gmt_time - $server_time) / 3600;
861        $diff_weblogger_server = ($weblogger_time - $server_time) / 3600;
862        $diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;
863        $gmt_offset = -$diff_gmt_weblogger;
864
865        // Add a gmt_offset option, with value $gmt_offset
866        if (!get_settings('gmt_offset')) {
867                if(!$wpdb->get_var("SELECT * FROM $wpdb->options WHERE option_name = 'gmt_offset'")) {
868                        $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_description, option_admin_level) VALUES ('gmt_offset', 8, $gmt_offset, 'The difference in hours between GMT and your timezone', 8)");
869                }
870
871        }
872
873        // Check if we already set the GMT fields (if we did, then
874        // MAX(post_date_gmt) can't be '0000-00-00 00:00:00'
875        // <michel_v> I just slapped myself silly for not thinking about it earlier
876        $got_gmt_fields = ($wpdb->get_var("SELECT MAX(post_date_gmt) FROM $wpdb->posts") == '0000-00-00 00:00:00') ? false : true;
877
878        if (!$got_gmt_fields) {
879
880                // Add or substract time to all dates, to get GMT dates
881                $add_hours = intval($diff_gmt_weblogger);
882                $add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours));
883                $wpdb->query("UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
884                $wpdb->query("UPDATE $wpdb->posts SET post_modified = post_date");
885                $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'");
886                $wpdb->query("UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
887                $wpdb->query("UPDATE $wpdb->users SET dateYMDhour = DATE_ADD(dateYMDhour, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
888        }
889
890        // post-meta
891        maybe_create_table($wpdb->postmeta, "
892        CREATE TABLE $wpdb->postmeta (
893          meta_id int(11) NOT NULL auto_increment,
894          post_id int(11) NOT NULL default 0,
895          meta_key varchar(255),
896          meta_value text,
897          PRIMARY KEY (meta_id),
898          INDEX (post_id),
899          INDEX (meta_key)
900        )
901        ");
902
903        // First we need to enlarge option_value so it can hold larger values:
904        $wpdb->query("ALTER TABLE `$wpdb->options` CHANGE `option_value` `option_value` TEXT NOT NULL");
905       
906        // Now an option for blog pinging
907        if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'ping_sites'")) {
908                $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('ping_sites', 3, 'http://rpc.pingomatic.com/', 8)");
909        }
910       
911        // Option for using the advanced edit screen by default
912        if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'advanced_edit'")) {
913                $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('advanced_edit', 5, '0', 8)");
914        }
915        // Fix for CVS versions
916        $wpdb->query("UPDATE $wpdb->options SET option_type = '5' WHERE option_name = 'advanced_edit'");
917       
918        // Now an option for moderation words
919        if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'moderation_keys'")) {
920                $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('moderation_keys', 3, '', 8)");
921        }
922
923        // Option for plugins
924        if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'active_plugins'")) {
925                $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('active_plugins', 3, '', 8)");
926        }
927
928        // Option for max # of links per comment
929        if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'comment_max_links'")) {
930                $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('comment_max_links', 3, '5', 8)");
931        }
932
933        // Option for different blog URL
934        if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'home'")) {
935                $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('home', 3, '', 8)");
936        }
937
938        // Option for category base
939        if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'category_base'")) {
940                $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('category_base', 3, '', 8)");
941        }
942
943        // Delete unused options
944        $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file');
945        foreach ($unusedoptions as $option) :
946                delete_option($option);
947        endforeach;
948
949        // Forward-thinking
950        $wpdb->query("ALTER TABLE `$wpdb->posts` CHANGE `post_status` `post_status` ENUM( 'publish', 'draft', 'private', 'static' ) DEFAULT 'publish' NOT NULL");
951        maybe_add_column($wpdb->posts, 'post_parent', "ALTER TABLE `$wpdb->posts` ADD `post_parent` INT NOT NULL ;");
952
953
954        $wpdb->query("ALTER TABLE `$wpdb->comments` CHANGE `comment_author_url` `comment_author_url` VARCHAR( 200 ) NOT NULL");
955}
956
957function upgrade_130() {
958    global $wpdb;
959
960        if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'default_email_category'")) {
961        $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_description, option_admin_level) VALUES('default_email_category', 1, '1', 'by default posts by email will have this category', 8)");
962    }
963
964        if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'recently_edited'")) {
965        $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('recently_edited', 3, '', 8)");
966    }
967
968        maybe_add_column($wpdb->options, 'autoload', "ALTER TABLE `$wpdb->options` ADD `autoload` ENUM( 'yes', 'no' ) NOT NULL ;");
969
970        // Set up a few options not to load by default
971        $fatoptions = array( 'moderation_keys', 'recently_edited' );
972        foreach ($fatoptions as $fatoption) :
973                $wpdb->query("UPDATE $wpdb->options SET `autoload` = 'no' WHERE option_name = '$fatoption'");
974        endforeach;
975
976    // Remove extraneous backslashes.
977        $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt FROM $wpdb->posts");
978        if ($posts) {
979                foreach($posts as $post) {
980            $post_content = addslashes(deslash($post->post_content));
981            $post_title = addslashes(deslash($post->post_title));
982            $post_excerpt = addslashes(deslash($post->post_excerpt));
983            $wpdb->query("UPDATE $wpdb->posts SET post_title = '$post_title', post_content = '$post_content', post_excerpt = '$post_excerpt' WHERE ID = '$post->ID'");
984                }
985        }
986
987    // Remove extraneous backslashes.
988        $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments");
989        if ($comments) {
990                foreach($comments as $comment) {
991            $comment_content = addslashes(deslash($comment->comment_content));
992            $comment_author = addslashes(deslash($comment->comment_author));
993            $wpdb->query("UPDATE $wpdb->comments SET comment_content = '$comment_content', comment_author = '$comment_author' WHERE comment_ID = '$comment->comment_ID'");
994                }
995        }
996
997    // Remove extraneous backslashes.
998        $links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM $wpdb->links");
999        if ($links) {
1000                foreach($links as $link) {
1001            $link_name = addslashes(deslash($link->link_name));
1002            $link_description = addslashes(deslash($link->link_description));
1003            $wpdb->query("UPDATE $wpdb->links SET link_name = '$link_name', link_description = '$link_description' WHERE link_id = '$link->link_id'");
1004                }
1005        }
1006
1007    // The "paged" option for what_to_show is no more.
1008    if ($wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'what_to_show'") == 'paged') {
1009        $wpdb->query("UPDATE $wpdb->options SET option_value = 'posts' WHERE option_name = 'what_to_show'");
1010    }
1011
1012        if ( !is_array( get_settings('active_plugins') ) ) {
1013                $plugins = explode("\n", trim(get_settings('active_plugins')) );
1014                update_option('active_plugins', $plugins);
1015        }
1016
1017
1018}
1019
1020// The functions we use to actually do stuff
1021
1022// General
1023function maybe_create_table($table_name, $create_ddl) {
1024    global $wpdb;
1025    foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
1026        if ($table == $table_name) {
1027            return true;
1028        }
1029    }
1030    //didn't find it try to create it.
1031    $q = $wpdb->query($create_ddl);
1032    // we cannot directly tell that whether this succeeded!
1033    foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
1034        if ($table == $table_name) {
1035            return true;
1036        }
1037    }
1038    return false;
1039}
1040
1041function drop_index($table, $index) {
1042        global $wpdb;
1043        $wpdb->hide_errors();
1044        $wpdb->query("ALTER TABLE `$table` DROP INDEX `$index`");
1045        // Now we need to take out all the extra ones we may have created
1046        for ($i = 0; $i < 25; $i++) {
1047                $wpdb->query("ALTER TABLE `$table` DROP INDEX `{$index}_$i`");
1048        }
1049        $wpdb->show_errors();
1050        return true;
1051}
1052
1053function add_clean_index($table, $index) {
1054        global $wpdb;
1055        drop_index($table, $index);
1056        $wpdb->query("ALTER TABLE `$table` ADD INDEX ( `$index` )");
1057        return true;
1058}
1059
1060/**
1061 ** maybe_add_column()
1062 ** Add column to db table if it doesn't exist.
1063 ** Returns:  true if already exists or on successful completion
1064 **           false on error
1065 */
1066function maybe_add_column($table_name, $column_name, $create_ddl) {
1067    global $wpdb, $debug;
1068    foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
1069        if ($debug) echo("checking $column == $column_name<br />");
1070        if ($column == $column_name) {
1071            return true;
1072        }
1073    }
1074    //didn't find it try to create it.
1075    $q = $wpdb->query($create_ddl);
1076    // we cannot directly tell that whether this succeeded!
1077    foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
1078        if ($column == $column_name) {
1079            return true;
1080        }
1081    }
1082    return false;
1083}
1084
1085
1086// get_alloptions as it was for 1.2.
1087function get_alloptions_110() {
1088        global $wpdb;
1089        if ($options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options")) {
1090                foreach ($options as $option) {
1091                        // "When trying to design a foolproof system,
1092                        //  never underestimate the ingenuity of the fools :)" -- Dougal
1093                        if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
1094                        if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
1095                        if ('category_base' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
1096                        $all_options->{$option->option_name} = stripslashes($option->option_value);
1097                }
1098        }
1099        return $all_options;
1100}
1101
1102function deslash($content) {
1103    // Note: \\\ inside a regex denotes a single backslash.
1104
1105    // Replace one or more backslashes followed by a single quote with
1106    // a single quote.
1107    $content = preg_replace("/\\\+'/", "'", $content);
1108
1109    // Replace one or more backslashes followed by a double quote with
1110    // a double quote.
1111    $content = preg_replace('/\\\+"/', '"', $content);
1112
1113    // Replace one or more backslashes with one backslash.
1114    $content = preg_replace("/\\\+/", "\\", $content);
1115
1116    return $content;
1117}
1118
1119function dbDelta($queries, $execute = true) {
1120        global $wpdb;
1121       
1122        // Seperate individual queries into an array
1123        if( !is_array($queries) ) {
1124                $queries = explode( ';', $queries );
1125                if('' == $queries[count($queries) - 1]) array_pop($queries);
1126        }
1127       
1128        $cqueries = array(); // Creation Queries
1129        $iqueries = array(); // Insertion Queries
1130        $for_update = array();
1131       
1132        // Create a tablename index for an array ($cqueries) of queries
1133        foreach($queries as $qry) {
1134                if(preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
1135                        $cqueries[strtolower($matches[1])] = $qry;
1136                        $for_update[$matches[1]] = 'Created table '.$matches[1];
1137                }
1138                else if(preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
1139                        array_unshift($cqueries, $qry);
1140                }
1141                else if(preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
1142                        $iqueries[] = $qry;
1143                }
1144                else if(preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {
1145                        $iqueries[] = $qry;
1146                }
1147                else {
1148                        // Unrecognized query type
1149                }
1150        }       
1151
1152        // Check to see which tables and fields exist
1153        if($tables = $wpdb->get_col('SHOW TABLES;')) {
1154                // For every table in the database
1155                foreach($tables as $table) {
1156                        // If a table query exists for the database table...
1157                        if( array_key_exists(strtolower($table), $cqueries) ) {
1158                                // Clear the field and index arrays
1159                                unset($cfields);
1160                                unset($indices);
1161                                // Get all of the field names in the query from between the parens
1162                                preg_match("|\((.*)\)|ms", $cqueries[strtolower($table)], $match2);
1163                                $qryline = trim($match2[1]);
1164
1165                                // Separate field lines into an array
1166                                $flds = explode("\n", $qryline);
1167
1168                                //echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
1169                               
1170                                // For every field line specified in the query
1171                                foreach($flds as $fld) {
1172                                        // Extract the field name
1173                                        preg_match("|^([^ ]*)|", trim($fld), $fvals);
1174                                        $fieldname = $fvals[1];
1175                                       
1176                                        // Verify the found field name
1177                                        $validfield = true;
1178                                        switch(strtolower($fieldname))
1179                                        {
1180                                        case '':
1181                                        case 'primary':
1182                                        case 'index':
1183                                        case 'fulltext':
1184                                        case 'unique':
1185                                        case 'key':
1186                                                $validfield = false;
1187                                                $indices[] = trim(trim($fld), ", \n");
1188                                                break;
1189                                        }
1190                                        $fld = trim($fld);
1191                                       
1192                                        // If it's a valid field, add it to the field array
1193                                        if($validfield) {
1194                                                $cfields[strtolower($fieldname)] = trim($fld, ", \n");
1195                                        }
1196                                }
1197                               
1198                                // Fetch the table column structure from the database
1199                                $tablefields = $wpdb->get_results("DESCRIBE {$table};");
1200                                                               
1201                                // For every field in the table
1202                                foreach($tablefields as $tablefield) {                         
1203                                        // If the table field exists in the field array...
1204                                        if(array_key_exists(strtolower($tablefield->Field), $cfields)) {
1205                                                // Get the field type from the query
1206                                                preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
1207                                                $fieldtype = $matches[1];
1208
1209                                                // Is actual field type different from the field type in query?
1210                                                if($tablefield->Type != $fieldtype) {
1211                                                        // Add a query to change the column type
1212                                                        $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
1213                                                        $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
1214                                                }
1215                                               
1216                                                // Get the default value from the array
1217                                                        //echo "{$cfields[strtolower($tablefield->Field)]}<br>";
1218                                                if(preg_match("| DEFAULT '(.*)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
1219                                                        $default_value = $matches[1];
1220                                                        if($tablefield->Default != $default_value)
1221                                                        {
1222                                                                // Add a query to change the column's default value
1223                                                                $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
1224                                                                $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
1225                                                        }
1226                                                }
1227
1228                                                // Remove the field from the array (so it's not added)
1229                                                unset($cfields[strtolower($tablefield->Field)]);
1230                                        }
1231                                        else {
1232                                                // This field exists in the table, but not in the creation queries?
1233                                        }
1234                                }
1235
1236                                // For every remaining field specified for the table
1237                                foreach($cfields as $fieldname => $fielddef) {
1238                                        // Push a query line into $cqueries that adds the field to that table
1239                                        $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
1240                                        $for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
1241                                }
1242                               
1243                                // Index stuff goes here
1244                                // Fetch the table index structure from the database
1245                                $tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
1246                               
1247                                if($tableindices) {
1248                                        // Clear the index array
1249                                        unset($index_ary);
1250
1251                                        // For every index in the table
1252                                        foreach($tableindices as $tableindex) {
1253                                                // Add the index to the index data array
1254                                                $keyname = $tableindex->Key_name;
1255                                                $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
1256                                                $index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
1257                                        }
1258
1259                                        // For each actual index in the index array
1260                                        foreach($index_ary as $index_name => $index_data) {
1261                                                // Build a create string to compare to the query
1262                                                $index_string = '';
1263                                                if($index_name == 'PRIMARY') {
1264                                                        $index_string .= 'PRIMARY ';
1265                                                }
1266                                                else if($index_data['unique']) {
1267                                                        $index_string .= 'UNIQUE ';
1268                                                }
1269                                                $index_string .= 'KEY ';
1270                                                if($index_name != 'PRIMARY') {
1271                                                        $index_string .= $index_name;
1272                                                }
1273                                                $index_columns = '';
1274                                                // For each column in the index
1275                                                foreach($index_data['columns'] as $column_data) {                                       
1276                                                        if($index_columns != '') $index_columns .= ',';
1277                                                        // Add the field to the column list string
1278                                                        $index_columns .= $column_data['fieldname'];
1279                                                        if($column_data['subpart'] != '') {
1280                                                                $index_columns .= '('.$column_data['subpart'].')';
1281                                                        }
1282                                                }
1283                                                // Add the column list to the index create string
1284                                                $index_string .= ' ('.$index_columns.')';
1285
1286                                                if(!(($aindex = array_search($index_string, $indices)) === false)) {
1287                                                        unset($indices[$aindex]);
1288                                                        //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br/>Found index:".$index_string."</pre>\n";
1289                                                }
1290                                                //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";
1291                                        }
1292                                }
1293
1294                                // For every remaining index specified for the table
1295                                foreach($indices as $index) {
1296                                        // Push a query line into $cqueries that adds the index to that table
1297                                        $cqueries[] = "ALTER TABLE {$table} ADD $index";
1298                                        $for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index;
1299                                }
1300
1301                                // Remove the original table creation query from processing
1302                                unset($cqueries[strtolower($table)]);
1303                                unset($for_update[strtolower($table)]);
1304                        } else {
1305                                // This table exists in the database, but not in the creation queries?
1306                        }
1307                }
1308        }
1309
1310        $allqueries = array_merge($cqueries, $iqueries);
1311        if($execute) {
1312                foreach($allqueries as $query) {
1313                        //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($query, true)."</pre>\n";
1314                        $wpdb->query($query);
1315                }
1316        }
1317
1318        return $for_update;
1319}
1320
1321function make_db_current() {
1322        global $wp_queries;
1323
1324        $alterations = dbDelta($wp_queries);
1325        echo "<ol>\n";
1326        foreach($alterations as $alteration) echo "<li>$alteration</li>\n";
1327        echo "</ol>\n";
1328}
1329
1330function rename_field($table, $field, $new) {
1331//      ALTER TABLE `wp_users` CHANGE `ID` `user_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT
1332}
1333
1334function remove_field($table, $field) {
1335        global $wpdb;
1336// ALTER TABLE `wp_users` DROP `user_domain`
1337}
1338
1339?>
Note: See TracBrowser for help on using the repository browser.