changeset 194 | 32102edaa81b |
parent 136 | bde1974c263b |
child 204 | 09a1c134465b |
193:2f6f6f7551ca | 194:32102edaa81b |
---|---|
5 * Here we keep the DB structure and option values. |
5 * Here we keep the DB structure and option values. |
6 * |
6 * |
7 * @package WordPress |
7 * @package WordPress |
8 * @subpackage Administration |
8 * @subpackage Administration |
9 */ |
9 */ |
10 |
|
11 // Declare these as global in case schema.php is included from a function. |
|
12 global $wpdb, $wp_queries, $charset_collate; |
|
10 |
13 |
11 /** |
14 /** |
12 * The database character collate. |
15 * The database character collate. |
13 * @var string |
16 * @var string |
14 * @global string |
17 * @global string |
15 * @name $charset_collate |
18 * @name $charset_collate |
16 */ |
19 */ |
17 $charset_collate = ''; |
20 $charset_collate = ''; |
18 |
21 |
19 // Declare these as global in case schema.php is included from a function. |
22 if ( ! empty( $wpdb->charset ) ) |
20 global $wpdb, $wp_queries; |
|
21 |
|
22 if ( ! empty($wpdb->charset) ) |
|
23 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
23 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
24 if ( ! empty($wpdb->collate) ) |
24 if ( ! empty( $wpdb->collate ) ) |
25 $charset_collate .= " COLLATE $wpdb->collate"; |
25 $charset_collate .= " COLLATE $wpdb->collate"; |
26 |
26 |
27 /** Create WordPress database tables SQL */ |
27 /** |
28 $wp_queries = "CREATE TABLE $wpdb->terms ( |
28 * Retrieve the SQL for creating database tables. |
29 * |
|
30 * @since 3.3.0 |
|
31 * |
|
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. |
|
35 */ |
|
36 function wp_get_db_schema( $scope = 'all', $blog_id = null ) { |
|
37 global $wpdb; |
|
38 |
|
39 $charset_collate = ''; |
|
40 |
|
41 if ( ! empty($wpdb->charset) ) |
|
42 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
|
43 if ( ! empty($wpdb->collate) ) |
|
44 $charset_collate .= " COLLATE $wpdb->collate"; |
|
45 |
|
46 if ( $blog_id && $blog_id != $wpdb->blogid ) |
|
47 $old_blog_id = $wpdb->set_blog_id( $blog_id ); |
|
48 |
|
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 ); |
|
51 |
|
52 // Blog specific tables. |
|
53 $blog_tables = "CREATE TABLE $wpdb->terms ( |
|
29 term_id bigint(20) unsigned NOT NULL auto_increment, |
54 term_id bigint(20) unsigned NOT NULL auto_increment, |
30 name varchar(200) NOT NULL default '', |
55 name varchar(200) NOT NULL default '', |
31 slug varchar(200) NOT NULL default '', |
56 slug varchar(200) NOT NULL default '', |
32 term_group bigint(10) NOT NULL default 0, |
57 term_group bigint(10) NOT NULL default 0, |
33 PRIMARY KEY (term_id), |
58 PRIMARY KEY (term_id), |
76 comment_agent varchar(255) NOT NULL default '', |
101 comment_agent varchar(255) NOT NULL default '', |
77 comment_type varchar(20) NOT NULL default '', |
102 comment_type varchar(20) NOT NULL default '', |
78 comment_parent bigint(20) unsigned NOT NULL default '0', |
103 comment_parent bigint(20) unsigned NOT NULL default '0', |
79 user_id bigint(20) unsigned NOT NULL default '0', |
104 user_id bigint(20) unsigned NOT NULL default '0', |
80 PRIMARY KEY (comment_ID), |
105 PRIMARY KEY (comment_ID), |
81 KEY comment_approved (comment_approved), |
|
82 KEY comment_post_ID (comment_post_ID), |
106 KEY comment_post_ID (comment_post_ID), |
83 KEY comment_approved_date_gmt (comment_approved,comment_date_gmt), |
107 KEY comment_approved_date_gmt (comment_approved,comment_date_gmt), |
84 KEY comment_date_gmt (comment_date_gmt) |
108 KEY comment_date_gmt (comment_date_gmt), |
109 KEY comment_parent (comment_parent) |
|
85 ) $charset_collate; |
110 ) $charset_collate; |
86 CREATE TABLE $wpdb->links ( |
111 CREATE TABLE $wpdb->links ( |
87 link_id bigint(20) unsigned NOT NULL auto_increment, |
112 link_id bigint(20) unsigned NOT NULL auto_increment, |
88 link_url varchar(255) NOT NULL default '', |
113 link_url varchar(255) NOT NULL default '', |
89 link_name varchar(255) NOT NULL default '', |
114 link_name varchar(255) NOT NULL default '', |
100 PRIMARY KEY (link_id), |
125 PRIMARY KEY (link_id), |
101 KEY link_visible (link_visible) |
126 KEY link_visible (link_visible) |
102 ) $charset_collate; |
127 ) $charset_collate; |
103 CREATE TABLE $wpdb->options ( |
128 CREATE TABLE $wpdb->options ( |
104 option_id bigint(20) unsigned NOT NULL auto_increment, |
129 option_id bigint(20) unsigned NOT NULL auto_increment, |
105 blog_id int(11) NOT NULL default '0', |
|
106 option_name varchar(64) NOT NULL default '', |
130 option_name varchar(64) NOT NULL default '', |
107 option_value longtext NOT NULL, |
131 option_value longtext NOT NULL, |
108 autoload varchar(20) NOT NULL default 'yes', |
132 autoload varchar(20) NOT NULL default 'yes', |
109 PRIMARY KEY (option_id), |
133 PRIMARY KEY (option_id), |
110 UNIQUE KEY option_name (option_name) |
134 UNIQUE KEY option_name (option_name) |
133 post_name varchar(200) NOT NULL default '', |
157 post_name varchar(200) NOT NULL default '', |
134 to_ping text NOT NULL, |
158 to_ping text NOT NULL, |
135 pinged text NOT NULL, |
159 pinged text NOT NULL, |
136 post_modified datetime NOT NULL default '0000-00-00 00:00:00', |
160 post_modified datetime NOT NULL default '0000-00-00 00:00:00', |
137 post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00', |
161 post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00', |
138 post_content_filtered text NOT NULL, |
162 post_content_filtered longtext NOT NULL, |
139 post_parent bigint(20) unsigned NOT NULL default '0', |
163 post_parent bigint(20) unsigned NOT NULL default '0', |
140 guid varchar(255) NOT NULL default '', |
164 guid varchar(255) NOT NULL default '', |
141 menu_order int(11) NOT NULL default '0', |
165 menu_order int(11) NOT NULL default '0', |
142 post_type varchar(20) NOT NULL default 'post', |
166 post_type varchar(20) NOT NULL default 'post', |
143 post_mime_type varchar(100) NOT NULL default '', |
167 post_mime_type varchar(100) NOT NULL default '', |
144 comment_count bigint(20) NOT NULL default '0', |
168 comment_count bigint(20) NOT NULL default '0', |
145 PRIMARY KEY (ID), |
169 PRIMARY KEY (ID), |
146 KEY post_name (post_name), |
170 KEY post_name (post_name), |
147 KEY type_status_date (post_type,post_status,post_date,ID), |
171 KEY type_status_date (post_type,post_status,post_date,ID), |
148 KEY post_parent (post_parent) |
172 KEY post_parent (post_parent), |
149 ) $charset_collate; |
173 KEY post_author (post_author) |
150 CREATE TABLE $wpdb->users ( |
174 ) $charset_collate;\n"; |
175 |
|
176 // Single site users table. The multisite flavor of the users table is handled below. |
|
177 $users_single_table = "CREATE TABLE $wpdb->users ( |
|
151 ID bigint(20) unsigned NOT NULL auto_increment, |
178 ID bigint(20) unsigned NOT NULL auto_increment, |
152 user_login varchar(60) NOT NULL default '', |
179 user_login varchar(60) NOT NULL default '', |
153 user_pass varchar(64) NOT NULL default '', |
180 user_pass varchar(64) NOT NULL default '', |
154 user_nicename varchar(50) NOT NULL default '', |
181 user_nicename varchar(50) NOT NULL default '', |
155 user_email varchar(100) NOT NULL default '', |
182 user_email varchar(100) NOT NULL default '', |
159 user_status int(11) NOT NULL default '0', |
186 user_status int(11) NOT NULL default '0', |
160 display_name varchar(250) NOT NULL default '', |
187 display_name varchar(250) NOT NULL default '', |
161 PRIMARY KEY (ID), |
188 PRIMARY KEY (ID), |
162 KEY user_login_key (user_login), |
189 KEY user_login_key (user_login), |
163 KEY user_nicename (user_nicename) |
190 KEY user_nicename (user_nicename) |
164 ) $charset_collate; |
191 ) $charset_collate;\n"; |
165 CREATE TABLE $wpdb->usermeta ( |
192 |
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', |
|
207 PRIMARY KEY (ID), |
|
208 KEY user_login_key (user_login), |
|
209 KEY user_nicename (user_nicename) |
|
210 ) $charset_collate;\n"; |
|
211 |
|
212 // usermeta |
|
213 $usermeta_table = "CREATE TABLE $wpdb->usermeta ( |
|
166 umeta_id bigint(20) unsigned NOT NULL auto_increment, |
214 umeta_id bigint(20) unsigned NOT NULL auto_increment, |
167 user_id bigint(20) unsigned NOT NULL default '0', |
215 user_id bigint(20) unsigned NOT NULL default '0', |
168 meta_key varchar(255) default NULL, |
216 meta_key varchar(255) default NULL, |
169 meta_value longtext, |
217 meta_value longtext, |
170 PRIMARY KEY (umeta_id), |
218 PRIMARY KEY (umeta_id), |
171 KEY user_id (user_id), |
219 KEY user_id (user_id), |
172 KEY meta_key (meta_key) |
220 KEY meta_key (meta_key) |
221 ) $charset_collate;\n"; |
|
222 |
|
223 // Global tables |
|
224 if ( $is_multisite ) |
|
225 $global_tables = $users_multi_table . $usermeta_table; |
|
226 else |
|
227 $global_tables = $users_single_table . $usermeta_table; |
|
228 |
|
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) |
|
246 ) $charset_collate; |
|
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) |
|
253 ) $charset_collate; |
|
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', |
|
260 PRIMARY KEY (ID), |
|
261 KEY IP (IP) |
|
262 ) $charset_collate; |
|
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 '', |
|
267 PRIMARY KEY (id), |
|
268 KEY domain (domain,path) |
|
269 ) $charset_collate; |
|
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, |
|
274 meta_value longtext, |
|
275 PRIMARY KEY (meta_id), |
|
276 KEY meta_key (meta_key), |
|
277 KEY site_id (site_id) |
|
278 ) $charset_collate; |
|
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 '', |
|
289 meta longtext, |
|
290 KEY activation_key (activation_key), |
|
291 KEY domain (domain) |
|
173 ) $charset_collate;"; |
292 ) $charset_collate;"; |
293 |
|
294 switch ( $scope ) { |
|
295 case 'blog' : |
|
296 $queries = $blog_tables; |
|
297 break; |
|
298 case 'global' : |
|
299 $queries = $global_tables; |
|
300 if ( $is_multisite ) |
|
301 $queries .= $ms_global_tables; |
|
302 break; |
|
303 case 'ms_global' : |
|
304 $queries = $ms_global_tables; |
|
305 break; |
|
306 default: |
|
307 case 'all' : |
|
308 $queries = $global_tables . $blog_tables; |
|
309 if ( $is_multisite ) |
|
310 $queries .= $ms_global_tables; |
|
311 break; |
|
312 } |
|
313 |
|
314 if ( isset( $old_blog_id ) ) |
|
315 $wpdb->set_blog_id( $old_blog_id ); |
|
316 |
|
317 return $queries; |
|
318 } |
|
319 |
|
320 // Populate for back compat. |
|
321 $wp_queries = wp_get_db_schema( 'all' ); |
|
174 |
322 |
175 /** |
323 /** |
176 * Create WordPress options and set the default values. |
324 * Create WordPress options and set the default values. |
177 * |
325 * |
178 * @since 1.5.0 |
326 * @since 1.5.0 |
179 * @uses $wpdb |
327 * @uses $wpdb |
180 * @uses $wp_db_version |
328 * @uses $wp_db_version |
181 */ |
329 */ |
182 function populate_options() { |
330 function populate_options() { |
183 global $wpdb, $wp_db_version; |
331 global $wpdb, $wp_db_version, $current_site, $wp_current_db_version; |
184 |
332 |
185 $guessurl = wp_guess_url(); |
333 $guessurl = wp_guess_url(); |
186 |
334 |
187 do_action('populate_options'); |
335 do_action('populate_options'); |
188 |
336 |
191 $uploads_use_yearmonth_folders = 0; |
339 $uploads_use_yearmonth_folders = 0; |
192 } else { |
340 } else { |
193 $uploads_use_yearmonth_folders = 1; |
341 $uploads_use_yearmonth_folders = 1; |
194 } |
342 } |
195 |
343 |
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(); |
|
349 |
|
350 $timezone_string = ''; |
|
351 $gmt_offset = 0; |
|
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. |
|
355 */ |
|
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; |
|
361 |
|
196 $options = array( |
362 $options = array( |
197 'siteurl' => $guessurl, |
363 'siteurl' => $guessurl, |
198 'blogname' => __('My Blog'), |
364 'blogname' => __('My Site'), |
199 'blogdescription' => __('Just another WordPress weblog'), |
365 /* translators: blog tagline */ |
366 'blogdescription' => __('Just another WordPress site'), |
|
200 'users_can_register' => 0, |
367 'users_can_register' => 0, |
201 'admin_email' => 'you@example.com', |
368 'admin_email' => 'you@example.com', |
202 'start_of_week' => 1, |
369 /* translators: default start of the week. 0 = Sunday, 1 = Monday */ |
370 'start_of_week' => _x( '1', 'start of week' ), |
|
203 'use_balanceTags' => 0, |
371 'use_balanceTags' => 0, |
204 'use_smilies' => 1, |
372 'use_smilies' => 1, |
205 'require_name_email' => 1, |
373 'require_name_email' => 1, |
206 'comments_notify' => 1, |
374 'comments_notify' => 1, |
207 'posts_per_rss' => 10, |
375 'posts_per_rss' => 10, |
212 'mailserver_port' => 110, |
380 'mailserver_port' => 110, |
213 'default_category' => 1, |
381 'default_category' => 1, |
214 'default_comment_status' => 'open', |
382 'default_comment_status' => 'open', |
215 'default_ping_status' => 'open', |
383 'default_ping_status' => 'open', |
216 'default_pingback_flag' => 1, |
384 'default_pingback_flag' => 1, |
217 'default_post_edit_rows' => 10, |
385 'default_post_edit_rows' => 20, |
218 'posts_per_page' => 10, |
386 'posts_per_page' => 10, |
219 /* translators: default date format, see http://php.net/date */ |
387 /* translators: default date format, see http://php.net/date */ |
220 'date_format' => __('F j, Y'), |
388 'date_format' => __('F j, Y'), |
221 /* translators: default time format, see http://php.net/date */ |
389 /* translators: default time format, see http://php.net/date */ |
222 'time_format' => __('g:i a'), |
390 'time_format' => __('g:i a'), |
236 'home' => $guessurl, |
404 'home' => $guessurl, |
237 'category_base' => '', |
405 'category_base' => '', |
238 'ping_sites' => 'http://rpc.pingomatic.com/', |
406 'ping_sites' => 'http://rpc.pingomatic.com/', |
239 'advanced_edit' => 0, |
407 'advanced_edit' => 0, |
240 'comment_max_links' => 2, |
408 'comment_max_links' => 2, |
241 'gmt_offset' => date('Z') / 3600, |
409 'gmt_offset' => $gmt_offset, |
242 |
410 |
243 // 1.5 |
411 // 1.5 |
244 'default_email_category' => 1, |
412 'default_email_category' => 1, |
245 'recently_edited' => '', |
413 'recently_edited' => '', |
246 'use_linksupdate' => 0, |
414 'template' => $template, |
247 'template' => 'default', |
415 'stylesheet' => WP_DEFAULT_THEME, |
248 'stylesheet' => 'default', |
|
249 'comment_whitelist' => 1, |
416 'comment_whitelist' => 1, |
250 'blacklist_keys' => '', |
417 'blacklist_keys' => '', |
251 'comment_registration' => 0, |
418 'comment_registration' => 0, |
252 'rss_language' => 'en', |
|
253 'html_type' => 'text/html', |
419 'html_type' => 'text/html', |
254 |
420 |
255 // 1.5.1 |
421 // 1.5.1 |
256 'use_trackback' => 0, |
422 'use_trackback' => 0, |
257 |
423 |
260 'db_version' => $wp_db_version, |
426 'db_version' => $wp_db_version, |
261 |
427 |
262 // 2.0.1 |
428 // 2.0.1 |
263 'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders, |
429 'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders, |
264 'upload_path' => '', |
430 'upload_path' => '', |
265 |
|
266 // 2.0.3 |
|
267 'secret' => wp_generate_password(64), |
|
268 |
431 |
269 // 2.1 |
432 // 2.1 |
270 'blog_public' => '1', |
433 'blog_public' => '1', |
271 'default_link_category' => 2, |
434 'default_link_category' => 2, |
272 'show_on_front' => 'posts', |
435 'show_on_front' => 'posts', |
295 'image_default_link_type' => 'file', |
458 'image_default_link_type' => 'file', |
296 'image_default_size' => '', |
459 'image_default_size' => '', |
297 'image_default_align' => '', |
460 'image_default_align' => '', |
298 'close_comments_for_old_posts' => 0, |
461 'close_comments_for_old_posts' => 0, |
299 'close_comments_days_old' => 14, |
462 'close_comments_days_old' => 14, |
300 'thread_comments' => 0, |
463 'thread_comments' => 1, |
301 'thread_comments_depth' => 5, |
464 'thread_comments_depth' => 5, |
302 'page_comments' => 1, |
465 'page_comments' => 0, |
303 'comments_per_page' => 50, |
466 'comments_per_page' => 50, |
304 'default_comments_page' => 'newest', |
467 'default_comments_page' => 'newest', |
305 'comment_order' => 'asc', |
468 'comment_order' => 'asc', |
306 'sticky_posts' => array(), |
469 'sticky_posts' => array(), |
307 'widget_categories' => array(), |
470 'widget_categories' => array(), |
308 'widget_text' => array(), |
471 'widget_text' => array(), |
309 'widget_rss' => array(), |
472 'widget_rss' => array(), |
473 'uninstall_plugins' => array(), |
|
310 |
474 |
311 // 2.8 |
475 // 2.8 |
312 'timezone_string' => '', |
476 'timezone_string' => $timezone_string, |
313 |
477 |
314 // 2.9 |
478 // 2.9 |
315 'embed_autourls' => 1, |
479 'embed_autourls' => 1, |
316 'embed_size_w' => '', |
480 'embed_size_w' => '', |
317 'embed_size_h' => 600, |
481 'embed_size_h' => 600, |
482 |
|
483 // 3.0 |
|
484 'page_for_posts' => 0, |
|
485 'page_on_front' => 0, |
|
486 |
|
487 // 3.1 |
|
488 'default_post_format' => 0, |
|
318 ); |
489 ); |
319 |
490 |
491 // 3.3 |
|
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; |
|
495 } |
|
496 |
|
497 // 3.0 multisite |
|
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%/'; |
|
502 } |
|
503 |
|
320 // Set autoload to no for these options |
504 // Set autoload to no for these options |
321 $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' ); |
505 $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins' ); |
322 |
506 |
323 $existing_options = $wpdb->get_col("SELECT option_name FROM $wpdb->options"); |
507 $existing_options = $wpdb->get_col("SELECT option_name FROM $wpdb->options"); |
324 |
508 |
325 $insert = ''; |
509 $insert = ''; |
326 foreach ( $options as $option => $value ) { |
510 foreach ( $options as $option => $value ) { |
345 |
529 |
346 // in case it is set, but blank, update "home" |
530 // in case it is set, but blank, update "home" |
347 if ( !__get_option('home') ) update_option('home', $guessurl); |
531 if ( !__get_option('home') ) update_option('home', $guessurl); |
348 |
532 |
349 // Delete unused options |
533 // Delete unused options |
350 $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', |
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'); |
351 'page_uris', 'update_core', 'update_plugins', 'update_themes', 'doing_cron', 'random_seed', 'rss_excerpt_length'); |
535 foreach ( $unusedoptions as $option ) |
352 foreach ($unusedoptions as $option) |
|
353 delete_option($option); |
536 delete_option($option); |
354 |
537 |
355 // delete obsolete magpie stuff |
538 // delete obsolete magpie stuff |
356 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'"); |
539 $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'"); |
357 } |
540 } |
358 |
541 |
359 /** |
542 /** |
367 populate_roles_230(); |
550 populate_roles_230(); |
368 populate_roles_250(); |
551 populate_roles_250(); |
369 populate_roles_260(); |
552 populate_roles_260(); |
370 populate_roles_270(); |
553 populate_roles_270(); |
371 populate_roles_280(); |
554 populate_roles_280(); |
555 populate_roles_300(); |
|
372 } |
556 } |
373 |
557 |
374 /** |
558 /** |
375 * Create the roles for WordPress 2.0 |
559 * Create the roles for WordPress 2.0 |
376 * |
560 * |
588 if ( !empty( $role ) ) { |
772 if ( !empty( $role ) ) { |
589 $role->add_cap( 'install_themes' ); |
773 $role->add_cap( 'install_themes' ); |
590 } |
774 } |
591 } |
775 } |
592 |
776 |
593 ?> |
777 /** |
778 * Create and modify WordPress roles for WordPress 3.0. |
|
779 * |
|
780 * @since 3.0.0 |
|
781 */ |
|
782 function populate_roles_300() { |
|
783 $role =& get_role( 'administrator' ); |
|
784 |
|
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' ); |
|
794 } |
|
795 } |
|
796 |
|
797 /** |
|
798 * Install Network. |
|
799 * |
|
800 * @since 3.0.0 |
|
801 * |
|
802 */ |
|
803 if ( !function_exists( 'install_network' ) ) : |
|
804 function install_network() { |
|
805 if ( ! defined( 'WP_INSTALLING_NETWORK' ) ) |
|
806 define( 'WP_INSTALLING_NETWORK', true ); |
|
807 |
|
808 dbDelta( wp_get_db_schema( 'global' ) ); |
|
809 } |
|
810 endif; |
|
811 |
|
812 /** |
|
813 * populate network settings |
|
814 * |
|
815 * @since 3.0.0 |
|
816 * |
|
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. |
|
820 */ |
|
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; |
|
823 |
|
824 $errors = new WP_Error(); |
|
825 if ( '' == $domain ) |
|
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.' ) ); |
|
829 |
|
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.' ) ); |
|
833 |
|
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.' ) ); |
|
837 |
|
838 if ( $errors->get_error_code() ) |
|
839 return $errors; |
|
840 |
|
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; |
|
849 |
|
850 if ( 1 == $network_id ) { |
|
851 $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) ); |
|
852 $network_id = $wpdb->insert_id; |
|
853 } else { |
|
854 $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path, 'id' => $network_id ) ); |
|
855 } |
|
856 |
|
857 if ( !is_multisite() ) { |
|
858 $site_admins = array( $site_user->user_login ); |
|
859 $users = get_users( array( 'fields' => array( 'ID', 'user_login' ) ) ); |
|
860 if ( $users ) { |
|
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; |
|
864 } |
|
865 } |
|
866 } else { |
|
867 $site_admins = get_site_option( 'site_admins' ); |
|
868 } |
|
869 |
|
870 $welcome_email = __( 'Dear User, |
|
871 |
|
872 Your new SITE_NAME site has been successfully set up at: |
|
873 BLOG_URL |
|
874 |
|
875 You can log in to the administrator account with the following information: |
|
876 Username: USERNAME |
|
877 Password: PASSWORD |
|
878 Log in here: BLOG_URLwp-login.php |
|
879 |
|
880 We hope you enjoy your new site. Thanks! |
|
881 |
|
882 --The Team @ SITE_NAME' ); |
|
883 |
|
884 $sitemeta = array( |
|
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(), |
|
906 ); |
|
907 if ( ! $subdomain_install ) |
|
908 $sitemeta['illegal_names'][] = 'blog'; |
|
909 |
|
910 $insert = ''; |
|
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 ) ) |
|
917 $insert .= ', '; |
|
918 $insert .= "( $network_id, '$meta_key', '$meta_value')"; |
|
919 } |
|
920 $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); |
|
921 |
|
922 $current_site->domain = $domain; |
|
923 $current_site->path = $path; |
|
924 $current_site->site_name = ucfirst( $domain ); |
|
925 |
|
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 ); |
|
934 } |
|
935 update_option( 'fileupload_url', get_option( 'siteurl' ) . '/' . $upload_path ); |
|
936 } |
|
937 |
|
938 if ( $subdomain_install ) |
|
939 $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
|
940 else |
|
941 $wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' ); |
|
942 |
|
943 flush_rewrite_rules(); |
|
944 |
|
945 if ( $subdomain_install ) { |
|
946 $vhost_ok = false; |
|
947 $errstr = ''; |
|
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 ) ) |
|
953 $vhost_ok = true; |
|
954 |
|
955 if ( ! $vhost_ok ) { |
|
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>' ); |
|
960 $msg .= '</p>'; |
|
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 ); |
|
964 } |
|
965 } |
|
966 |
|
967 return true; |
|
968 } |