Repository navigation
Description
What problem does this address?
Currently, when switching from a classic theme to a block theme, widgets created in the classic theme aren't migrated over.
What is your proposed solution?
I could have sworn this was previously discussed, whether on a hallway hangout or in a core editor meeting, but I can't find any related issues so I decided to open this one up since this recently came up as a point of feedback. Since widgets "live" in the spaces that template parts fill, it makes the most sense for migration to happen in the form of generating template parts during migration:
- User has widgets in a classic theme.
- User switches to a block theme.
- Widget areas are converted to an equivalent template part with blocks (header, sidebar, etc). Anything already a block can remain as such and anything else could be converted to a legacy widget block thanks to the work done with the block widget editor.
If the user didn't want to use this, they could just ignore or delete the template part. If they switched back to a classic theme, it should preserve backwards compatibility. I don't know enough about the technical underpinnings here either way but wanted to get this documented regardless as it feels like a key area of refinement ahead of more folks adopting block themes in due time.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields✅ Done
- StatusShow more project fields✅ Done
Activity
mtias commentedon Jun 27, 2022
So I think you should be able to import an existing widget area content into a template part. We should probably place this in the block inspector for a template part as an "import", "use existing widget area" or "transform" action:
Considering widget areas can already have block content, this should be a fairly seamless transition. Once it's possible to use and edit template parts on non-block themes (#37943), this flow should be even more transparent.
noisysocks commentedon Jun 27, 2022
It might have been privately with me! 😅 Let me copy and paste some notes that I wrote in July 2021 about this subject:
Using CPTs
after_theme_switch. When we detect that user is moving from a classic theme to a block theme, or from a block theme to a classic theme, perform a migration.sidebar-1,footer-1, etc.), create a template part with the same ID for each widget area, runwidgetToBlockon each widget to create template part HTML.blockToWidgeton each block to create widgets.core/legacy-widgetblock.core/legacy-widgetblock.Pros
Cons
Using widget areas
dynamic_sidebar().InnerBlocks.EntityProviderto save changes to asidebarentity via the/wp/v2/widgetsAPI added in 5.8.core/legacy-widgetblock.Pros
Cons
dynamic_sidebar()and its ilk are a mess :) No "clean slate" for block themes.I lean towards the first approach because I feel it fits nicely with block themes and the site editor being a "fresh start" for WordPress that serves as a foundation for the next 15 years of growth. In the year 2030, do we want to be explaining to developers what a "widget" is? :)
But, this is all hypothetical. I think we should build a prototype of both approaches and see what happens.
noisysocks commentedon Jun 27, 2022
I like this idea of doing the migration on request as opposed to automatically on theme switch. It's more intentional—less surprises. Also, it caters for users who wish to ditch their existing widget areas and start fresh.
carlomanf commentedon Jun 28, 2022
@noisysocks There are a few issues I see with the "Using CPTs" proposal:
after_theme_switchhook doesn't fire for some reason (e.g. if the theme is switched using phpmyadmin)I think @mtias suggestion of importing widget areas on request is far more preferable, and I believe it also mirrors the ability to import menus to the navigation block.
That said, the lack of a solution to #31397 could still cause confusion for users about why it's easier to import a "legacy" widget area than to import an inactive template part. No equivalent problem exists for the navigation block because navigations are not tied to themes.
#31971 still looks like a workable first step to solving #31397 but was closed due to the PHP code being moved from the experimental plugin into core.
noisysocks commentedon Jun 29, 2022
Yeah, good call on #31397. I think it's another missing piece of the theme switching puzzle.
What makes sense to me right now is that both widget areas and template parts to stick around in the database after switching theme and for us to provide:
render_template_part()).mtias commentedon Jun 29, 2022
@noisysocks the function for the last part already exists — themes can use
block_template_part( $part )already in PHP. It's just lacking a UI to edit them.mtias commentedon Sep 10, 2022
I'm bumping the priority of this for visibility.
Mamaduka commentedon Nov 3, 2022
I just pushed my current progress for this feature #45509.