make_site_theme_from_default

Creates a site theme from the default theme.

Description

(false|void) make_site_theme_from_default( (string) $theme_name, (string) $template ); 

}

Returns (false|void)

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_default' ) ) { 
  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_default($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_default($theme_name, $template) { 
  2. $site_dir = WP_CONTENT_DIR . "/themes/$template"; 
  3. $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME
  4.  
  5. // Copy files from the default theme to the site theme. 
  6. //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css'); 
  7.  
  8. $theme_dir = @ opendir($default_dir); 
  9. if ($theme_dir) { 
  10. while(($theme_file = readdir( $theme_dir )) !== false) { 
  11. if (is_dir("$default_dir/$theme_file")) 
  12. continue; 
  13. if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file")) 
  14. return; 
  15. chmod("$site_dir/$theme_file", 0777); 
  16. @closedir($theme_dir); 
  17.  
  18. // Rewrite the theme header. 
  19. $stylelines = explode("\n", implode('', file("$site_dir/style.css"))); 
  20. if ($stylelines) { 
  21. $f = fopen("$site_dir/style.css", 'w'); 
  22.  
  23. foreach ($stylelines as $line) { 
  24. if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name; 
  25. elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url'); 
  26. elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.'; 
  27. elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1'; 
  28. elseif (strpos($line, 'Author:') !== false) $line = 'Author: You'; 
  29. fwrite($f, $line . "\n"); 
  30. fclose($f); 
  31.  
  32. // Copy the images. 
  33. umask(0); 
  34. if (! mkdir("$site_dir/images", 0777)) { 
  35. return false; 
  36.  
  37. $images_dir = @ opendir("$default_dir/images"); 
  38. if ($images_dir) { 
  39. while(($image = readdir($images_dir)) !== false) { 
  40. if (is_dir("$default_dir/images/$image")) 
  41. continue; 
  42. if (! @copy("$default_dir/images/$image", "$site_dir/images/$image")) 
  43. return; 
  44. chmod("$site_dir/images/$image", 0777); 
  45. @closedir($images_dir);