make_site_theme_from_oldschool()
最后更新于:2021-11-27 14:40:28
make_site_theme_from_oldschool( string$theme_name, string$template)Creates a site theme from an existing theme.
参数
- $theme_name
-
(string) (Required) The name of the theme.
- $template
-
(string) (Required) The directory name of the theme.
响应
(bool)
源文件
文件: gc-admin/includes/upgrade.php
function make_site_theme_from_oldschool( $theme_name, $template ) {
$home_path = get_home_path();
$site_dir = GC_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 GC files are copied.
*/
$files = array(
'index.php' => 'index.php',
'gc-layout.css' => 'style.css',
'gc-comments.php' => 'comments.php',
'gc-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, 'GC_USE_THEMES' ) !== false ) {
if ( ! copy( GC_CONTENT_DIR . '/themes/' . GC_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.*gc-blog-header/', $line ) ) {
$line = '//' . $line;
}
// Update stylesheet references.
$line = str_replace( "<?php echo __get_option('siteurl'); ?>/gc-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line );
// Update comments template inclusion.
$line = str_replace( "<?php include(ABSPATH . 'gc-comments.php'); ?>", '<?php comments_template(); ?>', $line );
fwrite( $f, "{$line}n" );
}
fclose( $f );
}
}
// Add a theme header.
$header = "/*nTheme Name: $theme_namenTheme URI: " . __get_option( 'siteurl' ) . "nDescription: A theme automatically created by the update.nVersion: 1.0nAuthor: Moin*/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;
}