make_site_theme_from_oldschool

Creates a site theme from an existing theme.

Description

make_site_theme_from_oldschool( (string) $theme_name, (string) $template ); 

}

Parameters (2)

0. $theme_name (string)
The name of the theme.
1. $template (string)
The directory name of the theme.

Usage

  1. if ( !function_exists( 'make_site_theme_from_oldschool' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 
  3.  
  4. // The name of the theme. 
  5. $theme_name = ''; 
  6.  
  7. // The directory name of the theme. 
  8. $template = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = make_site_theme_from_oldschool($theme_name, $template); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/upgrade.php  
  1. function make_site_theme_from_oldschool($theme_name, $template) { 
  2. $home_path = get_home_path(); 
  3. $site_dir = WP_CONTENT_DIR . "/themes/$template"; 
  4.  
  5. if (! file_exists("$home_path/index.php")) 
  6. return false; 
  7.  
  8. /** 
  9. * Copy files from the old locations to the site theme. 
  10. * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied. 
  11. */ 
  12. $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php'); 
  13.  
  14. foreach ($files as $oldfile => $newfile) { 
  15. if ($oldfile == 'index.php') 
  16. $oldpath = $home_path; 
  17. else 
  18. $oldpath = ABSPATH
  19.  
  20. // Check to make sure it's not a new index. 
  21. if ($oldfile == 'index.php') { 
  22. $index = implode('', file("$oldpath/$oldfile")); 
  23. if (strpos($index, 'WP_USE_THEMES') !== false) { 
  24. if (! @copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile")) 
  25. return false; 
  26.  
  27. // Don't copy anything. 
  28. continue; 
  29.  
  30. if (! @copy("$oldpath/$oldfile", "$site_dir/$newfile")) 
  31. return false; 
  32.  
  33. chmod("$site_dir/$newfile", 0777); 
  34.  
  35. // Update the blog header include in each file. 
  36. $lines = explode("\n", implode('', file("$site_dir/$newfile"))); 
  37. if ($lines) { 
  38. $f = fopen("$site_dir/$newfile", 'w'); 
  39.  
  40. foreach ($lines as $line) { 
  41. if (preg_match('/require.*wp-blog-header/', $line)) 
  42. $line = '//' . $line; 
  43.  
  44. // Update stylesheet references. 
  45. $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line); 
  46.  
  47. // Update comments template inclusion. 
  48. $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", "<?php comments_template(); ?>", $line); 
  49.  
  50. fwrite($f, "{$line}\n"); 
  51. fclose($f); 
  52.  
  53. // Add a theme header. 
  54. $header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option('siteurl') . "\nDescription: A theme automatically created by the update.\nVersion: 1.0\nAuthor: Moi\n*/\n"; 
  55.  
  56. $stylelines = file_get_contents("$site_dir/style.css"); 
  57. if ($stylelines) { 
  58. $f = fopen("$site_dir/style.css", 'w'); 
  59.  
  60. fwrite($f, $header); 
  61. fwrite($f, $stylelines); 
  62. fclose($f); 
  63.  
  64. return true;