mirror of
https://gh.wpcy.net/https://github.com/WordPress/create-block-theme.git
synced 2026-04-25 12:02:15 +08:00
Co-authored-by: Vicente Canales <vicente.canales@automattic.com> Co-authored-by: Vicente Canales <1157901+vcanales@users.noreply.github.com> Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
35 lines
1,012 B
PHP
35 lines
1,012 B
PHP
<?php
|
|
|
|
if ( class_exists( 'ZipArchive' ) ) {
|
|
|
|
// This Class extends the ZipArchive class to add the theme slug as a base folder for all the files
|
|
class CBT_Zip_Archive extends ZipArchive {
|
|
|
|
private string $theme_slug;
|
|
private string $theme_folder;
|
|
|
|
function __construct( $theme_slug ) {
|
|
// If the original theme is in a subfolder the theme slug will be the last part of the path
|
|
$complete_slug = explode( DIRECTORY_SEPARATOR, $theme_slug );
|
|
$folder = end( $complete_slug );
|
|
$this->theme_folder = $folder;
|
|
}
|
|
|
|
function addFromStringToTheme( $name, $content ) {
|
|
$name = $this->theme_folder . '/' . $name;
|
|
return parent::addFromString( $name, $content );
|
|
}
|
|
|
|
function addFileToTheme( $filepath, $entryname ) {
|
|
$entryname = $this->theme_folder . '/' . $entryname;
|
|
return parent::addFile( $filepath, $entryname );
|
|
}
|
|
|
|
function addThemeDir( $dirname ) {
|
|
$dirname = $this->theme_folder . '/' . $dirname;
|
|
return parent::addEmptyDir( $dirname );
|
|
}
|
|
|
|
}
|
|
|
|
}
|