Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added conditional check between saving and exporting to retain theme … #400

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions admin/create-theme/theme-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Theme_Templates {
/*
* Build a collection of templates and template-parts that should be exported (and modified) based on the given export_type and new slug
*/
public static function get_theme_templates( $export_type ) {
public static function get_theme_templates( $export_type, $zip = null ) {
$templates = get_block_templates();
$template_parts = get_block_templates( array(), 'wp_template_part' );
$exported_templates = array();
Expand All @@ -23,18 +23,21 @@ public static function get_theme_templates( $export_type ) {
$template = self::filter_theme_template(
$template,
$export_type,
$templates_path
$templates_path,
$zip
);
if ( $template ) {
$exported_templates[] = $template;
}
}

// NOTE: This is being saved and is not being exported as a zip file so, nullify the 4th paramater for later conditional check
foreach ( $template_parts as $template ) {
$template = self::filter_theme_template(
$template,
$export_type,
$parts_path
$parts_path,
null // This is not an exported zip
);
if ( $template ) {
$exported_parts[] = $template;
Expand All @@ -53,7 +56,7 @@ public static function get_theme_templates( $export_type ) {
* Templates not filtered out are modified based on the slug information provided and cleaned up
* to have the expected exported value.
*/
static function filter_theme_template( $template, $export_type, $path ) {
static function filter_theme_template( $template, $export_type, $path, $zip ) {
if ( 'theme' === $template->source && 'user' === $export_type ) {
return false;
}
Expand All @@ -71,7 +74,9 @@ static function filter_theme_template( $template, $export_type, $path ) {

// NOTE: Templates that reference template parts are exported with the 'theme' attribute.
// This is undesirable and should be removed.
$template->content = str_replace( ',"theme":"' . get_stylesheet() . '"', '', $template->content );
if ( ! empty( $zip ) ) {
$template->content = str_replace( ',"theme":"' . get_stylesheet() . '"', '', $template->content );
}

return $template;
}
Expand Down
2 changes: 1 addition & 1 deletion admin/create-theme/theme-zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function copy_theme_to_zip( $zip, $new_slug, $new_name ) {
* all = all templates no matter what
*/
public static function add_templates_to_zip( $zip, $export_type, $new_slug ) {
$theme_templates = Theme_Templates::get_theme_templates( $export_type );
$theme_templates = Theme_Templates::get_theme_templates( $export_type, $zip );

if ( $theme_templates->templates ) {
$zip->addEmptyDir( 'templates' );
Expand Down
Loading