make_site_theme_from_default

The timeline below displays how wordpress function make_site_theme_from_default has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Creates a site theme from the default theme.
 *
 * {@internal Missing Long Description}}
 *
 * @since 1.5.0
 *
 * @param string $theme_name The name of the theme.
 * @param string $template   The directory name of the theme.
 * @return void|false
 */
function make_site_theme_from_default($theme_name, $template)
{
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
    /*
     * Copy files from the default theme to the site theme.
     * $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' );
     */
    $theme_dir = @opendir($default_dir);
    if ($theme_dir) {
        while (($theme_file = readdir($theme_dir)) !== false) {
            if (is_dir("{$default_dir}/{$theme_file}")) {
                continue;
            }
            if (!copy("{$default_dir}/{$theme_file}", "{$site_dir}/{$theme_file}")) {
                return;
            }
            chmod("{$site_dir}/{$theme_file}", 0777);
        }
        closedir($theme_dir);
    }
    // Rewrite the theme header.
    $stylelines = explode("\n", implode('', file("{$site_dir}/style.css")));
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        $headers = array('Theme Name:' => $theme_name, 'Theme URI:' => __get_option('url'), 'Description:' => 'Your theme.', 'Version:' => '1', 'Author:' => 'You');
        foreach ($stylelines as $line) {
            foreach ($headers as $header => $value) {
                if (str_contains($line, $header)) {
                    $line = $header . ' ' . $value;
                    break;
                }
            }
            fwrite($f, $line . "\n");
        }
        fclose($f);
    }
    // Copy the images.
    umask(0);
    if (!mkdir("{$site_dir}/images", 0777)) {
        return false;
    }
    $images_dir = @opendir("{$default_dir}/images");
    if ($images_dir) {
        while (($image = readdir($images_dir)) !== false) {
            if (is_dir("{$default_dir}/images/{$image}")) {
                continue;
            }
            if (!copy("{$default_dir}/images/{$image}", "{$site_dir}/images/{$image}")) {
                return;
            }
            chmod("{$site_dir}/images/{$image}", 0777);
        }
        closedir($images_dir);
    }
}

WordPress Version: 5.4

/**
 * Creates a site theme from the default theme.
 *
 * {@internal Missing Long Description}}
 *
 * @since 1.5.0
 *
 * @param string $theme_name The name of the theme.
 * @param string $template   The directory name of the theme.
 * @return void|false
 */
function make_site_theme_from_default($theme_name, $template)
{
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
    // Copy files from the default theme to the site theme.
    // $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' );
    $theme_dir = @opendir($default_dir);
    if ($theme_dir) {
        while (($theme_file = readdir($theme_dir)) !== false) {
            if (is_dir("{$default_dir}/{$theme_file}")) {
                continue;
            }
            if (!copy("{$default_dir}/{$theme_file}", "{$site_dir}/{$theme_file}")) {
                return;
            }
            chmod("{$site_dir}/{$theme_file}", 0777);
        }
        closedir($theme_dir);
    }
    // Rewrite the theme header.
    $stylelines = explode("\n", implode('', file("{$site_dir}/style.css")));
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        foreach ($stylelines as $line) {
            if (strpos($line, 'Theme Name:') !== false) {
                $line = 'Theme Name: ' . $theme_name;
            } elseif (strpos($line, 'Theme URI:') !== false) {
                $line = 'Theme URI: ' . __get_option('url');
            } elseif (strpos($line, 'Description:') !== false) {
                $line = 'Description: Your theme.';
            } elseif (strpos($line, 'Version:') !== false) {
                $line = 'Version: 1';
            } elseif (strpos($line, 'Author:') !== false) {
                $line = 'Author: You';
            }
            fwrite($f, $line . "\n");
        }
        fclose($f);
    }
    // Copy the images.
    umask(0);
    if (!mkdir("{$site_dir}/images", 0777)) {
        return false;
    }
    $images_dir = @opendir("{$default_dir}/images");
    if ($images_dir) {
        while (($image = readdir($images_dir)) !== false) {
            if (is_dir("{$default_dir}/images/{$image}")) {
                continue;
            }
            if (!copy("{$default_dir}/images/{$image}", "{$site_dir}/images/{$image}")) {
                return;
            }
            chmod("{$site_dir}/images/{$image}", 0777);
        }
        closedir($images_dir);
    }
}

WordPress Version: 5.3

/**
 * Creates a site theme from the default theme.
 *
 * {@internal Missing Long Description}}
 *
 * @since 1.5.0
 *
 * @param string $theme_name The name of the theme.
 * @param string $template   The directory name of the theme.
 * @return false|void
 */
function make_site_theme_from_default($theme_name, $template)
{
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
    // Copy files from the default theme to the site theme.
    //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
    $theme_dir = @opendir($default_dir);
    if ($theme_dir) {
        while (($theme_file = readdir($theme_dir)) !== false) {
            if (is_dir("{$default_dir}/{$theme_file}")) {
                continue;
            }
            if (!copy("{$default_dir}/{$theme_file}", "{$site_dir}/{$theme_file}")) {
                return;
            }
            chmod("{$site_dir}/{$theme_file}", 0777);
        }
        closedir($theme_dir);
    }
    // Rewrite the theme header.
    $stylelines = explode("\n", implode('', file("{$site_dir}/style.css")));
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        foreach ($stylelines as $line) {
            if (strpos($line, 'Theme Name:') !== false) {
                $line = 'Theme Name: ' . $theme_name;
            } elseif (strpos($line, 'Theme URI:') !== false) {
                $line = 'Theme URI: ' . __get_option('url');
            } elseif (strpos($line, 'Description:') !== false) {
                $line = 'Description: Your theme.';
            } elseif (strpos($line, 'Version:') !== false) {
                $line = 'Version: 1';
            } elseif (strpos($line, 'Author:') !== false) {
                $line = 'Author: You';
            }
            fwrite($f, $line . "\n");
        }
        fclose($f);
    }
    // Copy the images.
    umask(0);
    if (!mkdir("{$site_dir}/images", 0777)) {
        return false;
    }
    $images_dir = @opendir("{$default_dir}/images");
    if ($images_dir) {
        while (($image = readdir($images_dir)) !== false) {
            if (is_dir("{$default_dir}/images/{$image}")) {
                continue;
            }
            if (!copy("{$default_dir}/images/{$image}", "{$site_dir}/images/{$image}")) {
                return;
            }
            chmod("{$site_dir}/images/{$image}", 0777);
        }
        closedir($images_dir);
    }
}

WordPress Version: 4.3

/**
 * Creates a site theme from the default theme.
 *
 * {@internal Missing Long Description}}
 *
 * @since 1.5.0
 *
 * @param string $theme_name The name of the theme.
 * @param string $template   The directory name of the theme.
 * @return false|void
 */
function make_site_theme_from_default($theme_name, $template)
{
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
    // Copy files from the default theme to the site theme.
    //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
    $theme_dir = @opendir($default_dir);
    if ($theme_dir) {
        while (($theme_file = readdir($theme_dir)) !== false) {
            if (is_dir("{$default_dir}/{$theme_file}")) {
                continue;
            }
            if (!@copy("{$default_dir}/{$theme_file}", "{$site_dir}/{$theme_file}")) {
                return;
            }
            chmod("{$site_dir}/{$theme_file}", 0777);
        }
    }
    @closedir($theme_dir);
    // Rewrite the theme header.
    $stylelines = explode("\n", implode('', file("{$site_dir}/style.css")));
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        foreach ($stylelines as $line) {
            if (strpos($line, 'Theme Name:') !== false) {
                $line = 'Theme Name: ' . $theme_name;
            } elseif (strpos($line, 'Theme URI:') !== false) {
                $line = 'Theme URI: ' . __get_option('url');
            } elseif (strpos($line, 'Description:') !== false) {
                $line = 'Description: Your theme.';
            } elseif (strpos($line, 'Version:') !== false) {
                $line = 'Version: 1';
            } elseif (strpos($line, 'Author:') !== false) {
                $line = 'Author: You';
            }
            fwrite($f, $line . "\n");
        }
        fclose($f);
    }
    // Copy the images.
    umask(0);
    if (!mkdir("{$site_dir}/images", 0777)) {
        return false;
    }
    $images_dir = @opendir("{$default_dir}/images");
    if ($images_dir) {
        while (($image = readdir($images_dir)) !== false) {
            if (is_dir("{$default_dir}/images/{$image}")) {
                continue;
            }
            if (!@copy("{$default_dir}/images/{$image}", "{$site_dir}/images/{$image}")) {
                return;
            }
            chmod("{$site_dir}/images/{$image}", 0777);
        }
    }
    @closedir($images_dir);
}

WordPress Version: 4.2

/**
 * Creates a site theme from the default theme.
 *
 * {@internal Missing Long Description}}
 *
 * @since 1.5.0
 *
 * @param string $theme_name The name of the theme.
 * @param string $template   The directory name of the theme.
 * @return null|false
 */
function make_site_theme_from_default($theme_name, $template)
{
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
    // Copy files from the default theme to the site theme.
    //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
    $theme_dir = @opendir($default_dir);
    if ($theme_dir) {
        while (($theme_file = readdir($theme_dir)) !== false) {
            if (is_dir("{$default_dir}/{$theme_file}")) {
                continue;
            }
            if (!@copy("{$default_dir}/{$theme_file}", "{$site_dir}/{$theme_file}")) {
                return;
            }
            chmod("{$site_dir}/{$theme_file}", 0777);
        }
    }
    @closedir($theme_dir);
    // Rewrite the theme header.
    $stylelines = explode("\n", implode('', file("{$site_dir}/style.css")));
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        foreach ($stylelines as $line) {
            if (strpos($line, 'Theme Name:') !== false) {
                $line = 'Theme Name: ' . $theme_name;
            } elseif (strpos($line, 'Theme URI:') !== false) {
                $line = 'Theme URI: ' . __get_option('url');
            } elseif (strpos($line, 'Description:') !== false) {
                $line = 'Description: Your theme.';
            } elseif (strpos($line, 'Version:') !== false) {
                $line = 'Version: 1';
            } elseif (strpos($line, 'Author:') !== false) {
                $line = 'Author: You';
            }
            fwrite($f, $line . "\n");
        }
        fclose($f);
    }
    // Copy the images.
    umask(0);
    if (!mkdir("{$site_dir}/images", 0777)) {
        return false;
    }
    $images_dir = @opendir("{$default_dir}/images");
    if ($images_dir) {
        while (($image = readdir($images_dir)) !== false) {
            if (is_dir("{$default_dir}/images/{$image}")) {
                continue;
            }
            if (!@copy("{$default_dir}/images/{$image}", "{$site_dir}/images/{$image}")) {
                return;
            }
            chmod("{$site_dir}/images/{$image}", 0777);
        }
    }
    @closedir($images_dir);
}

WordPress Version: 4.1

/**
 * {@internal Missing Short Description}}
 *
 * {@internal Missing Long Description}}
 *
 * @since 1.5.0
 *
 * @param string $theme_name
 * @param string $template
 * @return null|false
 */
function make_site_theme_from_default($theme_name, $template)
{
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
    // Copy files from the default theme to the site theme.
    //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
    $theme_dir = @opendir($default_dir);
    if ($theme_dir) {
        while (($theme_file = readdir($theme_dir)) !== false) {
            if (is_dir("{$default_dir}/{$theme_file}")) {
                continue;
            }
            if (!@copy("{$default_dir}/{$theme_file}", "{$site_dir}/{$theme_file}")) {
                return;
            }
            chmod("{$site_dir}/{$theme_file}", 0777);
        }
    }
    @closedir($theme_dir);
    // Rewrite the theme header.
    $stylelines = explode("\n", implode('', file("{$site_dir}/style.css")));
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        foreach ($stylelines as $line) {
            if (strpos($line, 'Theme Name:') !== false) {
                $line = 'Theme Name: ' . $theme_name;
            } elseif (strpos($line, 'Theme URI:') !== false) {
                $line = 'Theme URI: ' . __get_option('url');
            } elseif (strpos($line, 'Description:') !== false) {
                $line = 'Description: Your theme.';
            } elseif (strpos($line, 'Version:') !== false) {
                $line = 'Version: 1';
            } elseif (strpos($line, 'Author:') !== false) {
                $line = 'Author: You';
            }
            fwrite($f, $line . "\n");
        }
        fclose($f);
    }
    // Copy the images.
    umask(0);
    if (!mkdir("{$site_dir}/images", 0777)) {
        return false;
    }
    $images_dir = @opendir("{$default_dir}/images");
    if ($images_dir) {
        while (($image = readdir($images_dir)) !== false) {
            if (is_dir("{$default_dir}/images/{$image}")) {
                continue;
            }
            if (!@copy("{$default_dir}/images/{$image}", "{$site_dir}/images/{$image}")) {
                return;
            }
            chmod("{$site_dir}/images/{$image}", 0777);
        }
    }
    @closedir($images_dir);
}

WordPress Version: 3.7

/**
 * {@internal Missing Short Description}}
 *
 * {@internal Missing Long Description}}
 *
 * @since 1.5.0
 *
 * @param unknown_type $theme_name
 * @param unknown_type $template
 * @return unknown
 */
function make_site_theme_from_default($theme_name, $template)
{
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
    // Copy files from the default theme to the site theme.
    //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
    $theme_dir = @opendir($default_dir);
    if ($theme_dir) {
        while (($theme_file = readdir($theme_dir)) !== false) {
            if (is_dir("{$default_dir}/{$theme_file}")) {
                continue;
            }
            if (!@copy("{$default_dir}/{$theme_file}", "{$site_dir}/{$theme_file}")) {
                return;
            }
            chmod("{$site_dir}/{$theme_file}", 0777);
        }
    }
    @closedir($theme_dir);
    // Rewrite the theme header.
    $stylelines = explode("\n", implode('', file("{$site_dir}/style.css")));
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        foreach ($stylelines as $line) {
            if (strpos($line, 'Theme Name:') !== false) {
                $line = 'Theme Name: ' . $theme_name;
            } elseif (strpos($line, 'Theme URI:') !== false) {
                $line = 'Theme URI: ' . __get_option('url');
            } elseif (strpos($line, 'Description:') !== false) {
                $line = 'Description: Your theme.';
            } elseif (strpos($line, 'Version:') !== false) {
                $line = 'Version: 1';
            } elseif (strpos($line, 'Author:') !== false) {
                $line = 'Author: You';
            }
            fwrite($f, $line . "\n");
        }
        fclose($f);
    }
    // Copy the images.
    umask(0);
    if (!mkdir("{$site_dir}/images", 0777)) {
        return false;
    }
    $images_dir = @opendir("{$default_dir}/images");
    if ($images_dir) {
        while (($image = readdir($images_dir)) !== false) {
            if (is_dir("{$default_dir}/images/{$image}")) {
                continue;
            }
            if (!@copy("{$default_dir}/images/{$image}", "{$site_dir}/images/{$image}")) {
                return;
            }
            chmod("{$site_dir}/images/{$image}", 0777);
        }
    }
    @closedir($images_dir);
}