make_site_theme_from_default

函数
make_site_theme_from_default ( $theme_name, $template )
参数
  • (string) $theme_name The name of the theme.
    Required:
  • (string) $template The directory name of the theme.
    Required:
返回值
  • (void|false)
定义位置
相关方法
make_site_theme_from_oldschoolmake_site_themeregister_theme_featurepreview_theme_ob_filterget_gmt_from_date
引入
1.5.0
弃用
-

make_site_theme_from_default: 这是WordPress中的一个函数,允许你在默认主题的基础上为多站点网络中的特定站点创建一个自定义主题。你可以使用这个函数为你的网络中的每个站点定制默认的主题。

从默认主题创建一个网站主题。

{@内部缺失的长描述}{@内部缺失的长描述}}。

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 );
	}
}

常见问题

FAQs
查看更多 >