-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from WordPress/add/subfolder-to-zip
Adding files to zip subfolder called as theme slug
- Loading branch information
Showing
4 changed files
with
64 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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 CbtZipArchive extends ZipArchive { | ||
|
||
private string $theme_slug; | ||
|
||
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 ); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters