3 * WordPress Administration Scheme API
5 * Here we keep the DB structure and option values.
8 * @subpackage Administration
11 // Declare these as global in case schema.php is included from a function.
12 global $wpdb, $wp_queries, $charset_collate;
15 * The database character collate.
18 * @name $charset_collate
20 $charset_collate = '';
22 if ( ! empty( $wpdb->charset ) )
23 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
24 if ( ! empty( $wpdb->collate ) )
25 $charset_collate .= " COLLATE $wpdb->collate";
28 * Retrieve the SQL for creating database tables.
32 * @param string $scope Optional. The tables for which to retrieve SQL. Can be all, global, ms_global, or blog tables. Defaults to all.
33 * @param int $blog_id Optional. The blog ID for which to retrieve SQL. Default is the current blog ID.
34 * @return string The SQL needed to create the requested tables.
36 function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
39 $charset_collate = '';
41 if ( ! empty($wpdb->charset) )
42 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
43 if ( ! empty($wpdb->collate) )
44 $charset_collate .= " COLLATE $wpdb->collate";
46 if ( $blog_id && $blog_id != $wpdb->blogid )
47 $old_blog_id = $wpdb->set_blog_id( $blog_id );
49 // Engage multisite if in the middle of turning it on from network.php.
50 $is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK );
52 // Blog specific tables.
53 $blog_tables = "CREATE TABLE $wpdb->terms (
54 term_id bigint(20) unsigned NOT NULL auto_increment,
55 name varchar(200) NOT NULL default '',
56 slug varchar(200) NOT NULL default '',
57 term_group bigint(10) NOT NULL default 0,
58 PRIMARY KEY (term_id),
59 UNIQUE KEY slug (slug),
62 CREATE TABLE $wpdb->term_taxonomy (
63 term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment,
64 term_id bigint(20) unsigned NOT NULL default 0,
65 taxonomy varchar(32) NOT NULL default '',
66 description longtext NOT NULL,
67 parent bigint(20) unsigned NOT NULL default 0,
68 count bigint(20) NOT NULL default 0,
69 PRIMARY KEY (term_taxonomy_id),
70 UNIQUE KEY term_id_taxonomy (term_id,taxonomy),
71 KEY taxonomy (taxonomy)
73 CREATE TABLE $wpdb->term_relationships (
74 object_id bigint(20) unsigned NOT NULL default 0,
75 term_taxonomy_id bigint(20) unsigned NOT NULL default 0,
76 term_order int(11) NOT NULL default 0,
77 PRIMARY KEY (object_id,term_taxonomy_id),
78 KEY term_taxonomy_id (term_taxonomy_id)
80 CREATE TABLE $wpdb->commentmeta (
81 meta_id bigint(20) unsigned NOT NULL auto_increment,
82 comment_id bigint(20) unsigned NOT NULL default '0',
83 meta_key varchar(255) default NULL,
85 PRIMARY KEY (meta_id),
86 KEY comment_id (comment_id),
87 KEY meta_key (meta_key)
89 CREATE TABLE $wpdb->comments (
90 comment_ID bigint(20) unsigned NOT NULL auto_increment,
91 comment_post_ID bigint(20) unsigned NOT NULL default '0',
92 comment_author tinytext NOT NULL,
93 comment_author_email varchar(100) NOT NULL default '',
94 comment_author_url varchar(200) NOT NULL default '',
95 comment_author_IP varchar(100) NOT NULL default '',
96 comment_date datetime NOT NULL default '0000-00-00 00:00:00',
97 comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
98 comment_content text NOT NULL,
99 comment_karma int(11) NOT NULL default '0',
100 comment_approved varchar(20) NOT NULL default '1',
101 comment_agent varchar(255) NOT NULL default '',
102 comment_type varchar(20) NOT NULL default '',
103 comment_parent bigint(20) unsigned NOT NULL default '0',
104 user_id bigint(20) unsigned NOT NULL default '0',
105 PRIMARY KEY (comment_ID),
106 KEY comment_post_ID (comment_post_ID),
107 KEY comment_approved_date_gmt (comment_approved,comment_date_gmt),
108 KEY comment_date_gmt (comment_date_gmt),
109 KEY comment_parent (comment_parent)
111 CREATE TABLE $wpdb->links (
112 link_id bigint(20) unsigned NOT NULL auto_increment,
113 link_url varchar(255) NOT NULL default '',
114 link_name varchar(255) NOT NULL default '',
115 link_image varchar(255) NOT NULL default '',
116 link_target varchar(25) NOT NULL default '',
117 link_description varchar(255) NOT NULL default '',
118 link_visible varchar(20) NOT NULL default 'Y',
119 link_owner bigint(20) unsigned NOT NULL default '1',
120 link_rating int(11) NOT NULL default '0',
121 link_updated datetime NOT NULL default '0000-00-00 00:00:00',
122 link_rel varchar(255) NOT NULL default '',
123 link_notes mediumtext NOT NULL,
124 link_rss varchar(255) NOT NULL default '',
125 PRIMARY KEY (link_id),
126 KEY link_visible (link_visible)
128 CREATE TABLE $wpdb->options (
129 option_id bigint(20) unsigned NOT NULL auto_increment,
130 option_name varchar(64) NOT NULL default '',
131 option_value longtext NOT NULL,
132 autoload varchar(20) NOT NULL default 'yes',
133 PRIMARY KEY (option_id),
134 UNIQUE KEY option_name (option_name)
136 CREATE TABLE $wpdb->postmeta (
137 meta_id bigint(20) unsigned NOT NULL auto_increment,
138 post_id bigint(20) unsigned NOT NULL default '0',
139 meta_key varchar(255) default NULL,
141 PRIMARY KEY (meta_id),
142 KEY post_id (post_id),
143 KEY meta_key (meta_key)
145 CREATE TABLE $wpdb->posts (
146 ID bigint(20) unsigned NOT NULL auto_increment,
147 post_author bigint(20) unsigned NOT NULL default '0',
148 post_date datetime NOT NULL default '0000-00-00 00:00:00',
149 post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
150 post_content longtext NOT NULL,
151 post_title text NOT NULL,
152 post_excerpt text NOT NULL,
153 post_status varchar(20) NOT NULL default 'publish',
154 comment_status varchar(20) NOT NULL default 'open',
155 ping_status varchar(20) NOT NULL default 'open',
156 post_password varchar(20) NOT NULL default '',
157 post_name varchar(200) NOT NULL default '',
158 to_ping text NOT NULL,
159 pinged text NOT NULL,
160 post_modified datetime NOT NULL default '0000-00-00 00:00:00',
161 post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
162 post_content_filtered longtext NOT NULL,
163 post_parent bigint(20) unsigned NOT NULL default '0',
164 guid varchar(255) NOT NULL default '',
165 menu_order int(11) NOT NULL default '0',
166 post_type varchar(20) NOT NULL default 'post',
167 post_mime_type varchar(100) NOT NULL default '',
168 comment_count bigint(20) NOT NULL default '0',
170 KEY post_name (post_name),
171 KEY type_status_date (post_type,post_status,post_date,ID),
172 KEY post_parent (post_parent),
173 KEY post_author (post_author)
174 ) $charset_collate;\n";
176 // Single site users table. The multisite flavor of the users table is handled below.
177 $users_single_table = "CREATE TABLE $wpdb->users (
178 ID bigint(20) unsigned NOT NULL auto_increment,
179 user_login varchar(60) NOT NULL default '',
180 user_pass varchar(64) NOT NULL default '',
181 user_nicename varchar(50) NOT NULL default '',
182 user_email varchar(100) NOT NULL default '',
183 user_url varchar(100) NOT NULL default '',
184 user_registered datetime NOT NULL default '0000-00-00 00:00:00',
185 user_activation_key varchar(60) NOT NULL default '',
186 user_status int(11) NOT NULL default '0',
187 display_name varchar(250) NOT NULL default '',
189 KEY user_login_key (user_login),
190 KEY user_nicename (user_nicename)
191 ) $charset_collate;\n";
193 // Multisite users table
194 $users_multi_table = "CREATE TABLE $wpdb->users (
195 ID bigint(20) unsigned NOT NULL auto_increment,
196 user_login varchar(60) NOT NULL default '',
197 user_pass varchar(64) NOT NULL default '',
198 user_nicename varchar(50) NOT NULL default '',
199 user_email varchar(100) NOT NULL default '',
200 user_url varchar(100) NOT NULL default '',
201 user_registered datetime NOT NULL default '0000-00-00 00:00:00',
202 user_activation_key varchar(60) NOT NULL default '',
203 user_status int(11) NOT NULL default '0',
204 display_name varchar(250) NOT NULL default '',
205 spam tinyint(2) NOT NULL default '0',
206 deleted tinyint(2) NOT NULL default '0',
208 KEY user_login_key (user_login),
209 KEY user_nicename (user_nicename)
210 ) $charset_collate;\n";
213 $usermeta_table = "CREATE TABLE $wpdb->usermeta (
214 umeta_id bigint(20) unsigned NOT NULL auto_increment,
215 user_id bigint(20) unsigned NOT NULL default '0',
216 meta_key varchar(255) default NULL,
218 PRIMARY KEY (umeta_id),
219 KEY user_id (user_id),
220 KEY meta_key (meta_key)
221 ) $charset_collate;\n";
225 $global_tables = $users_multi_table . $usermeta_table;
227 $global_tables = $users_single_table . $usermeta_table;
229 // Multisite global tables.
230 $ms_global_tables = "CREATE TABLE $wpdb->blogs (
231 blog_id bigint(20) NOT NULL auto_increment,
232 site_id bigint(20) NOT NULL default '0',
233 domain varchar(200) NOT NULL default '',
234 path varchar(100) NOT NULL default '',
235 registered datetime NOT NULL default '0000-00-00 00:00:00',
236 last_updated datetime NOT NULL default '0000-00-00 00:00:00',
237 public tinyint(2) NOT NULL default '1',
238 archived enum('0','1') NOT NULL default '0',
239 mature tinyint(2) NOT NULL default '0',
240 spam tinyint(2) NOT NULL default '0',
241 deleted tinyint(2) NOT NULL default '0',
242 lang_id int(11) NOT NULL default '0',
243 PRIMARY KEY (blog_id),
244 KEY domain (domain(50),path(5)),
245 KEY lang_id (lang_id)
247 CREATE TABLE $wpdb->blog_versions (
248 blog_id bigint(20) NOT NULL default '0',
249 db_version varchar(20) NOT NULL default '',
250 last_updated datetime NOT NULL default '0000-00-00 00:00:00',
251 PRIMARY KEY (blog_id),
252 KEY db_version (db_version)
254 CREATE TABLE $wpdb->registration_log (
255 ID bigint(20) NOT NULL auto_increment,
256 email varchar(255) NOT NULL default '',
257 IP varchar(30) NOT NULL default '',
258 blog_id bigint(20) NOT NULL default '0',
259 date_registered datetime NOT NULL default '0000-00-00 00:00:00',
263 CREATE TABLE $wpdb->site (
264 id bigint(20) NOT NULL auto_increment,
265 domain varchar(200) NOT NULL default '',
266 path varchar(100) NOT NULL default '',
268 KEY domain (domain,path)
270 CREATE TABLE $wpdb->sitemeta (
271 meta_id bigint(20) NOT NULL auto_increment,
272 site_id bigint(20) NOT NULL default '0',
273 meta_key varchar(255) default NULL,
275 PRIMARY KEY (meta_id),
276 KEY meta_key (meta_key),
277 KEY site_id (site_id)
279 CREATE TABLE $wpdb->signups (
280 domain varchar(200) NOT NULL default '',
281 path varchar(100) NOT NULL default '',
282 title longtext NOT NULL,
283 user_login varchar(60) NOT NULL default '',
284 user_email varchar(100) NOT NULL default '',
285 registered datetime NOT NULL default '0000-00-00 00:00:00',
286 activated datetime NOT NULL default '0000-00-00 00:00:00',
287 active tinyint(1) NOT NULL default '0',
288 activation_key varchar(50) NOT NULL default '',
290 KEY activation_key (activation_key),
292 ) $charset_collate;";
296 $queries = $blog_tables;
299 $queries = $global_tables;
301 $queries .= $ms_global_tables;
304 $queries = $ms_global_tables;
308 $queries = $global_tables . $blog_tables;
310 $queries .= $ms_global_tables;
314 if ( isset( $old_blog_id ) )
315 $wpdb->set_blog_id( $old_blog_id );
320 // Populate for back compat.
321 $wp_queries = wp_get_db_schema( 'all' );
324 * Create WordPress options and set the default values.
328 * @uses $wp_db_version
330 function populate_options() {
331 global $wpdb, $wp_db_version, $current_site, $wp_current_db_version;
333 $guessurl = wp_guess_url();
335 do_action('populate_options');
337 if ( ini_get('safe_mode') ) {
338 // Safe mode can break mkdir() so use a flat structure by default.
339 $uploads_use_yearmonth_folders = 0;
341 $uploads_use_yearmonth_folders = 1;
344 $template = WP_DEFAULT_THEME;
345 // If default theme is a child theme, we need to get its template
346 $theme = wp_get_theme( $template );
347 if ( ! $theme->errors() )
348 $template = $theme->get_template();
350 $timezone_string = '';
352 /* translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14)
353 or a valid timezone string (America/New_York). See http://us3.php.net/manual/en/timezones.php
354 for all timezone strings supported by PHP.
356 $offset_or_tz = _x( '0', 'default GMT offset or timezone string' );
357 if ( is_numeric( $offset_or_tz ) )
358 $gmt_offset = $offset_or_tz;
359 elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list() ) )
360 $timezone_string = $offset_or_tz;
363 'siteurl' => $guessurl,
364 'blogname' => __('My Site'),
365 /* translators: blog tagline */
366 'blogdescription' => __('Just another WordPress site'),
367 'users_can_register' => 0,
368 'admin_email' => 'you@example.com',
369 /* translators: default start of the week. 0 = Sunday, 1 = Monday */
370 'start_of_week' => _x( '1', 'start of week' ),
371 'use_balanceTags' => 0,
373 'require_name_email' => 1,
374 'comments_notify' => 1,
375 'posts_per_rss' => 10,
376 'rss_use_excerpt' => 0,
377 'mailserver_url' => 'mail.example.com',
378 'mailserver_login' => 'login@example.com',
379 'mailserver_pass' => 'password',
380 'mailserver_port' => 110,
381 'default_category' => 1,
382 'default_comment_status' => 'open',
383 'default_ping_status' => 'open',
384 'default_pingback_flag' => 1,
385 'default_post_edit_rows' => 20,
386 'posts_per_page' => 10,
387 /* translators: default date format, see http://php.net/date */
388 'date_format' => __('F j, Y'),
389 /* translators: default time format, see http://php.net/date */
390 'time_format' => __('g:i a'),
391 /* translators: links last updated date format, see http://php.net/date */
392 'links_updated_date_format' => __('F j, Y g:i a'),
393 'links_recently_updated_prepend' => '<em>',
394 'links_recently_updated_append' => '</em>',
395 'links_recently_updated_time' => 120,
396 'comment_moderation' => 0,
397 'moderation_notify' => 1,
398 'permalink_structure' => '',
399 'gzipcompression' => 0,
401 'blog_charset' => 'UTF-8',
402 'moderation_keys' => '',
403 'active_plugins' => array(),
405 'category_base' => '',
406 'ping_sites' => 'http://rpc.pingomatic.com/',
407 'advanced_edit' => 0,
408 'comment_max_links' => 2,
409 'gmt_offset' => $gmt_offset,
412 'default_email_category' => 1,
413 'recently_edited' => '',
414 'template' => $template,
415 'stylesheet' => WP_DEFAULT_THEME,
416 'comment_whitelist' => 1,
417 'blacklist_keys' => '',
418 'comment_registration' => 0,
419 'html_type' => 'text/html',
422 'use_trackback' => 0,
425 'default_role' => 'subscriber',
426 'db_version' => $wp_db_version,
429 'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders,
433 'blog_public' => '1',
434 'default_link_category' => 2,
435 'show_on_front' => 'posts',
441 'show_avatars' => '1',
442 'avatar_rating' => 'G',
443 'upload_url_path' => '',
444 'thumbnail_size_w' => 150,
445 'thumbnail_size_h' => 150,
446 'thumbnail_crop' => 1,
447 'medium_size_w' => 300,
448 'medium_size_h' => 300,
451 'avatar_default' => 'mystery',
453 'enable_xmlrpc' => 0,
456 'large_size_w' => 1024,
457 'large_size_h' => 1024,
458 'image_default_link_type' => 'file',
459 'image_default_size' => '',
460 'image_default_align' => '',
461 'close_comments_for_old_posts' => 0,
462 'close_comments_days_old' => 14,
463 'thread_comments' => 1,
464 'thread_comments_depth' => 5,
465 'page_comments' => 0,
466 'comments_per_page' => 50,
467 'default_comments_page' => 'newest',
468 'comment_order' => 'asc',
469 'sticky_posts' => array(),
470 'widget_categories' => array(),
471 'widget_text' => array(),
472 'widget_rss' => array(),
473 'uninstall_plugins' => array(),
476 'timezone_string' => $timezone_string,
479 'embed_autourls' => 1,
480 'embed_size_w' => '',
481 'embed_size_h' => 600,
484 'page_for_posts' => 0,
485 'page_on_front' => 0,
488 'default_post_format' => 0,
492 if ( ! is_multisite() ) {
493 $options['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version
494 ? $wp_current_db_version : $wp_db_version;
498 if ( is_multisite() ) {
499 /* translators: blog tagline */
500 $options[ 'blogdescription' ] = sprintf(__('Just another %s site'), $current_site->site_name );
501 $options[ 'permalink_structure' ] = '/%year%/%monthnum%/%day%/%postname%/';
504 // Set autoload to no for these options
505 $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins' );
507 $existing_options = $wpdb->get_col("SELECT option_name FROM $wpdb->options");
510 foreach ( $options as $option => $value ) {
511 if ( in_array($option, $existing_options) )
513 if ( in_array($option, $fat_options) )
518 $option = $wpdb->escape($option);
519 if ( is_array($value) )
520 $value = serialize($value);
521 $value = $wpdb->escape($value);
522 if ( !empty($insert) )
524 $insert .= "('$option', '$value', '$autoload')";
527 if ( !empty($insert) )
528 $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert);
530 // in case it is set, but blank, update "home"
531 if ( !__get_option('home') ) update_option('home', $guessurl);
533 // Delete unused options
534 $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', 'can_compress_scripts', 'page_uris', 'update_core', 'update_plugins', 'update_themes', 'doing_cron', 'random_seed', 'rss_excerpt_length', 'secret', 'use_linksupdate', 'default_comment_status_page', 'wporg_popular_tags', 'what_to_show', 'rss_language');
535 foreach ( $unusedoptions as $option )
536 delete_option($option);
538 // delete obsolete magpie stuff
539 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'");
543 * Execute WordPress role creation for the various WordPress versions.
547 function populate_roles() {
548 populate_roles_160();
549 populate_roles_210();
550 populate_roles_230();
551 populate_roles_250();
552 populate_roles_260();
553 populate_roles_270();
554 populate_roles_280();
555 populate_roles_300();
559 * Create the roles for WordPress 2.0
563 function populate_roles_160() {
566 // Dummy gettext calls to get strings in the catalog.
567 /* translators: user role */
568 _x('Administrator', 'User role');
569 /* translators: user role */
570 _x('Editor', 'User role');
571 /* translators: user role */
572 _x('Author', 'User role');
573 /* translators: user role */
574 _x('Contributor', 'User role');
575 /* translators: user role */
576 _x('Subscriber', 'User role');
578 add_role('administrator', 'Administrator');
579 add_role('editor', 'Editor');
580 add_role('author', 'Author');
581 add_role('contributor', 'Contributor');
582 add_role('subscriber', 'Subscriber');
584 // Add caps for Administrator role
585 $role =& get_role('administrator');
586 $role->add_cap('switch_themes');
587 $role->add_cap('edit_themes');
588 $role->add_cap('activate_plugins');
589 $role->add_cap('edit_plugins');
590 $role->add_cap('edit_users');
591 $role->add_cap('edit_files');
592 $role->add_cap('manage_options');
593 $role->add_cap('moderate_comments');
594 $role->add_cap('manage_categories');
595 $role->add_cap('manage_links');
596 $role->add_cap('upload_files');
597 $role->add_cap('import');
598 $role->add_cap('unfiltered_html');
599 $role->add_cap('edit_posts');
600 $role->add_cap('edit_others_posts');
601 $role->add_cap('edit_published_posts');
602 $role->add_cap('publish_posts');
603 $role->add_cap('edit_pages');
604 $role->add_cap('read');
605 $role->add_cap('level_10');
606 $role->add_cap('level_9');
607 $role->add_cap('level_8');
608 $role->add_cap('level_7');
609 $role->add_cap('level_6');
610 $role->add_cap('level_5');
611 $role->add_cap('level_4');
612 $role->add_cap('level_3');
613 $role->add_cap('level_2');
614 $role->add_cap('level_1');
615 $role->add_cap('level_0');
617 // Add caps for Editor role
618 $role =& get_role('editor');
619 $role->add_cap('moderate_comments');
620 $role->add_cap('manage_categories');
621 $role->add_cap('manage_links');
622 $role->add_cap('upload_files');
623 $role->add_cap('unfiltered_html');
624 $role->add_cap('edit_posts');
625 $role->add_cap('edit_others_posts');
626 $role->add_cap('edit_published_posts');
627 $role->add_cap('publish_posts');
628 $role->add_cap('edit_pages');
629 $role->add_cap('read');
630 $role->add_cap('level_7');
631 $role->add_cap('level_6');
632 $role->add_cap('level_5');
633 $role->add_cap('level_4');
634 $role->add_cap('level_3');
635 $role->add_cap('level_2');
636 $role->add_cap('level_1');
637 $role->add_cap('level_0');
639 // Add caps for Author role
640 $role =& get_role('author');
641 $role->add_cap('upload_files');
642 $role->add_cap('edit_posts');
643 $role->add_cap('edit_published_posts');
644 $role->add_cap('publish_posts');
645 $role->add_cap('read');
646 $role->add_cap('level_2');
647 $role->add_cap('level_1');
648 $role->add_cap('level_0');
650 // Add caps for Contributor role
651 $role =& get_role('contributor');
652 $role->add_cap('edit_posts');
653 $role->add_cap('read');
654 $role->add_cap('level_1');
655 $role->add_cap('level_0');
657 // Add caps for Subscriber role
658 $role =& get_role('subscriber');
659 $role->add_cap('read');
660 $role->add_cap('level_0');
664 * Create and modify WordPress roles for WordPress 2.1.
668 function populate_roles_210() {
669 $roles = array('administrator', 'editor');
670 foreach ($roles as $role) {
671 $role =& get_role($role);
675 $role->add_cap('edit_others_pages');
676 $role->add_cap('edit_published_pages');
677 $role->add_cap('publish_pages');
678 $role->add_cap('delete_pages');
679 $role->add_cap('delete_others_pages');
680 $role->add_cap('delete_published_pages');
681 $role->add_cap('delete_posts');
682 $role->add_cap('delete_others_posts');
683 $role->add_cap('delete_published_posts');
684 $role->add_cap('delete_private_posts');
685 $role->add_cap('edit_private_posts');
686 $role->add_cap('read_private_posts');
687 $role->add_cap('delete_private_pages');
688 $role->add_cap('edit_private_pages');
689 $role->add_cap('read_private_pages');
692 $role =& get_role('administrator');
693 if ( ! empty($role) ) {
694 $role->add_cap('delete_users');
695 $role->add_cap('create_users');
698 $role =& get_role('author');
699 if ( ! empty($role) ) {
700 $role->add_cap('delete_posts');
701 $role->add_cap('delete_published_posts');
704 $role =& get_role('contributor');
705 if ( ! empty($role) ) {
706 $role->add_cap('delete_posts');
711 * Create and modify WordPress roles for WordPress 2.3.
715 function populate_roles_230() {
716 $role =& get_role( 'administrator' );
718 if ( !empty( $role ) ) {
719 $role->add_cap( 'unfiltered_upload' );
724 * Create and modify WordPress roles for WordPress 2.5.
728 function populate_roles_250() {
729 $role =& get_role( 'administrator' );
731 if ( !empty( $role ) ) {
732 $role->add_cap( 'edit_dashboard' );
737 * Create and modify WordPress roles for WordPress 2.6.
741 function populate_roles_260() {
742 $role =& get_role( 'administrator' );
744 if ( !empty( $role ) ) {
745 $role->add_cap( 'update_plugins' );
746 $role->add_cap( 'delete_plugins' );
751 * Create and modify WordPress roles for WordPress 2.7.
755 function populate_roles_270() {
756 $role =& get_role( 'administrator' );
758 if ( !empty( $role ) ) {
759 $role->add_cap( 'install_plugins' );
760 $role->add_cap( 'update_themes' );
765 * Create and modify WordPress roles for WordPress 2.8.
769 function populate_roles_280() {
770 $role =& get_role( 'administrator' );
772 if ( !empty( $role ) ) {
773 $role->add_cap( 'install_themes' );
778 * Create and modify WordPress roles for WordPress 3.0.
782 function populate_roles_300() {
783 $role =& get_role( 'administrator' );
785 if ( !empty( $role ) ) {
786 $role->add_cap( 'update_core' );
787 $role->add_cap( 'list_users' );
788 $role->add_cap( 'remove_users' );
789 $role->add_cap( 'add_users' );
790 $role->add_cap( 'promote_users' );
791 $role->add_cap( 'edit_theme_options' );
792 $role->add_cap( 'delete_themes' );
793 $role->add_cap( 'export' );
803 if ( !function_exists( 'install_network' ) ) :
804 function install_network() {
805 if ( ! defined( 'WP_INSTALLING_NETWORK' ) )
806 define( 'WP_INSTALLING_NETWORK', true );
808 dbDelta( wp_get_db_schema( 'global' ) );
813 * populate network settings
817 * @param int $network_id id of network to populate
818 * @return bool|WP_Error True on success, or WP_Error on warning (with the install otherwise successful,
819 * so the error code must be checked) or failure.
821 function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) {
822 global $wpdb, $current_site, $wp_db_version, $wp_rewrite;
824 $errors = new WP_Error();
826 $errors->add( 'empty_domain', __( 'You must provide a domain name.' ) );
827 if ( '' == $site_name )
828 $errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) );
830 // check for network collision
831 if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) )
832 $errors->add( 'siteid_exists', __( 'The network already exists.' ) );
834 $site_user = get_user_by( 'email', $email );
835 if ( ! is_email( $email ) )
836 $errors->add( 'invalid_email', __( 'You must provide a valid e-mail address.' ) );
838 if ( $errors->get_error_code() )
841 // set up site tables
842 $template = get_option( 'template' );
843 $stylesheet = get_option( 'stylesheet' );
844 $allowed_themes = array( $stylesheet => true );
845 if ( $template != $stylesheet )
846 $allowed_themes[ $template ] = true;
847 if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template )
848 $allowed_themes[ WP_DEFAULT_THEME ] = true;
850 if ( 1 == $network_id ) {
851 $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) );
852 $network_id = $wpdb->insert_id;
854 $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path, 'id' => $network_id ) );
857 if ( !is_multisite() ) {
858 $site_admins = array( $site_user->user_login );
859 $users = get_users( array( 'fields' => array( 'ID', 'user_login' ) ) );
861 foreach ( $users as $user ) {
862 if ( is_super_admin( $user->ID ) && !in_array( $user->user_login, $site_admins ) )
863 $site_admins[] = $user->user_login;
867 $site_admins = get_site_option( 'site_admins' );
870 $welcome_email = __( 'Dear User,
872 Your new SITE_NAME site has been successfully set up at:
875 You can log in to the administrator account with the following information:
878 Log in here: BLOG_URLwp-login.php
880 We hope you enjoy your new site. Thanks!
882 --The Team @ SITE_NAME' );
885 'site_name' => $site_name,
886 'admin_email' => $site_user->user_email,
887 'admin_user_id' => $site_user->ID,
888 'registration' => 'none',
889 'upload_filetypes' => 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf',
890 'blog_upload_space' => 100,
891 'fileupload_maxk' => 1500,
892 'site_admins' => $site_admins,
893 'allowedthemes' => $allowed_themes,
894 'illegal_names' => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ),
895 'wpmu_upgrade_site' => $wp_db_version,
896 'welcome_email' => $welcome_email,
897 'first_post' => __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ),
898 // @todo - network admins should have a method of editing the network siteurl (used for cookie hash)
899 'siteurl' => get_option( 'siteurl' ) . '/',
900 'add_new_users' => '0',
901 'upload_space_check_disabled' => '0',
902 'subdomain_install' => intval( $subdomain_install ),
903 'global_terms_enabled' => global_terms_enabled() ? '1' : '0',
904 'initial_db_version' => get_option( 'initial_db_version' ),
905 'active_sitewide_plugins' => array(),
907 if ( ! $subdomain_install )
908 $sitemeta['illegal_names'][] = 'blog';
911 foreach ( $sitemeta as $meta_key => $meta_value ) {
912 $meta_key = $wpdb->escape( $meta_key );
913 if ( is_array( $meta_value ) )
914 $meta_value = serialize( $meta_value );
915 $meta_value = $wpdb->escape( $meta_value );
916 if ( !empty( $insert ) )
918 $insert .= "( $network_id, '$meta_key', '$meta_value')";
920 $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert );
922 $current_site->domain = $domain;
923 $current_site->path = $path;
924 $current_site->site_name = ucfirst( $domain );
926 if ( !is_multisite() ) {
927 $wpdb->insert( $wpdb->blogs, array( 'site_id' => $network_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time( 'mysql' ) ) );
928 $blog_id = $wpdb->insert_id;
929 update_user_meta( $site_user->ID, 'source_domain', $domain );
930 update_user_meta( $site_user->ID, 'primary_blog', $blog_id );
931 if ( !$upload_path = get_option( 'upload_path' ) ) {
932 $upload_path = substr( WP_CONTENT_DIR, strlen( ABSPATH ) ) . '/uploads';
933 update_option( 'upload_path', $upload_path );
935 update_option( 'fileupload_url', get_option( 'siteurl' ) . '/' . $upload_path );
938 if ( $subdomain_install )
939 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
941 $wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' );
943 flush_rewrite_rules();
945 if ( $subdomain_install ) {
948 $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname!
949 $page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) );
950 if ( is_wp_error( $page ) )
951 $errstr = $page->get_error_message();
952 elseif ( 200 == wp_remote_retrieve_response_code( $page ) )
956 $msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
957 $msg .= '<p>' . sprintf( __( 'The installer attempted to contact a random hostname (<code>%1$s</code>) on your domain.' ), $hostname );
958 if ( ! empty ( $errstr ) )
959 $msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' );
961 $msg .= '<p>' . __( 'To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a <code>*</code> hostname record pointing at your web server in your DNS configuration tool.' ) . '</p>';
962 $msg .= '<p>' . __( 'You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.' ) . '</p>';
963 return new WP_Error( 'no_wildcard_dns', $msg );