1 | <?php |
---|
2 | /** |
---|
3 | * WordPress Administration Scheme API |
---|
4 | * |
---|
5 | * Here we keep the DB structure and option values. |
---|
6 | * |
---|
7 | * @package WordPress |
---|
8 | * @subpackage Administration |
---|
9 | */ |
---|
10 | |
---|
11 | // Declare these as global in case schema.php is included from a function. |
---|
12 | global $wpdb, $wp_queries, $charset_collate; |
---|
13 | |
---|
14 | /** |
---|
15 | * The database character collate. |
---|
16 | * @var string |
---|
17 | * @global string |
---|
18 | * @name $charset_collate |
---|
19 | */ |
---|
20 | $charset_collate = ''; |
---|
21 | |
---|
22 | if ( ! empty( $wpdb->charset ) ) |
---|
23 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
24 | if ( ! empty( $wpdb->collate ) ) |
---|
25 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
26 | |
---|
27 | /** |
---|
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 ( |
---|
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 | menu_order int(11) NOT NULL default '0', |
---|
59 | PRIMARY KEY (term_id), |
---|
60 | UNIQUE KEY slug (slug), |
---|
61 | KEY name (name) |
---|
62 | ) $charset_collate; |
---|
63 | CREATE TABLE $wpdb->term_taxonomy ( |
---|
64 | term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment, |
---|
65 | term_id bigint(20) unsigned NOT NULL default 0, |
---|
66 | taxonomy varchar(32) NOT NULL default '', |
---|
67 | description longtext NOT NULL, |
---|
68 | parent bigint(20) unsigned NOT NULL default 0, |
---|
69 | count bigint(20) NOT NULL default 0, |
---|
70 | PRIMARY KEY (term_taxonomy_id), |
---|
71 | UNIQUE KEY term_id_taxonomy (term_id,taxonomy), |
---|
72 | KEY taxonomy (taxonomy) |
---|
73 | ) $charset_collate; |
---|
74 | CREATE TABLE $wpdb->term_relationships ( |
---|
75 | object_id bigint(20) unsigned NOT NULL default 0, |
---|
76 | term_taxonomy_id bigint(20) unsigned NOT NULL default 0, |
---|
77 | term_order int(11) NOT NULL default 0, |
---|
78 | PRIMARY KEY (object_id,term_taxonomy_id), |
---|
79 | KEY term_taxonomy_id (term_taxonomy_id) |
---|
80 | ) $charset_collate; |
---|
81 | CREATE TABLE $wpdb->commentmeta ( |
---|
82 | meta_id bigint(20) unsigned NOT NULL auto_increment, |
---|
83 | comment_id bigint(20) unsigned NOT NULL default '0', |
---|
84 | meta_key varchar(255) default NULL, |
---|
85 | meta_value longtext, |
---|
86 | PRIMARY KEY (meta_id), |
---|
87 | KEY comment_id (comment_id), |
---|
88 | KEY meta_key (meta_key) |
---|
89 | ) $charset_collate; |
---|
90 | CREATE TABLE $wpdb->comments ( |
---|
91 | comment_ID bigint(20) unsigned NOT NULL auto_increment, |
---|
92 | comment_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
93 | comment_author tinytext NOT NULL, |
---|
94 | comment_author_email varchar(100) NOT NULL default '', |
---|
95 | comment_author_url varchar(200) NOT NULL default '', |
---|
96 | comment_author_IP varchar(100) NOT NULL default '', |
---|
97 | comment_date datetime NOT NULL default '0000-00-00 00:00:00', |
---|
98 | comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00', |
---|
99 | comment_content text NOT NULL, |
---|
100 | comment_karma int(11) NOT NULL default '0', |
---|
101 | comment_approved varchar(20) NOT NULL default '1', |
---|
102 | comment_agent varchar(255) NOT NULL default '', |
---|
103 | comment_type varchar(20) NOT NULL default '', |
---|
104 | comment_parent bigint(20) unsigned NOT NULL default '0', |
---|
105 | user_id bigint(20) unsigned NOT NULL default '0', |
---|
106 | PRIMARY KEY (comment_ID), |
---|
107 | KEY comment_approved (comment_approved), |
---|
108 | KEY comment_post_ID (comment_post_ID), |
---|
109 | KEY comment_approved_date_gmt (comment_approved,comment_date_gmt), |
---|
110 | KEY comment_date_gmt (comment_date_gmt), |
---|
111 | KEY comment_parent (comment_parent) |
---|
112 | ) $charset_collate; |
---|
113 | CREATE TABLE $wpdb->links ( |
---|
114 | link_id bigint(20) unsigned NOT NULL auto_increment, |
---|
115 | link_url varchar(255) NOT NULL default '', |
---|
116 | link_name varchar(255) NOT NULL default '', |
---|
117 | link_image varchar(255) NOT NULL default '', |
---|
118 | link_target varchar(25) NOT NULL default '', |
---|
119 | link_description varchar(255) NOT NULL default '', |
---|
120 | link_visible varchar(20) NOT NULL default 'Y', |
---|
121 | link_owner bigint(20) unsigned NOT NULL default '1', |
---|
122 | link_rating int(11) NOT NULL default '0', |
---|
123 | link_updated datetime NOT NULL default '0000-00-00 00:00:00', |
---|
124 | link_rel varchar(255) NOT NULL default '', |
---|
125 | link_notes mediumtext NOT NULL, |
---|
126 | link_rss varchar(255) NOT NULL default '', |
---|
127 | PRIMARY KEY (link_id), |
---|
128 | KEY link_visible (link_visible) |
---|
129 | ) $charset_collate; |
---|
130 | CREATE TABLE $wpdb->options ( |
---|
131 | option_id bigint(20) unsigned NOT NULL auto_increment, |
---|
132 | blog_id int(11) NOT NULL default '0', |
---|
133 | option_name varchar(64) NOT NULL default '', |
---|
134 | option_value longtext NOT NULL, |
---|
135 | autoload varchar(20) NOT NULL default 'yes', |
---|
136 | PRIMARY KEY (option_id), |
---|
137 | UNIQUE KEY option_name (option_name) |
---|
138 | ) $charset_collate; |
---|
139 | CREATE TABLE $wpdb->postmeta ( |
---|
140 | meta_id bigint(20) unsigned NOT NULL auto_increment, |
---|
141 | post_id bigint(20) unsigned NOT NULL default '0', |
---|
142 | meta_key varchar(255) default NULL, |
---|
143 | meta_value longtext, |
---|
144 | PRIMARY KEY (meta_id), |
---|
145 | KEY post_id (post_id), |
---|
146 | KEY meta_key (meta_key) |
---|
147 | ) $charset_collate; |
---|
148 | CREATE TABLE $wpdb->posts ( |
---|
149 | ID bigint(20) unsigned NOT NULL auto_increment, |
---|
150 | post_author bigint(20) unsigned NOT NULL default '0', |
---|
151 | post_date datetime NOT NULL default '0000-00-00 00:00:00', |
---|
152 | post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00', |
---|
153 | post_content longtext NOT NULL, |
---|
154 | post_title text NOT NULL, |
---|
155 | post_excerpt text NOT NULL, |
---|
156 | post_status varchar(20) NOT NULL default 'publish', |
---|
157 | comment_status varchar(20) NOT NULL default 'open', |
---|
158 | ping_status varchar(20) NOT NULL default 'open', |
---|
159 | post_password varchar(20) NOT NULL default '', |
---|
160 | post_name varchar(200) NOT NULL default '', |
---|
161 | to_ping text NOT NULL, |
---|
162 | pinged text NOT NULL, |
---|
163 | post_modified datetime NOT NULL default '0000-00-00 00:00:00', |
---|
164 | post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00', |
---|
165 | post_content_filtered text NOT NULL, |
---|
166 | post_parent bigint(20) unsigned NOT NULL default '0', |
---|
167 | guid varchar(255) NOT NULL default '', |
---|
168 | menu_order int(11) NOT NULL default '0', |
---|
169 | post_type varchar(20) NOT NULL default 'post', |
---|
170 | post_mime_type varchar(100) NOT NULL default '', |
---|
171 | comment_count bigint(20) NOT NULL default '0', |
---|
172 | PRIMARY KEY (ID), |
---|
173 | KEY post_name (post_name), |
---|
174 | KEY type_status_date (post_type,post_status,post_date,ID), |
---|
175 | KEY post_parent (post_parent), |
---|
176 | KEY post_author (post_author) |
---|
177 | ) $charset_collate;\n"; |
---|
178 | |
---|
179 | // Single site users table. The multisite flavor of the users table is handled below. |
---|
180 | $users_single_table = "CREATE TABLE $wpdb->users ( |
---|
181 | ID bigint(20) unsigned NOT NULL auto_increment, |
---|
182 | user_login varchar(60) NOT NULL default '', |
---|
183 | user_pass varchar(64) NOT NULL default '', |
---|
184 | user_nicename varchar(50) NOT NULL default '', |
---|
185 | user_email varchar(100) NOT NULL default '', |
---|
186 | user_url varchar(100) NOT NULL default '', |
---|
187 | user_registered datetime NOT NULL default '0000-00-00 00:00:00', |
---|
188 | user_activation_key varchar(60) NOT NULL default '', |
---|
189 | user_status int(11) NOT NULL default '0', |
---|
190 | display_name varchar(250) NOT NULL default '', |
---|
191 | PRIMARY KEY (ID), |
---|
192 | KEY user_login_key (user_login), |
---|
193 | KEY user_nicename (user_nicename) |
---|
194 | ) $charset_collate;\n"; |
---|
195 | |
---|
196 | // Multisite users table |
---|
197 | $users_multi_table = "CREATE TABLE $wpdb->users ( |
---|
198 | ID bigint(20) unsigned NOT NULL auto_increment, |
---|
199 | user_login varchar(60) NOT NULL default '', |
---|
200 | user_pass varchar(64) NOT NULL default '', |
---|
201 | user_nicename varchar(50) NOT NULL default '', |
---|
202 | user_email varchar(100) NOT NULL default '', |
---|
203 | user_url varchar(100) NOT NULL default '', |
---|
204 | user_registered datetime NOT NULL default '0000-00-00 00:00:00', |
---|
205 | user_activation_key varchar(60) NOT NULL default '', |
---|
206 | user_status int(11) NOT NULL default '0', |
---|
207 | display_name varchar(250) NOT NULL default '', |
---|
208 | spam tinyint(2) NOT NULL default '0', |
---|
209 | deleted tinyint(2) NOT NULL default '0', |
---|
210 | PRIMARY KEY (ID), |
---|
211 | KEY user_login_key (user_login), |
---|
212 | KEY user_nicename (user_nicename) |
---|
213 | ) $charset_collate;\n"; |
---|
214 | |
---|
215 | // usermeta |
---|
216 | $usermeta_table = "CREATE TABLE $wpdb->usermeta ( |
---|
217 | umeta_id bigint(20) unsigned NOT NULL auto_increment, |
---|
218 | user_id bigint(20) unsigned NOT NULL default '0', |
---|
219 | meta_key varchar(255) default NULL, |
---|
220 | meta_value longtext, |
---|
221 | PRIMARY KEY (umeta_id), |
---|
222 | KEY user_id (user_id), |
---|
223 | KEY meta_key (meta_key) |
---|
224 | ) $charset_collate;\n"; |
---|
225 | |
---|
226 | // Global tables |
---|
227 | if ( $is_multisite ) |
---|
228 | $global_tables = $users_multi_table . $usermeta_table; |
---|
229 | else |
---|
230 | $global_tables = $users_single_table . $usermeta_table; |
---|
231 | |
---|
232 | // Multisite global tables. |
---|
233 | $ms_global_tables = "CREATE TABLE $wpdb->blogs ( |
---|
234 | blog_id bigint(20) NOT NULL auto_increment, |
---|
235 | site_id bigint(20) NOT NULL default '0', |
---|
236 | domain varchar(200) NOT NULL default '', |
---|
237 | path varchar(100) NOT NULL default '', |
---|
238 | registered datetime NOT NULL default '0000-00-00 00:00:00', |
---|
239 | last_updated datetime NOT NULL default '0000-00-00 00:00:00', |
---|
240 | public tinyint(2) NOT NULL default '1', |
---|
241 | archived enum('0','1') NOT NULL default '0', |
---|
242 | mature tinyint(2) NOT NULL default '0', |
---|
243 | spam tinyint(2) NOT NULL default '0', |
---|
244 | deleted tinyint(2) NOT NULL default '0', |
---|
245 | lang_id int(11) NOT NULL default '0', |
---|
246 | PRIMARY KEY (blog_id), |
---|
247 | KEY domain (domain(50),path(5)), |
---|
248 | KEY lang_id (lang_id) |
---|
249 | ) $charset_collate; |
---|
250 | CREATE TABLE $wpdb->blog_versions ( |
---|
251 | blog_id bigint(20) NOT NULL default '0', |
---|
252 | db_version varchar(20) NOT NULL default '', |
---|
253 | last_updated datetime NOT NULL default '0000-00-00 00:00:00', |
---|
254 | PRIMARY KEY (blog_id), |
---|
255 | KEY db_version (db_version) |
---|
256 | ) $charset_collate; |
---|
257 | CREATE TABLE $wpdb->registration_log ( |
---|
258 | ID bigint(20) NOT NULL auto_increment, |
---|
259 | email varchar(255) NOT NULL default '', |
---|
260 | IP varchar(30) NOT NULL default '', |
---|
261 | blog_id bigint(20) NOT NULL default '0', |
---|
262 | date_registered datetime NOT NULL default '0000-00-00 00:00:00', |
---|
263 | PRIMARY KEY (ID), |
---|
264 | KEY IP (IP) |
---|
265 | ) $charset_collate; |
---|
266 | CREATE TABLE $wpdb->site ( |
---|
267 | id bigint(20) NOT NULL auto_increment, |
---|
268 | domain varchar(200) NOT NULL default '', |
---|
269 | path varchar(100) NOT NULL default '', |
---|
270 | PRIMARY KEY (id), |
---|
271 | KEY domain (domain,path) |
---|
272 | ) $charset_collate; |
---|
273 | CREATE TABLE $wpdb->sitemeta ( |
---|
274 | meta_id bigint(20) NOT NULL auto_increment, |
---|
275 | site_id bigint(20) NOT NULL default '0', |
---|
276 | meta_key varchar(255) default NULL, |
---|
277 | meta_value longtext, |
---|
278 | PRIMARY KEY (meta_id), |
---|
279 | KEY meta_key (meta_key), |
---|
280 | KEY site_id (site_id) |
---|
281 | ) $charset_collate; |
---|
282 | CREATE TABLE $wpdb->signups ( |
---|
283 | domain varchar(200) NOT NULL default '', |
---|
284 | path varchar(100) NOT NULL default '', |
---|
285 | title longtext NOT NULL, |
---|
286 | user_login varchar(60) NOT NULL default '', |
---|
287 | user_email varchar(100) NOT NULL default '', |
---|
288 | registered datetime NOT NULL default '0000-00-00 00:00:00', |
---|
289 | activated datetime NOT NULL default '0000-00-00 00:00:00', |
---|
290 | active tinyint(1) NOT NULL default '0', |
---|
291 | activation_key varchar(50) NOT NULL default '', |
---|
292 | meta longtext, |
---|
293 | KEY activation_key (activation_key), |
---|
294 | KEY domain (domain) |
---|
295 | ) $charset_collate;"; |
---|
296 | |
---|
297 | switch ( $scope ) { |
---|
298 | case 'blog' : |
---|
299 | $queries = $blog_tables; |
---|
300 | break; |
---|
301 | case 'global' : |
---|
302 | $queries = $global_tables; |
---|
303 | if ( $is_multisite ) |
---|
304 | $queries .= $ms_global_tables; |
---|
305 | break; |
---|
306 | case 'ms_global' : |
---|
307 | $queries = $ms_global_tables; |
---|
308 | break; |
---|
309 | default: |
---|
310 | case 'all' : |
---|
311 | $queries = $global_tables . $blog_tables; |
---|
312 | if ( $is_multisite ) |
---|
313 | $queries .= $ms_global_tables; |
---|
314 | break; |
---|
315 | } |
---|
316 | |
---|
317 | if ( isset( $old_blog_id ) ) |
---|
318 | $wpdb->set_blog_id( $old_blog_id ); |
---|
319 | |
---|
320 | return $queries; |
---|
321 | } |
---|
322 | |
---|
323 | // Populate for back compat. |
---|
324 | $wp_queries = wp_get_db_schema( 'all' ); |
---|
325 | |
---|
326 | /** |
---|
327 | * Create WordPress options and set the default values. |
---|
328 | * |
---|
329 | * @since 1.5.0 |
---|
330 | * @uses $wpdb |
---|
331 | * @uses $wp_db_version |
---|
332 | */ |
---|
333 | function populate_options() { |
---|
334 | global $wpdb, $wp_db_version, $current_site, $wp_current_db_version; |
---|
335 | |
---|
336 | $guessurl = wp_guess_url(); |
---|
337 | |
---|
338 | do_action('populate_options'); |
---|
339 | |
---|
340 | if ( ini_get('safe_mode') ) { |
---|
341 | // Safe mode can break mkdir() so use a flat structure by default. |
---|
342 | $uploads_use_yearmonth_folders = 0; |
---|
343 | } else { |
---|
344 | $uploads_use_yearmonth_folders = 1; |
---|
345 | } |
---|
346 | |
---|
347 | $template = WP_DEFAULT_THEME; |
---|
348 | // If default theme is a child theme, we need to get its template |
---|
349 | foreach ( (array) get_themes() as $theme ) { |
---|
350 | if ( WP_DEFAULT_THEME == $theme['Stylesheet'] ) { |
---|
351 | $template = $theme['Template']; |
---|
352 | break; |
---|
353 | } |
---|
354 | } |
---|
355 | |
---|
356 | $options = array( |
---|
357 | 'siteurl' => $guessurl, |
---|
358 | 'blogname' => __('My Site'), |
---|
359 | /* translators: blog tagline */ |
---|
360 | 'blogdescription' => __('Just another WordPress site'), |
---|
361 | 'users_can_register' => 0, |
---|
362 | 'admin_email' => 'you@example.com', |
---|
363 | 'start_of_week' => 1, |
---|
364 | 'use_balanceTags' => 0, |
---|
365 | 'use_smilies' => 1, |
---|
366 | 'require_name_email' => 1, |
---|
367 | 'comments_notify' => 1, |
---|
368 | 'posts_per_rss' => 10, |
---|
369 | 'rss_use_excerpt' => 0, |
---|
370 | 'mailserver_url' => 'mail.example.com', |
---|
371 | 'mailserver_login' => 'login@example.com', |
---|
372 | 'mailserver_pass' => 'password', |
---|
373 | 'mailserver_port' => 110, |
---|
374 | 'default_category' => 1, |
---|
375 | 'default_comment_status' => 'open', |
---|
376 | 'default_ping_status' => 'open', |
---|
377 | 'default_pingback_flag' => 1, |
---|
378 | 'default_post_edit_rows' => 20, |
---|
379 | 'posts_per_page' => 10, |
---|
380 | /* translators: default date format, see http://php.net/date */ |
---|
381 | 'date_format' => __('F j, Y'), |
---|
382 | /* translators: default time format, see http://php.net/date */ |
---|
383 | 'time_format' => __('g:i a'), |
---|
384 | /* translators: links last updated date format, see http://php.net/date */ |
---|
385 | 'links_updated_date_format' => __('F j, Y g:i a'), |
---|
386 | 'links_recently_updated_prepend' => '<em>', |
---|
387 | 'links_recently_updated_append' => '</em>', |
---|
388 | 'links_recently_updated_time' => 120, |
---|
389 | 'comment_moderation' => 0, |
---|
390 | 'moderation_notify' => 1, |
---|
391 | 'permalink_structure' => '', |
---|
392 | 'gzipcompression' => 0, |
---|
393 | 'hack_file' => 0, |
---|
394 | 'blog_charset' => 'UTF-8', |
---|
395 | 'moderation_keys' => '', |
---|
396 | 'active_plugins' => array(), |
---|
397 | 'home' => $guessurl, |
---|
398 | 'category_base' => '', |
---|
399 | 'ping_sites' => 'http://rpc.pingomatic.com/', |
---|
400 | 'advanced_edit' => 0, |
---|
401 | 'comment_max_links' => 2, |
---|
402 | 'gmt_offset' => date('Z') / 3600, |
---|
403 | |
---|
404 | // 1.5 |
---|
405 | 'default_email_category' => 1, |
---|
406 | 'recently_edited' => '', |
---|
407 | 'template' => $template, |
---|
408 | 'stylesheet' => WP_DEFAULT_THEME, |
---|
409 | 'comment_whitelist' => 1, |
---|
410 | 'blacklist_keys' => '', |
---|
411 | 'comment_registration' => 0, |
---|
412 | 'rss_language' => 'en', |
---|
413 | 'html_type' => 'text/html', |
---|
414 | |
---|
415 | // 1.5.1 |
---|
416 | 'use_trackback' => 0, |
---|
417 | |
---|
418 | // 2.0 |
---|
419 | 'default_role' => 'subscriber', |
---|
420 | 'db_version' => $wp_db_version, |
---|
421 | |
---|
422 | // 2.0.1 |
---|
423 | 'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders, |
---|
424 | 'upload_path' => '', |
---|
425 | |
---|
426 | // 2.1 |
---|
427 | 'blog_public' => '1', |
---|
428 | 'default_link_category' => 2, |
---|
429 | 'show_on_front' => 'posts', |
---|
430 | |
---|
431 | // 2.2 |
---|
432 | 'tag_base' => '', |
---|
433 | |
---|
434 | // 2.5 |
---|
435 | 'show_avatars' => '1', |
---|
436 | 'avatar_rating' => 'G', |
---|
437 | 'upload_url_path' => '', |
---|
438 | 'thumbnail_size_w' => 150, |
---|
439 | 'thumbnail_size_h' => 150, |
---|
440 | 'thumbnail_crop' => 1, |
---|
441 | 'medium_size_w' => 300, |
---|
442 | 'medium_size_h' => 300, |
---|
443 | |
---|
444 | // 2.6 |
---|
445 | 'avatar_default' => 'mystery', |
---|
446 | 'enable_app' => 0, |
---|
447 | 'enable_xmlrpc' => 0, |
---|
448 | |
---|
449 | // 2.7 |
---|
450 | 'large_size_w' => 1024, |
---|
451 | 'large_size_h' => 1024, |
---|
452 | 'image_default_link_type' => 'file', |
---|
453 | 'image_default_size' => '', |
---|
454 | 'image_default_align' => '', |
---|
455 | 'close_comments_for_old_posts' => 0, |
---|
456 | 'close_comments_days_old' => 14, |
---|
457 | 'thread_comments' => 1, |
---|
458 | 'thread_comments_depth' => 5, |
---|
459 | 'page_comments' => 0, |
---|
460 | 'comments_per_page' => 50, |
---|
461 | 'default_comments_page' => 'newest', |
---|
462 | 'comment_order' => 'asc', |
---|
463 | 'sticky_posts' => array(), |
---|
464 | 'widget_categories' => array(), |
---|
465 | 'widget_text' => array(), |
---|
466 | 'widget_rss' => array(), |
---|
467 | |
---|
468 | // 2.8 |
---|
469 | 'timezone_string' => '', |
---|
470 | |
---|
471 | // 2.9 |
---|
472 | 'embed_autourls' => 1, |
---|
473 | 'embed_size_w' => '', |
---|
474 | 'embed_size_h' => 600, |
---|
475 | |
---|
476 | // 3.0 |
---|
477 | 'page_for_posts' => 0, |
---|
478 | 'page_on_front' => 0, |
---|
479 | |
---|
480 | // 3.1 |
---|
481 | 'default_post_format' => 0, |
---|
482 | ); |
---|
483 | |
---|
484 | // 3.3 |
---|
485 | if ( ! is_multisite() ) { |
---|
486 | $options['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version |
---|
487 | ? $wp_current_db_version : $wp_db_version; |
---|
488 | } |
---|
489 | |
---|
490 | // 3.0 multisite |
---|
491 | if ( is_multisite() ) { |
---|
492 | /* translators: blog tagline */ |
---|
493 | $options[ 'blogdescription' ] = sprintf(__('Just another %s site'), $current_site->site_name ); |
---|
494 | $options[ 'permalink_structure' ] = '/%year%/%monthnum%/%day%/%postname%/'; |
---|
495 | } |
---|
496 | |
---|
497 | // Set autoload to no for these options |
---|
498 | $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' ); |
---|
499 | |
---|
500 | $existing_options = $wpdb->get_col("SELECT option_name FROM $wpdb->options"); |
---|
501 | |
---|
502 | $insert = ''; |
---|
503 | foreach ( $options as $option => $value ) { |
---|
504 | if ( in_array($option, $existing_options) ) |
---|
505 | continue; |
---|
506 | if ( in_array($option, $fat_options) ) |
---|
507 | $autoload = 'no'; |
---|
508 | else |
---|
509 | $autoload = 'yes'; |
---|
510 | |
---|
511 | $option = $wpdb->escape($option); |
---|
512 | if ( is_array($value) ) |
---|
513 | $value = serialize($value); |
---|
514 | $value = $wpdb->escape($value); |
---|
515 | if ( !empty($insert) ) |
---|
516 | $insert .= ', '; |
---|
517 | $insert .= "('$option', '$value', '$autoload')"; |
---|
518 | } |
---|
519 | |
---|
520 | if ( !empty($insert) ) |
---|
521 | $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert); |
---|
522 | |
---|
523 | // in case it is set, but blank, update "home" |
---|
524 | if ( !__get_option('home') ) update_option('home', $guessurl); |
---|
525 | |
---|
526 | // Delete unused options |
---|
527 | $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'); |
---|
528 | foreach ( $unusedoptions as $option ) |
---|
529 | delete_option($option); |
---|
530 | |
---|
531 | // delete obsolete magpie stuff |
---|
532 | $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'"); |
---|
533 | } |
---|
534 | |
---|
535 | /** |
---|
536 | * Execute WordPress role creation for the various WordPress versions. |
---|
537 | * |
---|
538 | * @since 2.0.0 |
---|
539 | */ |
---|
540 | function populate_roles() { |
---|
541 | populate_roles_160(); |
---|
542 | populate_roles_210(); |
---|
543 | populate_roles_230(); |
---|
544 | populate_roles_250(); |
---|
545 | populate_roles_260(); |
---|
546 | populate_roles_270(); |
---|
547 | populate_roles_280(); |
---|
548 | populate_roles_300(); |
---|
549 | } |
---|
550 | |
---|
551 | /** |
---|
552 | * Create the roles for WordPress 2.0 |
---|
553 | * |
---|
554 | * @since 2.0.0 |
---|
555 | */ |
---|
556 | function populate_roles_160() { |
---|
557 | // Add roles |
---|
558 | |
---|
559 | // Dummy gettext calls to get strings in the catalog. |
---|
560 | /* translators: user role */ |
---|
561 | _x('Administrator', 'User role'); |
---|
562 | /* translators: user role */ |
---|
563 | _x('Editor', 'User role'); |
---|
564 | /* translators: user role */ |
---|
565 | _x('Author', 'User role'); |
---|
566 | /* translators: user role */ |
---|
567 | _x('Contributor', 'User role'); |
---|
568 | /* translators: user role */ |
---|
569 | _x('Subscriber', 'User role'); |
---|
570 | |
---|
571 | add_role('administrator', 'Administrator'); |
---|
572 | add_role('editor', 'Editor'); |
---|
573 | add_role('author', 'Author'); |
---|
574 | add_role('contributor', 'Contributor'); |
---|
575 | add_role('subscriber', 'Subscriber'); |
---|
576 | |
---|
577 | // Add caps for Administrator role |
---|
578 | $role =& get_role('administrator'); |
---|
579 | $role->add_cap('switch_themes'); |
---|
580 | $role->add_cap('edit_themes'); |
---|
581 | $role->add_cap('activate_plugins'); |
---|
582 | $role->add_cap('edit_plugins'); |
---|
583 | $role->add_cap('edit_users'); |
---|
584 | $role->add_cap('edit_files'); |
---|
585 | $role->add_cap('manage_options'); |
---|
586 | $role->add_cap('moderate_comments'); |
---|
587 | $role->add_cap('manage_categories'); |
---|
588 | $role->add_cap('manage_links'); |
---|
589 | $role->add_cap('upload_files'); |
---|
590 | $role->add_cap('import'); |
---|
591 | $role->add_cap('unfiltered_html'); |
---|
592 | $role->add_cap('edit_posts'); |
---|
593 | $role->add_cap('edit_others_posts'); |
---|
594 | $role->add_cap('edit_published_posts'); |
---|
595 | $role->add_cap('publish_posts'); |
---|
596 | $role->add_cap('edit_pages'); |
---|
597 | $role->add_cap('read'); |
---|
598 | $role->add_cap('level_10'); |
---|
599 | $role->add_cap('level_9'); |
---|
600 | $role->add_cap('level_8'); |
---|
601 | $role->add_cap('level_7'); |
---|
602 | $role->add_cap('level_6'); |
---|
603 | $role->add_cap('level_5'); |
---|
604 | $role->add_cap('level_4'); |
---|
605 | $role->add_cap('level_3'); |
---|
606 | $role->add_cap('level_2'); |
---|
607 | $role->add_cap('level_1'); |
---|
608 | $role->add_cap('level_0'); |
---|
609 | |
---|
610 | // Add caps for Editor role |
---|
611 | $role =& get_role('editor'); |
---|
612 | $role->add_cap('moderate_comments'); |
---|
613 | $role->add_cap('manage_categories'); |
---|
614 | $role->add_cap('manage_links'); |
---|
615 | $role->add_cap('upload_files'); |
---|
616 | $role->add_cap('unfiltered_html'); |
---|
617 | $role->add_cap('edit_posts'); |
---|
618 | $role->add_cap('edit_others_posts'); |
---|
619 | $role->add_cap('edit_published_posts'); |
---|
620 | $role->add_cap('publish_posts'); |
---|
621 | $role->add_cap('edit_pages'); |
---|
622 | $role->add_cap('read'); |
---|
623 | $role->add_cap('level_7'); |
---|
624 | $role->add_cap('level_6'); |
---|
625 | $role->add_cap('level_5'); |
---|
626 | $role->add_cap('level_4'); |
---|
627 | $role->add_cap('level_3'); |
---|
628 | $role->add_cap('level_2'); |
---|
629 | $role->add_cap('level_1'); |
---|
630 | $role->add_cap('level_0'); |
---|
631 | |
---|
632 | // Add caps for Author role |
---|
633 | $role =& get_role('author'); |
---|
634 | $role->add_cap('upload_files'); |
---|
635 | $role->add_cap('edit_posts'); |
---|
636 | $role->add_cap('edit_published_posts'); |
---|
637 | $role->add_cap('publish_posts'); |
---|
638 | $role->add_cap('read'); |
---|
639 | $role->add_cap('level_2'); |
---|
640 | $role->add_cap('level_1'); |
---|
641 | $role->add_cap('level_0'); |
---|
642 | |
---|
643 | // Add caps for Contributor role |
---|
644 | $role =& get_role('contributor'); |
---|
645 | $role->add_cap('edit_posts'); |
---|
646 | $role->add_cap('read'); |
---|
647 | $role->add_cap('level_1'); |
---|
648 | $role->add_cap('level_0'); |
---|
649 | |
---|
650 | // Add caps for Subscriber role |
---|
651 | $role =& get_role('subscriber'); |
---|
652 | $role->add_cap('read'); |
---|
653 | $role->add_cap('level_0'); |
---|
654 | } |
---|
655 | |
---|
656 | /** |
---|
657 | * Create and modify WordPress roles for WordPress 2.1. |
---|
658 | * |
---|
659 | * @since 2.1.0 |
---|
660 | */ |
---|
661 | function populate_roles_210() { |
---|
662 | $roles = array('administrator', 'editor'); |
---|
663 | foreach ($roles as $role) { |
---|
664 | $role =& get_role($role); |
---|
665 | if ( empty($role) ) |
---|
666 | continue; |
---|
667 | |
---|
668 | $role->add_cap('edit_others_pages'); |
---|
669 | $role->add_cap('edit_published_pages'); |
---|
670 | $role->add_cap('publish_pages'); |
---|
671 | $role->add_cap('delete_pages'); |
---|
672 | $role->add_cap('delete_others_pages'); |
---|
673 | $role->add_cap('delete_published_pages'); |
---|
674 | $role->add_cap('delete_posts'); |
---|
675 | $role->add_cap('delete_others_posts'); |
---|
676 | $role->add_cap('delete_published_posts'); |
---|
677 | $role->add_cap('delete_private_posts'); |
---|
678 | $role->add_cap('edit_private_posts'); |
---|
679 | $role->add_cap('read_private_posts'); |
---|
680 | $role->add_cap('delete_private_pages'); |
---|
681 | $role->add_cap('edit_private_pages'); |
---|
682 | $role->add_cap('read_private_pages'); |
---|
683 | } |
---|
684 | |
---|
685 | $role =& get_role('administrator'); |
---|
686 | if ( ! empty($role) ) { |
---|
687 | $role->add_cap('delete_users'); |
---|
688 | $role->add_cap('create_users'); |
---|
689 | } |
---|
690 | |
---|
691 | $role =& get_role('author'); |
---|
692 | if ( ! empty($role) ) { |
---|
693 | $role->add_cap('delete_posts'); |
---|
694 | $role->add_cap('delete_published_posts'); |
---|
695 | } |
---|
696 | |
---|
697 | $role =& get_role('contributor'); |
---|
698 | if ( ! empty($role) ) { |
---|
699 | $role->add_cap('delete_posts'); |
---|
700 | } |
---|
701 | } |
---|
702 | |
---|
703 | /** |
---|
704 | * Create and modify WordPress roles for WordPress 2.3. |
---|
705 | * |
---|
706 | * @since 2.3.0 |
---|
707 | */ |
---|
708 | function populate_roles_230() { |
---|
709 | $role =& get_role( 'administrator' ); |
---|
710 | |
---|
711 | if ( !empty( $role ) ) { |
---|
712 | $role->add_cap( 'unfiltered_upload' ); |
---|
713 | } |
---|
714 | } |
---|
715 | |
---|
716 | /** |
---|
717 | * Create and modify WordPress roles for WordPress 2.5. |
---|
718 | * |
---|
719 | * @since 2.5.0 |
---|
720 | */ |
---|
721 | function populate_roles_250() { |
---|
722 | $role =& get_role( 'administrator' ); |
---|
723 | |
---|
724 | if ( !empty( $role ) ) { |
---|
725 | $role->add_cap( 'edit_dashboard' ); |
---|
726 | } |
---|
727 | } |
---|
728 | |
---|
729 | /** |
---|
730 | * Create and modify WordPress roles for WordPress 2.6. |
---|
731 | * |
---|
732 | * @since 2.6.0 |
---|
733 | */ |
---|
734 | function populate_roles_260() { |
---|
735 | $role =& get_role( 'administrator' ); |
---|
736 | |
---|
737 | if ( !empty( $role ) ) { |
---|
738 | $role->add_cap( 'update_plugins' ); |
---|
739 | $role->add_cap( 'delete_plugins' ); |
---|
740 | } |
---|
741 | } |
---|
742 | |
---|
743 | /** |
---|
744 | * Create and modify WordPress roles for WordPress 2.7. |
---|
745 | * |
---|
746 | * @since 2.7.0 |
---|
747 | */ |
---|
748 | function populate_roles_270() { |
---|
749 | $role =& get_role( 'administrator' ); |
---|
750 | |
---|
751 | if ( !empty( $role ) ) { |
---|
752 | $role->add_cap( 'install_plugins' ); |
---|
753 | $role->add_cap( 'update_themes' ); |
---|
754 | } |
---|
755 | } |
---|
756 | |
---|
757 | /** |
---|
758 | * Create and modify WordPress roles for WordPress 2.8. |
---|
759 | * |
---|
760 | * @since 2.8.0 |
---|
761 | */ |
---|
762 | function populate_roles_280() { |
---|
763 | $role =& get_role( 'administrator' ); |
---|
764 | |
---|
765 | if ( !empty( $role ) ) { |
---|
766 | $role->add_cap( 'install_themes' ); |
---|
767 | } |
---|
768 | } |
---|
769 | |
---|
770 | /** |
---|
771 | * Create and modify WordPress roles for WordPress 3.0. |
---|
772 | * |
---|
773 | * @since 3.0.0 |
---|
774 | */ |
---|
775 | function populate_roles_300() { |
---|
776 | $role =& get_role( 'administrator' ); |
---|
777 | |
---|
778 | if ( !empty( $role ) ) { |
---|
779 | $role->add_cap( 'update_core' ); |
---|
780 | $role->add_cap( 'list_users' ); |
---|
781 | $role->add_cap( 'remove_users' ); |
---|
782 | $role->add_cap( 'add_users' ); |
---|
783 | $role->add_cap( 'promote_users' ); |
---|
784 | $role->add_cap( 'edit_theme_options' ); |
---|
785 | $role->add_cap( 'delete_themes' ); |
---|
786 | $role->add_cap( 'export' ); |
---|
787 | } |
---|
788 | } |
---|
789 | |
---|
790 | /** |
---|
791 | * Install Network. |
---|
792 | * |
---|
793 | * @since 3.0.0 |
---|
794 | * |
---|
795 | */ |
---|
796 | if ( !function_exists( 'install_network' ) ) : |
---|
797 | function install_network() { |
---|
798 | if ( ! defined( 'WP_INSTALLING_NETWORK' ) ) |
---|
799 | define( 'WP_INSTALLING_NETWORK', true ); |
---|
800 | |
---|
801 | dbDelta( wp_get_db_schema( 'global' ) ); |
---|
802 | } |
---|
803 | endif; |
---|
804 | |
---|
805 | /** |
---|
806 | * populate network settings |
---|
807 | * |
---|
808 | * @since 3.0.0 |
---|
809 | * |
---|
810 | * @param int $network_id id of network to populate |
---|
811 | * @return bool|WP_Error True on success, or WP_Error on warning (with the install otherwise successful, |
---|
812 | * so the error code must be checked) or failure. |
---|
813 | */ |
---|
814 | function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) { |
---|
815 | global $wpdb, $current_site, $wp_db_version, $wp_rewrite; |
---|
816 | |
---|
817 | $errors = new WP_Error(); |
---|
818 | if ( '' == $domain ) |
---|
819 | $errors->add( 'empty_domain', __( 'You must provide a domain name.' ) ); |
---|
820 | if ( '' == $site_name ) |
---|
821 | $errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) ); |
---|
822 | |
---|
823 | // check for network collision |
---|
824 | if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) ) |
---|
825 | $errors->add( 'siteid_exists', __( 'The network already exists.' ) ); |
---|
826 | |
---|
827 | $site_user = get_user_by( 'email', $email ); |
---|
828 | if ( ! is_email( $email ) ) |
---|
829 | $errors->add( 'invalid_email', __( 'You must provide a valid e-mail address.' ) ); |
---|
830 | |
---|
831 | if ( $errors->get_error_code() ) |
---|
832 | return $errors; |
---|
833 | |
---|
834 | // set up site tables |
---|
835 | $template = get_option( 'template' ); |
---|
836 | $stylesheet = get_option( 'stylesheet' ); |
---|
837 | $allowed_themes = array( $stylesheet => true ); |
---|
838 | if ( $template != $stylesheet ) |
---|
839 | $allowed_themes[ $template ] = true; |
---|
840 | if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template ) |
---|
841 | $allowed_themes[ WP_DEFAULT_THEME ] = true; |
---|
842 | |
---|
843 | if ( 1 == $network_id ) { |
---|
844 | $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) ); |
---|
845 | $network_id = $wpdb->insert_id; |
---|
846 | } else { |
---|
847 | $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path, 'id' => $network_id ) ); |
---|
848 | } |
---|
849 | |
---|
850 | if ( !is_multisite() ) { |
---|
851 | $site_admins = array( $site_user->user_login ); |
---|
852 | $users = get_users( array( 'fields' => array( 'ID', 'user_login' ) ) ); |
---|
853 | if ( $users ) { |
---|
854 | foreach ( $users as $user ) { |
---|
855 | if ( is_super_admin( $user->ID ) && !in_array( $user->user_login, $site_admins ) ) |
---|
856 | $site_admins[] = $user->user_login; |
---|
857 | } |
---|
858 | } |
---|
859 | } else { |
---|
860 | $site_admins = get_site_option( 'site_admins' ); |
---|
861 | } |
---|
862 | |
---|
863 | $welcome_email = __( 'Dear User, |
---|
864 | |
---|
865 | Your new SITE_NAME site has been successfully set up at: |
---|
866 | BLOG_URL |
---|
867 | |
---|
868 | You can log in to the administrator account with the following information: |
---|
869 | Username: USERNAME |
---|
870 | Password: PASSWORD |
---|
871 | Log in here: BLOG_URLwp-login.php |
---|
872 | |
---|
873 | We hope you enjoy your new site. Thanks! |
---|
874 | |
---|
875 | --The Team @ SITE_NAME' ); |
---|
876 | |
---|
877 | $sitemeta = array( |
---|
878 | 'site_name' => $site_name, |
---|
879 | 'admin_email' => $site_user->user_email, |
---|
880 | 'admin_user_id' => $site_user->ID, |
---|
881 | 'registration' => 'none', |
---|
882 | 'upload_filetypes' => 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf', |
---|
883 | 'blog_upload_space' => 10, |
---|
884 | 'fileupload_maxk' => 1500, |
---|
885 | 'site_admins' => $site_admins, |
---|
886 | 'allowedthemes' => $allowed_themes, |
---|
887 | 'illegal_names' => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ), |
---|
888 | 'wpmu_upgrade_site' => $wp_db_version, |
---|
889 | 'welcome_email' => $welcome_email, |
---|
890 | 'first_post' => __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ), |
---|
891 | // @todo - network admins should have a method of editing the network siteurl (used for cookie hash) |
---|
892 | 'siteurl' => get_option( 'siteurl' ) . '/', |
---|
893 | 'add_new_users' => '0', |
---|
894 | 'upload_space_check_disabled' => '0', |
---|
895 | 'subdomain_install' => intval( $subdomain_install ), |
---|
896 | 'global_terms_enabled' => global_terms_enabled() ? '1' : '0', |
---|
897 | 'initial_db_version' => get_option( 'initial_db_version' ), |
---|
898 | 'active_sitewide_plugins' => array(), |
---|
899 | ); |
---|
900 | if ( ! $subdomain_install ) |
---|
901 | $sitemeta['illegal_names'][] = 'blog'; |
---|
902 | |
---|
903 | $insert = ''; |
---|
904 | foreach ( $sitemeta as $meta_key => $meta_value ) { |
---|
905 | $meta_key = $wpdb->escape( $meta_key ); |
---|
906 | if ( is_array( $meta_value ) ) |
---|
907 | $meta_value = serialize( $meta_value ); |
---|
908 | $meta_value = $wpdb->escape( $meta_value ); |
---|
909 | if ( !empty( $insert ) ) |
---|
910 | $insert .= ', '; |
---|
911 | $insert .= "( $network_id, '$meta_key', '$meta_value')"; |
---|
912 | } |
---|
913 | $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); |
---|
914 | |
---|
915 | $current_site->domain = $domain; |
---|
916 | $current_site->path = $path; |
---|
917 | $current_site->site_name = ucfirst( $domain ); |
---|
918 | |
---|
919 | if ( !is_multisite() ) { |
---|
920 | $wpdb->insert( $wpdb->blogs, array( 'site_id' => $network_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time( 'mysql' ) ) ); |
---|
921 | $blog_id = $wpdb->insert_id; |
---|
922 | update_user_meta( $site_user->ID, 'source_domain', $domain ); |
---|
923 | update_user_meta( $site_user->ID, 'primary_blog', $blog_id ); |
---|
924 | if ( !$upload_path = get_option( 'upload_path' ) ) { |
---|
925 | $upload_path = substr( WP_CONTENT_DIR, strlen( ABSPATH ) ) . '/uploads'; |
---|
926 | update_option( 'upload_path', $upload_path ); |
---|
927 | } |
---|
928 | update_option( 'fileupload_url', get_option( 'siteurl' ) . '/' . $upload_path ); |
---|
929 | } |
---|
930 | |
---|
931 | if ( $subdomain_install ) |
---|
932 | update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/'); |
---|
933 | else |
---|
934 | update_option( 'permalink_structure', '/blog/%year%/%monthnum%/%day%/%postname%/'); |
---|
935 | |
---|
936 | $wp_rewrite->flush_rules(); |
---|
937 | |
---|
938 | if ( $subdomain_install ) { |
---|
939 | $vhost_ok = false; |
---|
940 | $errstr = ''; |
---|
941 | $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname! |
---|
942 | $page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) ); |
---|
943 | if ( is_wp_error( $page ) ) |
---|
944 | $errstr = $page->get_error_message(); |
---|
945 | elseif ( 200 == wp_remote_retrieve_response_code( $page ) ) |
---|
946 | $vhost_ok = true; |
---|
947 | |
---|
948 | if ( ! $vhost_ok ) { |
---|
949 | $msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>'; |
---|
950 | $msg .= '<p>' . sprintf( __( 'The installer attempted to contact a random hostname (<code>%1$s</code>) on your domain.' ), $hostname ); |
---|
951 | if ( ! empty ( $errstr ) ) |
---|
952 | $msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' ); |
---|
953 | $msg .= '</p>'; |
---|
954 | $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>'; |
---|
955 | $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>'; |
---|
956 | return new WP_Error( 'no_wildcard_dns', $msg ); |
---|
957 | } |
---|
958 | } |
---|
959 | |
---|
960 | return true; |
---|
961 | } |
---|
962 | |
---|
963 | ?> |
---|