make_site_theme_from_oldschool

The timeline below displays how wordpress function make_site_theme_from_oldschool 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 an existing 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 bool
 */
function make_site_theme_from_oldschool($theme_name, $template)
{
    $home_path = get_home_path();
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
    if (!file_exists("{$home_path}/index.php")) {
        return false;
    }
    /*
     * Copy files from the old locations to the site theme.
     * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
     */
    $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
    foreach ($files as $oldfile => $newfile) {
        if ('index.php' === $oldfile) {
            $oldpath = $home_path;
        } else {
            $oldpath = ABSPATH;
        }
        // Check to make sure it's not a new index.
        if ('index.php' === $oldfile) {
            $index = implode('', file("{$oldpath}/{$oldfile}"));
            if (str_contains($index, 'WP_USE_THEMES')) {
                if (!copy("{$default_dir}/{$oldfile}", "{$site_dir}/{$newfile}")) {
                    return false;
                }
                // Don't copy anything.
                continue;
            }
        }
        if (!copy("{$oldpath}/{$oldfile}", "{$site_dir}/{$newfile}")) {
            return false;
        }
        chmod("{$site_dir}/{$newfile}", 0777);
        // Update the blog header include in each file.
        $lines = explode("\n", implode('', file("{$site_dir}/{$newfile}")));
        if ($lines) {
            $f = fopen("{$site_dir}/{$newfile}", 'w');
            foreach ($lines as $line) {
                if (preg_match('/require.*wp-blog-header/', $line)) {
                    $line = '//' . $line;
                }
                // Update stylesheet references.
                $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
                // Update comments template inclusion.
                $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", '<?php comments_template(); ?>', $line);
                fwrite($f, "{$line}\n");
            }
            fclose($f);
        }
    }
    // Add a theme header.
    $header = "/*\n" . "Theme Name: {$theme_name}\n" . 'Theme URI: ' . __get_option('siteurl') . "\n" . "Description: A theme automatically created by the update.\n" . "Version: 1.0\n" . "Author: Moi\n" . "*/\n";
    $stylelines = file_get_contents("{$site_dir}/style.css");
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        fwrite($f, $header);
        fwrite($f, $stylelines);
        fclose($f);
    }
    return true;
}

WordPress Version: 5.4

/**
 * Creates a site theme from an existing 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 bool
 */
function make_site_theme_from_oldschool($theme_name, $template)
{
    $home_path = get_home_path();
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    if (!file_exists("{$home_path}/index.php")) {
        return false;
    }
    /*
     * Copy files from the old locations to the site theme.
     * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
     */
    $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
    foreach ($files as $oldfile => $newfile) {
        if ('index.php' === $oldfile) {
            $oldpath = $home_path;
        } else {
            $oldpath = ABSPATH;
        }
        // Check to make sure it's not a new index.
        if ('index.php' === $oldfile) {
            $index = implode('', file("{$oldpath}/{$oldfile}"));
            if (strpos($index, 'WP_USE_THEMES') !== false) {
                if (!copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "{$site_dir}/{$newfile}")) {
                    return false;
                }
                // Don't copy anything.
                continue;
            }
        }
        if (!copy("{$oldpath}/{$oldfile}", "{$site_dir}/{$newfile}")) {
            return false;
        }
        chmod("{$site_dir}/{$newfile}", 0777);
        // Update the blog header include in each file.
        $lines = explode("\n", implode('', file("{$site_dir}/{$newfile}")));
        if ($lines) {
            $f = fopen("{$site_dir}/{$newfile}", 'w');
            foreach ($lines as $line) {
                if (preg_match('/require.*wp-blog-header/', $line)) {
                    $line = '//' . $line;
                }
                // Update stylesheet references.
                $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
                // Update comments template inclusion.
                $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", '<?php comments_template(); ?>', $line);
                fwrite($f, "{$line}\n");
            }
            fclose($f);
        }
    }
    // Add a theme header.
    $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";
    $stylelines = file_get_contents("{$site_dir}/style.css");
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        fwrite($f, $header);
        fwrite($f, $stylelines);
        fclose($f);
    }
    return true;
}

WordPress Version: 5.3

/**
 * Creates a site theme from an existing 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 bool
 */
function make_site_theme_from_oldschool($theme_name, $template)
{
    $home_path = get_home_path();
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    if (!file_exists("{$home_path}/index.php")) {
        return false;
    }
    /*
     * Copy files from the old locations to the site theme.
     * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
     */
    $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
    foreach ($files as $oldfile => $newfile) {
        if ($oldfile == 'index.php') {
            $oldpath = $home_path;
        } else {
            $oldpath = ABSPATH;
        }
        // Check to make sure it's not a new index.
        if ($oldfile == 'index.php') {
            $index = implode('', file("{$oldpath}/{$oldfile}"));
            if (strpos($index, 'WP_USE_THEMES') !== false) {
                if (!copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "{$site_dir}/{$newfile}")) {
                    return false;
                }
                // Don't copy anything.
                continue;
            }
        }
        if (!copy("{$oldpath}/{$oldfile}", "{$site_dir}/{$newfile}")) {
            return false;
        }
        chmod("{$site_dir}/{$newfile}", 0777);
        // Update the blog header include in each file.
        $lines = explode("\n", implode('', file("{$site_dir}/{$newfile}")));
        if ($lines) {
            $f = fopen("{$site_dir}/{$newfile}", 'w');
            foreach ($lines as $line) {
                if (preg_match('/require.*wp-blog-header/', $line)) {
                    $line = '//' . $line;
                }
                // Update stylesheet references.
                $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
                // Update comments template inclusion.
                $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", '<?php comments_template(); ?>', $line);
                fwrite($f, "{$line}\n");
            }
            fclose($f);
        }
    }
    // Add a theme header.
    $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";
    $stylelines = file_get_contents("{$site_dir}/style.css");
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        fwrite($f, $header);
        fwrite($f, $stylelines);
        fclose($f);
    }
    return true;
}

WordPress Version: 5.1

/**
 * Creates a site theme from an existing 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 bool
 */
function make_site_theme_from_oldschool($theme_name, $template)
{
    $home_path = get_home_path();
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    if (!file_exists("{$home_path}/index.php")) {
        return false;
    }
    /*
     * Copy files from the old locations to the site theme.
     * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
     */
    $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
    foreach ($files as $oldfile => $newfile) {
        if ($oldfile == 'index.php') {
            $oldpath = $home_path;
        } else {
            $oldpath = ABSPATH;
        }
        // Check to make sure it's not a new index.
        if ($oldfile == 'index.php') {
            $index = implode('', file("{$oldpath}/{$oldfile}"));
            if (strpos($index, 'WP_USE_THEMES') !== false) {
                if (!@copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "{$site_dir}/{$newfile}")) {
                    return false;
                }
                // Don't copy anything.
                continue;
            }
        }
        if (!@copy("{$oldpath}/{$oldfile}", "{$site_dir}/{$newfile}")) {
            return false;
        }
        chmod("{$site_dir}/{$newfile}", 0777);
        // Update the blog header include in each file.
        $lines = explode("\n", implode('', file("{$site_dir}/{$newfile}")));
        if ($lines) {
            $f = fopen("{$site_dir}/{$newfile}", 'w');
            foreach ($lines as $line) {
                if (preg_match('/require.*wp-blog-header/', $line)) {
                    $line = '//' . $line;
                }
                // Update stylesheet references.
                $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
                // Update comments template inclusion.
                $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", '<?php comments_template(); ?>', $line);
                fwrite($f, "{$line}\n");
            }
            fclose($f);
        }
    }
    // Add a theme header.
    $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";
    $stylelines = file_get_contents("{$site_dir}/style.css");
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        fwrite($f, $header);
        fwrite($f, $stylelines);
        fclose($f);
    }
    return true;
}

WordPress Version: 4.2

/**
 * Creates a site theme from an existing 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 bool
 */
function make_site_theme_from_oldschool($theme_name, $template)
{
    $home_path = get_home_path();
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    if (!file_exists("{$home_path}/index.php")) {
        return false;
    }
    /*
     * Copy files from the old locations to the site theme.
     * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
     */
    $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
    foreach ($files as $oldfile => $newfile) {
        if ($oldfile == 'index.php') {
            $oldpath = $home_path;
        } else {
            $oldpath = ABSPATH;
        }
        // Check to make sure it's not a new index.
        if ($oldfile == 'index.php') {
            $index = implode('', file("{$oldpath}/{$oldfile}"));
            if (strpos($index, 'WP_USE_THEMES') !== false) {
                if (!@copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "{$site_dir}/{$newfile}")) {
                    return false;
                }
                // Don't copy anything.
                continue;
            }
        }
        if (!@copy("{$oldpath}/{$oldfile}", "{$site_dir}/{$newfile}")) {
            return false;
        }
        chmod("{$site_dir}/{$newfile}", 0777);
        // Update the blog header include in each file.
        $lines = explode("\n", implode('', file("{$site_dir}/{$newfile}")));
        if ($lines) {
            $f = fopen("{$site_dir}/{$newfile}", 'w');
            foreach ($lines as $line) {
                if (preg_match('/require.*wp-blog-header/', $line)) {
                    $line = '//' . $line;
                }
                // Update stylesheet references.
                $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
                // Update comments template inclusion.
                $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", "<?php comments_template(); ?>", $line);
                fwrite($f, "{$line}\n");
            }
            fclose($f);
        }
    }
    // Add a theme header.
    $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";
    $stylelines = file_get_contents("{$site_dir}/style.css");
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        fwrite($f, $header);
        fwrite($f, $stylelines);
        fclose($f);
    }
    return true;
}

WordPress Version: 4.1

/**
 * {@internal Missing Short Description}}
 *
 * {@internal Missing Long Description}}
 *
 * @since 1.5.0
 *
 * @param string $theme_name
 * @param string $template
 * @return bool
 */
function make_site_theme_from_oldschool($theme_name, $template)
{
    $home_path = get_home_path();
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    if (!file_exists("{$home_path}/index.php")) {
        return false;
    }
    /*
     * Copy files from the old locations to the site theme.
     * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
     */
    $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
    foreach ($files as $oldfile => $newfile) {
        if ($oldfile == 'index.php') {
            $oldpath = $home_path;
        } else {
            $oldpath = ABSPATH;
        }
        // Check to make sure it's not a new index.
        if ($oldfile == 'index.php') {
            $index = implode('', file("{$oldpath}/{$oldfile}"));
            if (strpos($index, 'WP_USE_THEMES') !== false) {
                if (!@copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "{$site_dir}/{$newfile}")) {
                    return false;
                }
                // Don't copy anything.
                continue;
            }
        }
        if (!@copy("{$oldpath}/{$oldfile}", "{$site_dir}/{$newfile}")) {
            return false;
        }
        chmod("{$site_dir}/{$newfile}", 0777);
        // Update the blog header include in each file.
        $lines = explode("\n", implode('', file("{$site_dir}/{$newfile}")));
        if ($lines) {
            $f = fopen("{$site_dir}/{$newfile}", 'w');
            foreach ($lines as $line) {
                if (preg_match('/require.*wp-blog-header/', $line)) {
                    $line = '//' . $line;
                }
                // Update stylesheet references.
                $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
                // Update comments template inclusion.
                $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", "<?php comments_template(); ?>", $line);
                fwrite($f, "{$line}\n");
            }
            fclose($f);
        }
    }
    // Add a theme header.
    $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";
    $stylelines = file_get_contents("{$site_dir}/style.css");
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        fwrite($f, $header);
        fwrite($f, $stylelines);
        fclose($f);
    }
    return true;
}

WordPress Version: 4.0

/**
 * {@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_oldschool($theme_name, $template)
{
    $home_path = get_home_path();
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    if (!file_exists("{$home_path}/index.php")) {
        return false;
    }
    /*
     * Copy files from the old locations to the site theme.
     * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
     */
    $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
    foreach ($files as $oldfile => $newfile) {
        if ($oldfile == 'index.php') {
            $oldpath = $home_path;
        } else {
            $oldpath = ABSPATH;
        }
        // Check to make sure it's not a new index.
        if ($oldfile == 'index.php') {
            $index = implode('', file("{$oldpath}/{$oldfile}"));
            if (strpos($index, 'WP_USE_THEMES') !== false) {
                if (!@copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "{$site_dir}/{$newfile}")) {
                    return false;
                }
                // Don't copy anything.
                continue;
            }
        }
        if (!@copy("{$oldpath}/{$oldfile}", "{$site_dir}/{$newfile}")) {
            return false;
        }
        chmod("{$site_dir}/{$newfile}", 0777);
        // Update the blog header include in each file.
        $lines = explode("\n", implode('', file("{$site_dir}/{$newfile}")));
        if ($lines) {
            $f = fopen("{$site_dir}/{$newfile}", 'w');
            foreach ($lines as $line) {
                if (preg_match('/require.*wp-blog-header/', $line)) {
                    $line = '//' . $line;
                }
                // Update stylesheet references.
                $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
                // Update comments template inclusion.
                $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", "<?php comments_template(); ?>", $line);
                fwrite($f, "{$line}\n");
            }
            fclose($f);
        }
    }
    // Add a theme header.
    $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";
    $stylelines = file_get_contents("{$site_dir}/style.css");
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        fwrite($f, $header);
        fwrite($f, $stylelines);
        fclose($f);
    }
    return true;
}

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_oldschool($theme_name, $template)
{
    $home_path = get_home_path();
    $site_dir = WP_CONTENT_DIR . "/themes/{$template}";
    if (!file_exists("{$home_path}/index.php")) {
        return false;
    }
    // Copy files from the old locations to the site theme.
    // TODO: This does not copy arbitrary include dependencies. Only the
    // standard WP files are copied.
    $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
    foreach ($files as $oldfile => $newfile) {
        if ($oldfile == 'index.php') {
            $oldpath = $home_path;
        } else {
            $oldpath = ABSPATH;
        }
        if ($oldfile == 'index.php') {
            // Check to make sure it's not a new index
            $index = implode('', file("{$oldpath}/{$oldfile}"));
            if (strpos($index, 'WP_USE_THEMES') !== false) {
                if (!@copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "{$site_dir}/{$newfile}")) {
                    return false;
                }
                continue;
                // Don't copy anything
            }
        }
        if (!@copy("{$oldpath}/{$oldfile}", "{$site_dir}/{$newfile}")) {
            return false;
        }
        chmod("{$site_dir}/{$newfile}", 0777);
        // Update the blog header include in each file.
        $lines = explode("\n", implode('', file("{$site_dir}/{$newfile}")));
        if ($lines) {
            $f = fopen("{$site_dir}/{$newfile}", 'w');
            foreach ($lines as $line) {
                if (preg_match('/require.*wp-blog-header/', $line)) {
                    $line = '//' . $line;
                }
                // Update stylesheet references.
                $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
                // Update comments template inclusion.
                $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", "<?php comments_template(); ?>", $line);
                fwrite($f, "{$line}\n");
            }
            fclose($f);
        }
    }
    // Add a theme header.
    $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";
    $stylelines = file_get_contents("{$site_dir}/style.css");
    if ($stylelines) {
        $f = fopen("{$site_dir}/style.css", 'w');
        fwrite($f, $header);
        fwrite($f, $stylelines);
        fclose($f);
    }
    return true;
}