WordPress / create-block-theme

A WordPress plugin to create block themes
https://wordpress.org/plugins/create-block-theme/
GNU General Public License v2.0
330 stars 52 forks source link

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

Closed oskosk closed 1 year ago

oskosk commented 1 year ago

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 commented 1 year ago

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

https://github.com/WordPress/create-block-theme/blob/031eee54a21e563e48b09e4dbc546138f36e5ad0/admin/class-create-block-theme-admin.php#L992-L993

eventually calling _remove_theme_attribute_in_block_template_content here: https://github.com/WordPress/create-block-theme/blob/031eee54a21e563e48b09e4dbc546138f36e5ad0/admin/class-create-block-theme-admin.php#L497

...and then added back here

https://github.com/WordPress/create-block-theme/blob/031eee54a21e563e48b09e4dbc546138f36e5ad0/admin/class-create-block-theme-admin.php#L1004

via

https://github.com/WordPress/create-block-theme/blob/031eee54a21e563e48b09e4dbc546138f36e5ad0/admin/class-create-block-theme-admin.php#L732-L734

This behavior was introduced in 1.6 with https://github.com/WordPress/create-block-theme/commit/6f0000205cee02cb9ab0e8f14873d07a5fb0a7ce as part of #213

matiasbenedetto commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

matiasbenedetto commented 1 year ago

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

oskosk commented 1 year ago

Thank so much @matiasbenedetto

mayuge3 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

Gulpman commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago
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 commented 7 months ago

I have the same issue now in 1.13.8