3 * WordPress Administration Scheme API
5 * Here we keep the DB structure and option values.
8 * @subpackage Administration
12 * The database character collate.
15 * @name $charset_collate
17 $charset_collate = '';
19 // Declare these as global in case schema.php is included from a function.
20 global $wpdb, $wp_queries;
22 if ( $wpdb->has_cap( 'collation' ) ) {
23 if ( ! empty($wpdb->charset) )
24 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
25 if ( ! empty($wpdb->collate) )
26 $charset_collate .= " COLLATE $wpdb->collate";
29 /** Create WordPress database tables SQL */
30 $wp_queries = "CREATE TABLE $wpdb->terms (
31 term_id bigint(20) NOT NULL auto_increment,
32 name varchar(200) NOT NULL default '',
33 slug varchar(200) NOT NULL default '',
34 term_group bigint(10) NOT NULL default 0,
35 PRIMARY KEY (term_id),
36 UNIQUE KEY slug (slug),
39 CREATE TABLE $wpdb->term_taxonomy (
40 term_taxonomy_id bigint(20) NOT NULL auto_increment,
41 term_id bigint(20) NOT NULL default 0,
42 taxonomy varchar(32) NOT NULL default '',
43 description longtext NOT NULL,
44 parent bigint(20) NOT NULL default 0,
45 count bigint(20) NOT NULL default 0,
46 PRIMARY KEY (term_taxonomy_id),
47 UNIQUE KEY term_id_taxonomy (term_id,taxonomy)
49 CREATE TABLE $wpdb->term_relationships (
50 object_id bigint(20) NOT NULL default 0,
51 term_taxonomy_id bigint(20) NOT NULL default 0,
52 term_order int(11) NOT NULL default 0,
53 PRIMARY KEY (object_id,term_taxonomy_id),
54 KEY term_taxonomy_id (term_taxonomy_id)
56 CREATE TABLE $wpdb->comments (
57 comment_ID bigint(20) unsigned NOT NULL auto_increment,
58 comment_post_ID int(11) NOT NULL default '0',
59 comment_author tinytext NOT NULL,
60 comment_author_email varchar(100) NOT NULL default '',
61 comment_author_url varchar(200) NOT NULL default '',
62 comment_author_IP varchar(100) NOT NULL default '',
63 comment_date datetime NOT NULL default '0000-00-00 00:00:00',
64 comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
65 comment_content text NOT NULL,
66 comment_karma int(11) NOT NULL default '0',
67 comment_approved varchar(20) NOT NULL default '1',
68 comment_agent varchar(255) NOT NULL default '',
69 comment_type varchar(20) NOT NULL default '',
70 comment_parent bigint(20) NOT NULL default '0',
71 user_id bigint(20) NOT NULL default '0',
72 PRIMARY KEY (comment_ID),
73 KEY comment_approved (comment_approved),
74 KEY comment_post_ID (comment_post_ID),
75 KEY comment_approved_date_gmt (comment_approved,comment_date_gmt),
76 KEY comment_date_gmt (comment_date_gmt)
78 CREATE TABLE $wpdb->links (
79 link_id bigint(20) NOT NULL auto_increment,
80 link_url varchar(255) NOT NULL default '',
81 link_name varchar(255) NOT NULL default '',
82 link_image varchar(255) NOT NULL default '',
83 link_target varchar(25) NOT NULL default '',
84 link_category bigint(20) NOT NULL default '0',
85 link_description varchar(255) NOT NULL default '',
86 link_visible varchar(20) NOT NULL default 'Y',
87 link_owner int(11) NOT NULL default '1',
88 link_rating int(11) NOT NULL default '0',
89 link_updated datetime NOT NULL default '0000-00-00 00:00:00',
90 link_rel varchar(255) NOT NULL default '',
91 link_notes mediumtext NOT NULL,
92 link_rss varchar(255) NOT NULL default '',
93 PRIMARY KEY (link_id),
94 KEY link_category (link_category),
95 KEY link_visible (link_visible)
97 CREATE TABLE $wpdb->options (
98 option_id bigint(20) NOT NULL auto_increment,
99 blog_id int(11) NOT NULL default '0',
100 option_name varchar(64) NOT NULL default '',
101 option_value longtext NOT NULL,
102 autoload varchar(20) NOT NULL default 'yes',
103 PRIMARY KEY (option_id,blog_id,option_name),
104 KEY option_name (option_name)
106 CREATE TABLE $wpdb->postmeta (
107 meta_id bigint(20) NOT NULL auto_increment,
108 post_id bigint(20) NOT NULL default '0',
109 meta_key varchar(255) default NULL,
111 PRIMARY KEY (meta_id),
112 KEY post_id (post_id),
113 KEY meta_key (meta_key)
115 CREATE TABLE $wpdb->posts (
116 ID bigint(20) unsigned NOT NULL auto_increment,
117 post_author bigint(20) NOT NULL default '0',
118 post_date datetime NOT NULL default '0000-00-00 00:00:00',
119 post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
120 post_content longtext NOT NULL,
121 post_title text NOT NULL,
122 post_category int(4) NOT NULL default '0',
123 post_excerpt text NOT NULL,
124 post_status varchar(20) NOT NULL default 'publish',
125 comment_status varchar(20) NOT NULL default 'open',
126 ping_status varchar(20) NOT NULL default 'open',
127 post_password varchar(20) NOT NULL default '',
128 post_name varchar(200) NOT NULL default '',
129 to_ping text NOT NULL,
130 pinged text NOT NULL,
131 post_modified datetime NOT NULL default '0000-00-00 00:00:00',
132 post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
133 post_content_filtered text NOT NULL,
134 post_parent bigint(20) NOT NULL default '0',
135 guid varchar(255) NOT NULL default '',
136 menu_order int(11) NOT NULL default '0',
137 post_type varchar(20) NOT NULL default 'post',
138 post_mime_type varchar(100) NOT NULL default '',
139 comment_count bigint(20) NOT NULL default '0',
141 KEY post_name (post_name),
142 KEY type_status_date (post_type,post_status,post_date,ID),
143 KEY post_parent (post_parent)
145 CREATE TABLE $wpdb->users (
146 ID bigint(20) unsigned NOT NULL auto_increment,
147 user_login varchar(60) NOT NULL default '',
148 user_pass varchar(64) NOT NULL default '',
149 user_nicename varchar(50) NOT NULL default '',
150 user_email varchar(100) NOT NULL default '',
151 user_url varchar(100) NOT NULL default '',
152 user_registered datetime NOT NULL default '0000-00-00 00:00:00',
153 user_activation_key varchar(60) NOT NULL default '',
154 user_status int(11) NOT NULL default '0',
155 display_name varchar(250) NOT NULL default '',
157 KEY user_login_key (user_login),
158 KEY user_nicename (user_nicename)
160 CREATE TABLE $wpdb->usermeta (
161 umeta_id bigint(20) NOT NULL auto_increment,
162 user_id bigint(20) NOT NULL default '0',
163 meta_key varchar(255) default NULL,
165 PRIMARY KEY (umeta_id),
166 KEY user_id (user_id),
167 KEY meta_key (meta_key)
168 ) $charset_collate;";
171 * Create WordPress options and set the default values.
175 * @uses $wp_db_version
177 function populate_options() {
178 global $wpdb, $wp_db_version;
180 $guessurl = wp_guess_url();
182 do_action('populate_options');
184 add_option('siteurl', $guessurl);
185 add_option('blogname', __('My Blog'));
186 add_option('blogdescription', __('Just another WordPress weblog'));
187 add_option('users_can_register', 0);
188 add_option('admin_email', 'you@example.com');
189 add_option('start_of_week', 1);
190 add_option('use_balanceTags', 0);
191 add_option('use_smilies', 1);
192 add_option('require_name_email', 1);
193 add_option('comments_notify', 1);
194 add_option('posts_per_rss', 10);
195 add_option('rss_excerpt_length', 50);
196 add_option('rss_use_excerpt', 0);
197 add_option('mailserver_url', 'mail.example.com');
198 add_option('mailserver_login', 'login@example.com');
199 add_option('mailserver_pass', 'password');
200 add_option('mailserver_port', 110);
201 add_option('default_category', 1);
202 add_option('default_comment_status', 'open');
203 add_option('default_ping_status', 'open');
204 add_option('default_pingback_flag', 1);
205 add_option('default_post_edit_rows', 10);
206 add_option('posts_per_page', 10);
207 add_option('what_to_show', 'posts');
208 add_option('date_format', __('F j, Y'));
209 add_option('time_format', __('g:i a'));
210 add_option('links_updated_date_format', __('F j, Y g:i a'));
211 add_option('links_recently_updated_prepend', '<em>');
212 add_option('links_recently_updated_append', '</em>');
213 add_option('links_recently_updated_time', 120);
214 add_option('comment_moderation', 0);
215 add_option('moderation_notify', 1);
216 add_option('permalink_structure');
217 add_option('gzipcompression', 0);
218 add_option('hack_file', 0);
219 add_option('blog_charset', 'UTF-8');
220 add_option('moderation_keys');
221 add_option('active_plugins');
222 add_option('home', $guessurl);
223 // in case it is set, but blank, update "home"
224 if ( !__get_option('home') ) update_option('home', $guessurl);
225 add_option('category_base');
226 add_option('ping_sites', 'http://rpc.pingomatic.com/');
227 add_option('advanced_edit', 0);
228 add_option('comment_max_links', 2);
229 add_option('gmt_offset', date('Z') / 3600);
231 add_option('default_email_category', 1);
232 add_option('recently_edited');
233 add_option('use_linksupdate', 0);
234 add_option('template', 'default');
235 add_option('stylesheet', 'default');
236 add_option('comment_whitelist', 1);
237 add_option('page_uris');
238 add_option('blacklist_keys');
239 add_option('comment_registration', 0);
240 add_option('rss_language', 'en');
241 add_option('html_type', 'text/html');
243 add_option('use_trackback', 0);
245 add_option('default_role', 'subscriber');
246 add_option('db_version', $wp_db_version);
248 if ( ini_get('safe_mode') ) {
249 // Safe mode screws up mkdir(), so we must use a flat structure.
250 add_option('uploads_use_yearmonth_folders', 0);
251 add_option('upload_path', WP_CONTENT_DIR);
253 add_option('uploads_use_yearmonth_folders', 1);
254 add_option('upload_path', WP_CONTENT_DIR . '/uploads');
258 add_option('secret', wp_generate_password(64));
261 add_option('blog_public', '1');
262 add_option('default_link_category', 2);
263 add_option('show_on_front', 'posts');
266 add_option('tag_base');
269 add_option('show_avatars', '1');
270 add_option('avatar_rating', 'G');
271 add_option('upload_url_path', '');
272 add_option('thumbnail_size_w', 150);
273 add_option('thumbnail_size_h', 150);
274 add_option('thumbnail_crop', 1);
275 add_option('medium_size_w', 300);
276 add_option('medium_size_h', 300);
279 add_option('avatar_default', 'mystery');
280 add_option('enable_app', 0);
281 add_option('enable_xmlrpc', 0);
284 add_option('large_size_w', 1024);
285 add_option('large_size_h', 1024);
286 add_option('image_default_link_type', 'file');
287 add_option('image_default_size', '');
288 add_option('image_default_align', '');
289 add_option('close_comments_for_old_posts', 0);
290 add_option('close_comments_days_old', 14);
291 add_option('thread_comments', 0);
292 add_option('thread_comments_depth', 5);
293 add_option('page_comments', 1);
294 add_option('comments_per_page', 50);
295 add_option('default_comments_page', 'newest');
296 add_option('comment_order', 'asc');
297 add_option('use_ssl', 0);
298 add_option('sticky_posts', array());
299 add_option('widget_categories', array());
300 add_option('widget_text', array());
301 add_option('widget_rss', array());
302 add_option('update_core', array());
303 add_option('dismissed_update_core', array());
305 // Delete unused options
306 $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', 'deactivated_plugins');
307 foreach ($unusedoptions as $option) :
308 delete_option($option);
311 // Set up a few options not to load by default
312 $fatoptions = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' );
313 foreach ($fatoptions as $fatoption) :
314 $wpdb->query("UPDATE $wpdb->options SET `autoload` = 'no' WHERE option_name = '$fatoption'");
319 * Execute WordPress role creation for the various WordPress versions.
323 function populate_roles() {
324 populate_roles_160();
325 populate_roles_210();
326 populate_roles_230();
327 populate_roles_250();
328 populate_roles_260();
329 populate_roles_270();
333 * Create the roles for WordPress 2.0
337 function populate_roles_160() {
340 // Dummy gettext calls to get strings in the catalog.
341 _c('Administrator|User role');
342 _c('Editor|User role');
343 _c('Author|User role');
344 _c('Contributor|User role');
345 _c('Subscriber|User role');
347 add_role('administrator', 'Administrator|User role');
348 add_role('editor', 'Editor|User role');
349 add_role('author', 'Author|User role');
350 add_role('contributor', 'Contributor|User role');
351 add_role('subscriber', 'Subscriber|User role');
353 // Add caps for Administrator role
354 $role =& get_role('administrator');
355 $role->add_cap('switch_themes');
356 $role->add_cap('edit_themes');
357 $role->add_cap('activate_plugins');
358 $role->add_cap('edit_plugins');
359 $role->add_cap('edit_users');
360 $role->add_cap('edit_files');
361 $role->add_cap('manage_options');
362 $role->add_cap('moderate_comments');
363 $role->add_cap('manage_categories');
364 $role->add_cap('manage_links');
365 $role->add_cap('upload_files');
366 $role->add_cap('import');
367 $role->add_cap('unfiltered_html');
368 $role->add_cap('edit_posts');
369 $role->add_cap('edit_others_posts');
370 $role->add_cap('edit_published_posts');
371 $role->add_cap('publish_posts');
372 $role->add_cap('edit_pages');
373 $role->add_cap('read');
374 $role->add_cap('level_10');
375 $role->add_cap('level_9');
376 $role->add_cap('level_8');
377 $role->add_cap('level_7');
378 $role->add_cap('level_6');
379 $role->add_cap('level_5');
380 $role->add_cap('level_4');
381 $role->add_cap('level_3');
382 $role->add_cap('level_2');
383 $role->add_cap('level_1');
384 $role->add_cap('level_0');
386 // Add caps for Editor role
387 $role =& get_role('editor');
388 $role->add_cap('moderate_comments');
389 $role->add_cap('manage_categories');
390 $role->add_cap('manage_links');
391 $role->add_cap('upload_files');
392 $role->add_cap('unfiltered_html');
393 $role->add_cap('edit_posts');
394 $role->add_cap('edit_others_posts');
395 $role->add_cap('edit_published_posts');
396 $role->add_cap('publish_posts');
397 $role->add_cap('edit_pages');
398 $role->add_cap('read');
399 $role->add_cap('level_7');
400 $role->add_cap('level_6');
401 $role->add_cap('level_5');
402 $role->add_cap('level_4');
403 $role->add_cap('level_3');
404 $role->add_cap('level_2');
405 $role->add_cap('level_1');
406 $role->add_cap('level_0');
408 // Add caps for Author role
409 $role =& get_role('author');
410 $role->add_cap('upload_files');
411 $role->add_cap('edit_posts');
412 $role->add_cap('edit_published_posts');
413 $role->add_cap('publish_posts');
414 $role->add_cap('read');
415 $role->add_cap('level_2');
416 $role->add_cap('level_1');
417 $role->add_cap('level_0');
419 // Add caps for Contributor role
420 $role =& get_role('contributor');
421 $role->add_cap('edit_posts');
422 $role->add_cap('read');
423 $role->add_cap('level_1');
424 $role->add_cap('level_0');
426 // Add caps for Subscriber role
427 $role =& get_role('subscriber');
428 $role->add_cap('read');
429 $role->add_cap('level_0');
433 * Create and modify WordPress roles for WordPress 2.1.
437 function populate_roles_210() {
438 $roles = array('administrator', 'editor');
439 foreach ($roles as $role) {
440 $role =& get_role($role);
444 $role->add_cap('edit_others_pages');
445 $role->add_cap('edit_published_pages');
446 $role->add_cap('publish_pages');
447 $role->add_cap('delete_pages');
448 $role->add_cap('delete_others_pages');
449 $role->add_cap('delete_published_pages');
450 $role->add_cap('delete_posts');
451 $role->add_cap('delete_others_posts');
452 $role->add_cap('delete_published_posts');
453 $role->add_cap('delete_private_posts');
454 $role->add_cap('edit_private_posts');
455 $role->add_cap('read_private_posts');
456 $role->add_cap('delete_private_pages');
457 $role->add_cap('edit_private_pages');
458 $role->add_cap('read_private_pages');
461 $role =& get_role('administrator');
462 if ( ! empty($role) ) {
463 $role->add_cap('delete_users');
464 $role->add_cap('create_users');
467 $role =& get_role('author');
468 if ( ! empty($role) ) {
469 $role->add_cap('delete_posts');
470 $role->add_cap('delete_published_posts');
473 $role =& get_role('contributor');
474 if ( ! empty($role) ) {
475 $role->add_cap('delete_posts');
480 * Create and modify WordPress roles for WordPress 2.3.
484 function populate_roles_230() {
485 $role =& get_role( 'administrator' );
487 if ( !empty( $role ) ) {
488 $role->add_cap( 'unfiltered_upload' );
493 * Create and modify WordPress roles for WordPress 2.5.
497 function populate_roles_250() {
498 $role =& get_role( 'administrator' );
500 if ( !empty( $role ) ) {
501 $role->add_cap( 'edit_dashboard' );
506 * Create and modify WordPress roles for WordPress 2.6.
510 function populate_roles_260() {
511 $role =& get_role( 'administrator' );
513 if ( !empty( $role ) ) {
514 $role->add_cap( 'update_plugins' );
515 $role->add_cap( 'delete_plugins' );
520 * Create and modify WordPress roles for WordPress 2.7.
524 function populate_roles_270() {
525 $role =& get_role( 'administrator' );
527 if ( !empty( $role ) ) {
528 $role->add_cap( 'install_plugins' );
529 $role->add_cap( 'update_themes' );