2 // Here we keep the DB structure and option values
6 // Declare these as global in case schema.php is included from a function.
7 global $wpdb, $wp_queries;
9 if ( $wpdb->supports_collation() ) {
10 if ( ! empty($wpdb->charset) )
11 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
12 if ( ! empty($wpdb->collate) )
13 $charset_collate .= " COLLATE $wpdb->collate";
16 $wp_queries="CREATE TABLE $wpdb->terms (
17 term_id bigint(20) NOT NULL auto_increment,
18 name varchar(55) NOT NULL default '',
19 slug varchar(200) NOT NULL default '',
20 term_group bigint(10) NOT NULL default 0,
21 PRIMARY KEY (term_id),
22 UNIQUE KEY slug (slug)
24 CREATE TABLE $wpdb->term_taxonomy (
25 term_taxonomy_id bigint(20) NOT NULL auto_increment,
26 term_id bigint(20) NOT NULL default 0,
27 taxonomy varchar(32) NOT NULL default '',
28 description longtext NOT NULL,
29 parent bigint(20) NOT NULL default 0,
30 count bigint(20) NOT NULL default 0,
31 PRIMARY KEY (term_taxonomy_id),
32 UNIQUE KEY term_id_taxonomy (term_id,taxonomy)
34 CREATE TABLE $wpdb->term_relationships (
35 object_id bigint(20) NOT NULL default 0,
36 term_taxonomy_id bigint(20) NOT NULL default 0,
37 term_order int(11) NOT NULL default 0,
38 PRIMARY KEY (object_id,term_taxonomy_id),
39 KEY term_taxonomy_id (term_taxonomy_id)
41 CREATE TABLE $wpdb->comments (
42 comment_ID bigint(20) unsigned NOT NULL auto_increment,
43 comment_post_ID int(11) NOT NULL default '0',
44 comment_author tinytext NOT NULL,
45 comment_author_email varchar(100) NOT NULL default '',
46 comment_author_url varchar(200) NOT NULL default '',
47 comment_author_IP varchar(100) NOT NULL default '',
48 comment_date datetime NOT NULL default '0000-00-00 00:00:00',
49 comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
50 comment_content text NOT NULL,
51 comment_karma int(11) NOT NULL default '0',
52 comment_approved varchar(20) NOT NULL default '1',
53 comment_agent varchar(255) NOT NULL default '',
54 comment_type varchar(20) NOT NULL default '',
55 comment_parent bigint(20) NOT NULL default '0',
56 user_id bigint(20) NOT NULL default '0',
57 PRIMARY KEY (comment_ID),
58 KEY comment_approved (comment_approved),
59 KEY comment_post_ID (comment_post_ID),
60 KEY comment_approved_date_gmt (comment_approved,comment_date_gmt),
61 KEY comment_date_gmt (comment_date_gmt)
63 CREATE TABLE $wpdb->links (
64 link_id bigint(20) NOT NULL auto_increment,
65 link_url varchar(255) NOT NULL default '',
66 link_name varchar(255) NOT NULL default '',
67 link_image varchar(255) NOT NULL default '',
68 link_target varchar(25) NOT NULL default '',
69 link_category bigint(20) NOT NULL default '0',
70 link_description varchar(255) NOT NULL default '',
71 link_visible varchar(20) NOT NULL default 'Y',
72 link_owner int(11) NOT NULL default '1',
73 link_rating int(11) NOT NULL default '0',
74 link_updated datetime NOT NULL default '0000-00-00 00:00:00',
75 link_rel varchar(255) NOT NULL default '',
76 link_notes mediumtext NOT NULL,
77 link_rss varchar(255) NOT NULL default '',
78 PRIMARY KEY (link_id),
79 KEY link_category (link_category),
80 KEY link_visible (link_visible)
82 CREATE TABLE $wpdb->options (
83 option_id bigint(20) NOT NULL auto_increment,
84 blog_id int(11) NOT NULL default '0',
85 option_name varchar(64) NOT NULL default '',
86 option_value longtext NOT NULL,
87 autoload varchar(20) NOT NULL default 'yes',
88 PRIMARY KEY (option_id,blog_id,option_name),
89 KEY option_name (option_name)
91 CREATE TABLE $wpdb->postmeta (
92 meta_id bigint(20) NOT NULL auto_increment,
93 post_id bigint(20) NOT NULL default '0',
94 meta_key varchar(255) default NULL,
96 PRIMARY KEY (meta_id),
97 KEY post_id (post_id),
98 KEY meta_key (meta_key)
100 CREATE TABLE $wpdb->posts (
101 ID bigint(20) unsigned NOT NULL auto_increment,
102 post_author bigint(20) NOT NULL default '0',
103 post_date datetime NOT NULL default '0000-00-00 00:00:00',
104 post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
105 post_content longtext NOT NULL,
106 post_title text NOT NULL,
107 post_category int(4) NOT NULL default '0',
108 post_excerpt text NOT NULL,
109 post_status varchar(20) NOT NULL default 'publish',
110 comment_status varchar(20) NOT NULL default 'open',
111 ping_status varchar(20) NOT NULL default 'open',
112 post_password varchar(20) NOT NULL default '',
113 post_name varchar(200) NOT NULL default '',
114 to_ping text NOT NULL,
115 pinged text NOT NULL,
116 post_modified datetime NOT NULL default '0000-00-00 00:00:00',
117 post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
118 post_content_filtered text NOT NULL,
119 post_parent bigint(20) NOT NULL default '0',
120 guid varchar(255) NOT NULL default '',
121 menu_order int(11) NOT NULL default '0',
122 post_type varchar(20) NOT NULL default 'post',
123 post_mime_type varchar(100) NOT NULL default '',
124 comment_count bigint(20) NOT NULL default '0',
126 KEY post_name (post_name),
127 KEY type_status_date (post_type,post_status,post_date,ID)
129 CREATE TABLE $wpdb->users (
130 ID bigint(20) unsigned NOT NULL auto_increment,
131 user_login varchar(60) NOT NULL default '',
132 user_pass varchar(64) NOT NULL default '',
133 user_nicename varchar(50) NOT NULL default '',
134 user_email varchar(100) NOT NULL default '',
135 user_url varchar(100) NOT NULL default '',
136 user_registered datetime NOT NULL default '0000-00-00 00:00:00',
137 user_activation_key varchar(60) NOT NULL default '',
138 user_status int(11) NOT NULL default '0',
139 display_name varchar(250) NOT NULL default '',
141 KEY user_login_key (user_login),
142 KEY user_nicename (user_nicename)
144 CREATE TABLE $wpdb->usermeta (
145 umeta_id bigint(20) NOT NULL auto_increment,
146 user_id bigint(20) NOT NULL default '0',
147 meta_key varchar(255) default NULL,
149 PRIMARY KEY (umeta_id),
150 KEY user_id (user_id),
151 KEY meta_key (meta_key)
152 ) $charset_collate;";
154 function populate_options() {
155 global $wpdb, $wp_db_version;
157 $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
158 $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
159 add_option('siteurl', $guessurl);
160 add_option('blogname', __('My Blog'));
161 add_option('blogdescription', __('Just another WordPress weblog'));
162 add_option('users_can_register', 0);
163 add_option('admin_email', 'you@example.com');
164 add_option('start_of_week', 1);
165 add_option('use_balanceTags', 0);
166 add_option('use_smilies', 1);
167 add_option('require_name_email', 1);
168 add_option('comments_notify', 1);
169 add_option('posts_per_rss', 10);
170 add_option('rss_excerpt_length', 50);
171 add_option('rss_use_excerpt', 0);
172 add_option('mailserver_url', 'mail.example.com');
173 add_option('mailserver_login', 'login@example.com');
174 add_option('mailserver_pass', 'password');
175 add_option('mailserver_port', 110);
176 add_option('default_category', 1);
177 add_option('default_comment_status', 'open');
178 add_option('default_ping_status', 'open');
179 add_option('default_pingback_flag', 1);
180 add_option('default_post_edit_rows', 10);
181 add_option('posts_per_page', 10);
182 add_option('what_to_show', 'posts');
183 add_option('date_format', __('F j, Y'));
184 add_option('time_format', __('g:i a'));
185 add_option('links_updated_date_format', __('F j, Y g:i a'));
186 add_option('links_recently_updated_prepend', '<em>');
187 add_option('links_recently_updated_append', '</em>');
188 add_option('links_recently_updated_time', 120);
189 add_option('comment_moderation', 0);
190 add_option('moderation_notify', 1);
191 add_option('permalink_structure');
192 add_option('gzipcompression', 0);
193 add_option('hack_file', 0);
194 add_option('blog_charset', 'UTF-8');
195 add_option('moderation_keys');
196 add_option('active_plugins');
197 add_option('home', $guessurl);
198 // in case it is set, but blank, update "home"
199 if ( !__get_option('home') ) update_option('home', $guessurl);
200 add_option('category_base');
201 add_option('ping_sites', 'http://rpc.pingomatic.com/');
202 add_option('advanced_edit', 0);
203 add_option('comment_max_links', 2);
204 add_option('gmt_offset', date('Z') / 3600);
206 add_option('default_email_category', 1);
207 add_option('recently_edited');
208 add_option('use_linksupdate', 0);
209 add_option('template', 'default');
210 add_option('stylesheet', 'default');
211 add_option('comment_whitelist', 1);
212 add_option('page_uris');
213 add_option('blacklist_keys');
214 add_option('comment_registration', 0);
215 add_option('rss_language', 'en');
216 add_option('html_type', 'text/html');
218 add_option('use_trackback', 0);
220 add_option('default_role', 'subscriber');
221 add_option('db_version', $wp_db_version);
223 if ( ini_get('safe_mode') ) {
224 // Safe mode screws up mkdir(), so we must use a flat structure.
225 add_option('uploads_use_yearmonth_folders', 0);
226 add_option('upload_path', 'wp-content');
228 add_option('uploads_use_yearmonth_folders', 1);
229 add_option('upload_path', 'wp-content/uploads');
233 add_option('secret', wp_generate_password(64));
236 add_option('blog_public', '1');
237 add_option('default_link_category', 2);
238 add_option('show_on_front', 'posts');
241 add_option('tag_base');
244 add_option('show_avatars', '1');
245 add_option('avatar_rating', 'G');
246 add_option('upload_url_path', '');
247 add_option('thumbnail_size_w', 150);
248 add_option('thumbnail_size_h', 150);
249 add_option('thumbnail_crop', 1);
250 add_option('medium_size_w', 300);
251 add_option('medium_size_h', 300);
253 // Delete unused options
254 $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval');
255 foreach ($unusedoptions as $option) :
256 delete_option($option);
259 // Set up a few options not to load by default
260 $fatoptions = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' );
261 foreach ($fatoptions as $fatoption) :
262 $wpdb->query("UPDATE $wpdb->options SET `autoload` = 'no' WHERE option_name = '$fatoption'");
266 function populate_roles() {
267 populate_roles_160();
268 populate_roles_210();
269 populate_roles_230();
270 populate_roles_250();
273 function populate_roles_160() {
276 // Dummy gettext calls to get strings in the catalog.
277 _c('Administrator|User role');
278 _c('Editor|User role');
279 _c('Author|User role');
280 _c('Contributor|User role');
281 _c('Subscriber|User role');
283 add_role('administrator', 'Administrator|User role');
284 add_role('editor', 'Editor|User role');
285 add_role('author', 'Author|User role');
286 add_role('contributor', 'Contributor|User role');
287 add_role('subscriber', 'Subscriber|User role');
289 // Add caps for Administrator role
290 $role = get_role('administrator');
291 $role->add_cap('switch_themes');
292 $role->add_cap('edit_themes');
293 $role->add_cap('activate_plugins');
294 $role->add_cap('edit_plugins');
295 $role->add_cap('edit_users');
296 $role->add_cap('edit_files');
297 $role->add_cap('manage_options');
298 $role->add_cap('moderate_comments');
299 $role->add_cap('manage_categories');
300 $role->add_cap('manage_links');
301 $role->add_cap('upload_files');
302 $role->add_cap('import');
303 $role->add_cap('unfiltered_html');
304 $role->add_cap('edit_posts');
305 $role->add_cap('edit_others_posts');
306 $role->add_cap('edit_published_posts');
307 $role->add_cap('publish_posts');
308 $role->add_cap('edit_pages');
309 $role->add_cap('read');
310 $role->add_cap('level_10');
311 $role->add_cap('level_9');
312 $role->add_cap('level_8');
313 $role->add_cap('level_7');
314 $role->add_cap('level_6');
315 $role->add_cap('level_5');
316 $role->add_cap('level_4');
317 $role->add_cap('level_3');
318 $role->add_cap('level_2');
319 $role->add_cap('level_1');
320 $role->add_cap('level_0');
322 // Add caps for Editor role
323 $role = get_role('editor');
324 $role->add_cap('moderate_comments');
325 $role->add_cap('manage_categories');
326 $role->add_cap('manage_links');
327 $role->add_cap('upload_files');
328 $role->add_cap('unfiltered_html');
329 $role->add_cap('edit_posts');
330 $role->add_cap('edit_others_posts');
331 $role->add_cap('edit_published_posts');
332 $role->add_cap('publish_posts');
333 $role->add_cap('edit_pages');
334 $role->add_cap('read');
335 $role->add_cap('level_7');
336 $role->add_cap('level_6');
337 $role->add_cap('level_5');
338 $role->add_cap('level_4');
339 $role->add_cap('level_3');
340 $role->add_cap('level_2');
341 $role->add_cap('level_1');
342 $role->add_cap('level_0');
344 // Add caps for Author role
345 $role = get_role('author');
346 $role->add_cap('upload_files');
347 $role->add_cap('edit_posts');
348 $role->add_cap('edit_published_posts');
349 $role->add_cap('publish_posts');
350 $role->add_cap('read');
351 $role->add_cap('level_2');
352 $role->add_cap('level_1');
353 $role->add_cap('level_0');
355 // Add caps for Contributor role
356 $role = get_role('contributor');
357 $role->add_cap('edit_posts');
358 $role->add_cap('read');
359 $role->add_cap('level_1');
360 $role->add_cap('level_0');
362 // Add caps for Subscriber role
363 $role = get_role('subscriber');
364 $role->add_cap('read');
365 $role->add_cap('level_0');
368 function populate_roles_210() {
369 $roles = array('administrator', 'editor');
370 foreach ($roles as $role) {
371 $role = get_role($role);
375 $role->add_cap('edit_others_pages');
376 $role->add_cap('edit_published_pages');
377 $role->add_cap('publish_pages');
378 $role->add_cap('delete_pages');
379 $role->add_cap('delete_others_pages');
380 $role->add_cap('delete_published_pages');
381 $role->add_cap('delete_posts');
382 $role->add_cap('delete_others_posts');
383 $role->add_cap('delete_published_posts');
384 $role->add_cap('delete_private_posts');
385 $role->add_cap('edit_private_posts');
386 $role->add_cap('read_private_posts');
387 $role->add_cap('delete_private_pages');
388 $role->add_cap('edit_private_pages');
389 $role->add_cap('read_private_pages');
392 $role = get_role('administrator');
393 if ( ! empty($role) ) {
394 $role->add_cap('delete_users');
395 $role->add_cap('create_users');
398 $role = get_role('author');
399 if ( ! empty($role) ) {
400 $role->add_cap('delete_posts');
401 $role->add_cap('delete_published_posts');
404 $role = get_role('contributor');
405 if ( ! empty($role) ) {
406 $role->add_cap('delete_posts');
410 function populate_roles_230() {
411 $role = get_role( 'administrator' );
413 if ( !empty( $role ) ) {
414 $role->add_cap( 'unfiltered_upload' );
418 function populate_roles_250() {
419 $role = get_role( 'administrator' );
421 if ( !empty( $role ) ) {
422 $role->add_cap( 'edit_dashboard' );