WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.46k stars 4.18k forks source link

Integrating FSE with a classic theme in "hybrid" mode #46495

Closed abaicus closed 1 year ago

abaicus commented 1 year ago

What problem does this address?

There is currently no proper way to allow a user to select in a classic theme which templates he wants to use FSE on.

I have created a proof-of-concept theme that illustrates the hurdles I've encountered (it has a theme.json file because of https://github.com/WordPress/gutenberg/issues/45862). I am not sure if there is anything I might be missing or if there are some flaws in how the site editor works right now.

I'm trying to allow the user to enable FSE on different templates using some customizer controls (a thing that I'm guessing other theme authors might want to do in the future on their classic themes):

Customizer controls screenshot ![image](https://user-images.githubusercontent.com/15010186/207263419-080a2152-4466-43fb-b0ce-ab1340ff1caa.png)

Some good points are made in https://github.com/WordPress/gutenberg/issues/44224 regarding the blockers, the main one being the assumption that there must be an index.html file inside the theme, so the site editor is loaded.

I did manage to find a way around this, using the theme_file_path filter, but I don't think that this is a great solution. This will render the block-templates theme support useless, forcing the wp_is_block_theme function to return true. On the other hand, without short-circuiting the path, WordPress assumes that the theme is a block theme and always enables the site editor.

While what I have done in the POC theme seems to be working fine, there still are some flaws. Depending on which templates a user might select, the editor might not load and show a blank page.

For example, if the user has a static page setup under Settings > Reading, and only enables the 404 and Search FSE templates, the site editor automatically redirects to site-editor.php?postType=page&postId=<<Front_Page_ID>>. This would be fine in a traditional setup with a block theme, but in this case, it loads a blank page.

I should mention that the proper templates load on the front end.

If the editor loads site-editor.php?postType=wp_template instead, things would go fine, but as soon as you try to click the Site link in the navigation sidebar, a request for the same page happens, breaking the editor with no error in the console.

Classic theme users might still want to use the PHP templates that have customizer options for some of the cases (e.g., archive / single posts)

What is your proposed solution?

I understand why the redirect makes sense in the context of a block theme, but would there be any way to specify a fallback in the case of classic themes that would want to disable some templates explicitly?

Any help is appreciated!

Thank you!

carlomanf commented 1 year ago

This seems to be the same issue as #31633. Basically, the site editor can't yet handle PHP templates. I'm inclined to predict that the eventual solution would involve the much-prioritised "browse mode" and most resemble solution number 2 as listed in the linked issue.

annezazu commented 1 year ago

I agree that this is a duplicate. I'm going to close it out and encourage you to comment on https://github.com/WordPress/gutenberg/issues/31633! It helps keep discussions more concentrated and comprehensive when a problem hasn't yet been solved. If that feels incorrect or you'd like to keep this open, please just say so and we can continue the discussion.