Changeset 2037 for trunk/wp-admin/upgrade-functions.php
- Timestamp:
- 01/02/2005 10:09:16 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/upgrade-functions.php
r1975 r2037 208 208 } 209 209 } 210 211 make_site_theme(); 210 212 } 211 213 … … 526 528 } 527 529 530 // Create a site theme from the default theme. 531 function make_site_theme() { 532 // Name the theme after the blog. 533 $site = get_option('blogname'); 534 $template = sanitize_title($site); 535 $site_dir = ABSPATH . "wp-content/themes/$template"; 536 537 // If the theme already exists, nothing to do. 538 if ( is_dir($site_dir)) { 539 return; 540 } 541 542 // We must be able to write to the themes dir. 543 if (! is_writable(ABSPATH . "wp-content/themes")) { 544 return; 545 } 546 547 if (! mkdir($site_dir, 0777)) { 548 return; 549 } 550 551 // Copy files from the default theme to the new site theme. 552 // TODO: Copy wp-* template files from the blog root when upgrading from 553 // pre-theme releases. 554 $default_dir = ABSPATH . 'wp-content/themes/default'; 555 $files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css'); 556 557 foreach ($files as $file) { 558 if (! copy("$default_dir/$file", "$site_dir/$file")) { 559 return; 560 } 561 562 chmod("$site_dir/$file", 0777); 563 } 564 565 // Rewrite the theme header. 566 $stylelines = explode("\n", implode('', file("$site_dir/style.css"))); 567 if ($stylelines) { 568 $f = fopen("$site_dir/style.css", 'w'); 569 570 foreach ($stylelines as $line) { 571 if (strstr($line, "Theme Name:")) $line = "Theme Name: $site"; 572 elseif (strstr($line, "Theme URI:")) $line = "Theme URI: " . get_option('siteurl'); 573 elseif (strstr($line, "Description:")) $line = "Description: Your theme"; 574 elseif (strstr($line, "Version:")) $line = "Version: 1"; 575 elseif (strstr($line, "Author:")) $line = "Author: You"; 576 fwrite($f, "{$line}\n"); 577 } 578 fclose($f); 579 } 580 581 // Make the new site theme active. 582 $current_template = get_option('template'); 583 if ($current_template == 'default') { 584 update_option('template', $template); 585 update_option('stylesheet', $template); 586 } 587 return $template; 588 } 528 589 ?>
Note: See TracChangeset
for help on using the changeset viewer.