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

Export: Getting Template part has been deleted or is unavailable: header after uploading to a new site #242

Closed
oskosk opened this issue Feb 21, 2023 · 18 comments · Fixed by #244
Assignees

Comments

@oskosk
Copy link

oskosk commented Feb 21, 2023

While working on a theme created from scratch with Create Block Theme I opted to export the theme using the Export the activated theme with user changes option:

image

I got a zip bundle and uploaded to another site. On that new site I visited the editor and was shown a message Template part has been deleted or is unavailable: header (footer as well).

image

Workaround

I noticed then that the templates/index.html file part of the bundle created by the export was referring to the header part like this:

<!-- wp:template-part {"slug":"header","tagName":"header","theme":"new blank theme"} /-->

... while my original file (the one generated from scratch) read:

<!-- wp:template-part {"slug":"header","tagName":"header"} /-->

After removing "theme":"new blank theme" the template worked properly loading the index part.

How to reproduce

  1. On a fresh site, install Create Block Theme
  2. Visit Appearance -> Create Block Theme
  3. Create a blank theme. Name it Le Theme.
  4. Activate the Theme in Appearance -> Themes
  5. Export the theme: Visit Appearance -> Create Block Theme and export the theme. Keep the downloaded bundle somewhere.
  6. Deactivate and delete the recently created theme Le Theme: Visit Appearance -> Create Block Theme, switch to Twenty Twenty-Three, then delete Le Theme.
  7. Upload and activate the downloaded zip from step 5.
  8. Visit the Editor.
  9. Confirm the part is missing. Expect to see Template part has been deleted or is unavailable: header and Template part has been deleted or is unavailable: footer messages.
@oskosk
Copy link
Author

oskosk commented Feb 22, 2023

Seems like during the process of exporting, the theme attribute is first removed here

function add_templates_to_zip( $zip, $export_type, $new_slug ) {
$theme_templates = $this->get_theme_templates( $export_type, $new_slug );

eventually calling _remove_theme_attribute_in_block_template_content here:

$template->content = _remove_theme_attribute_in_block_template_content( $template->content );

...and then added back here

$template_data = $this->make_template_images_local( $template );

via

case 'core/template-part':
$block = $this->add_theme_attr_to_template_part_block( $block );
break;

This behavior was introduced in 1.6 with 6f00002 as part of #213

@matiasbenedetto matiasbenedetto self-assigned this Feb 22, 2023
@matiasbenedetto
Copy link
Contributor

Thanks, @oskosk for the detailed description of the problem.
It seems like we are adding the theme key to the template part block in all the cases and it's only needed in some of them.
I'll submit a potential fix shortly.

@Retrofitterdk
Copy link

I’ve experienced this problem as well. It only seems to happen, when theme name is multiple words. Shortening theme name to one word fixed the problem.

@matiasbenedetto
Copy link
Contributor

matiasbenedetto commented Feb 22, 2023

This behavior was introduced in 1.6 with 6f00002 as part of #213

The problem is related to the fact that the characters used in the theme slug were not sanitized correctly, specifically the white spaces. That problem is pre-existent with those changes. Anyways is a good opportunity to fix this bug and simplify the code a little. A potential fix: #244

@oskosk
Copy link
Author

oskosk commented Feb 22, 2023

Alright , thanks!
Note that after reporting this issue I continued working with 1.5.1 the whole day without experiencing the issue. Also with a theme using a name with spaces

@matiasbenedetto
Copy link
Contributor

matiasbenedetto commented Feb 22, 2023

Note that after reporting this issue I continued working with 1.5.1 the whole day without experiencing the issue. Also with a theme using a name with spaces

Yep, but that's because in 1.5.1 in we remove the theme key in the template parts linked from templates. In 1.6.0 no, so the template parts were linked like this (following your example theme name): "theme":"le theme" instead of "theme":"letheme"

@Thelmachido
Copy link

The same seems to happen when you try to create a clone of the TT3 theme, this was reported on this Forum review:

Screenshot 2023-02-23 at 16 34 12

Thanks, @matiasbenedetto for looking into this.

@Thelmachido
Copy link

More reports from the Create Block Theme forum: https://wordpress.org/support/topic/bug-exporting-templates-uses-wrong-theme-key/

@matiasbenedetto
Copy link
Contributor

The fix (#244) was merged and released in version 1.6.1 of the plugin. It should be working as expected now.

@oskosk
Copy link
Author

oskosk commented Feb 27, 2023

Thank so much @matiasbenedetto

@mayuge3
Copy link

mayuge3 commented Mar 4, 2023

Hello, @matiasbenedetto
This issue was fixed in 1.6.1, but it seems to happen again in 1.6.2.

I faced the same issue when I export, clone, overwrite the TT3 theme.

162
162code

@matiasbenedetto
Copy link
Contributor

matiasbenedetto commented Mar 5, 2023

This recent refactor #237 wiped out the fix added in #244, that's the reason for this issue happening again in 1.6.2.
I'm adding again the changes from #244 to #259.

@matiasbenedetto
Copy link
Contributor

This issue was fixed in 1.6.1, but it seems to happen again in 1.6.2.

This regression should be fixed in the 1.6.3 version.

@mayuge3
Copy link

mayuge3 commented Mar 6, 2023

It's fixed and works fine on version 1.6.3. Thank you!

@Gulpman
Copy link

Gulpman commented May 11, 2023

Hi,
I am having the same issue with version 1.9.0.

I have Spectra One Theme installed and am using the Spectra Plugin so I do not know if it maybe is related to those.
After creating a child theme from Spectra One with the Create Block Theme plugin I get the same error message about missing or deleted header and footer.
Manually removing template parts and adding new ones pointing to header and footer fixed the issue.

Also the preview picture of the theme is missing in the themes overview, after creating the child theme.

Apart from that everything is working flawlessly as fas as I can see.

Best
Sascha

@odyn
Copy link

odyn commented Jul 17, 2023

Also having problems with 1.13.1 and Wordpress 6.2.2. And in my case changing the theme name in htmls didn't help.

I'm getting confused where the template parts with changes are actually stored - is it the html files, is it the database ... together with using WPML for translation this is getting a bit out of hands.

@ashrudral
Copy link

Screenshot 2023-07-28 163829 I am still getting the issue of "Template part has been missing or unavailable". I am on WP 6.2 with the create block theme version 1.13.1. I tried with Spectra and blockbase theme, same error.

@lipematt
Copy link

I have the same issue now in 1.13.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants