If all of the add_theme_support() options from https://github.com/WordPress/gutenberg/issues/26901 are incorporated into theme.json, the only things a theme _must_ include in a functions.php file are its stylesheets.
For the sake of discussion, would it be possible (and a good idea) to allow block-based themes to define their front-end and editor stylesheets directly from within theme.json?
Will themes still need style sheets?
Many themes will still have stylesheets for things like transition and animations, etc. Global Styles won't cover all of those use cases.
But at a baseline, they'll need a style.css to house the standard DocBloc. WP won't currently recognize a theme without one. (I guess this could be changed. 馃槃)
In which case can we just always enqueue style.css without needing a line in functions.php? Other stylesheets could be @imported into style.css...
Yeah, currently, @imported stylesheets aren't loaded into the editor at all, so that would need to be changed. I filed https://github.com/WordPress/gutenberg/issues/26963 to discuss that point.
The issue with imported stylesheets is that a plugin would have no way to not enqueue a specific stylesheet.
But at a baseline, they'll need a style.css to house the standard DocBloc. WP won't currently recognize a theme without one. (I guess this could be changed. 馃槃)
I think we should allow the docblock to come from theme.json in order to allow a theme without any CSS and just with a theme.json file.
I think it would be a good idea to allow theme.json to load external stylesheets.
I imagine something like:
styles: {
"$handle": {
"src": "/assets/alignments-front.css",
"ver": (optional contrary to wp_enqueue_style defaults to the theme version instead of the core version WordPress version, we know that on theme.json we are in theme code and the theme version is more important).
"media": (optional same as wp_enqueue_style media)
}
}
Styles loaded in this way would behave exactly like the styles added in PHP, and plugins could interact with them in the same way.
cc: @mtias, @youknowriad
I don't know if this is a good idea, I need to think about it more but what I know is that the capabilities of theme.json are growing constantly and IMO before thinking of adding new features, let's make sure what we already have works perfectly. (For instance, do we really want to show all global styles UI like we have now, or do we want it to be controlled by the theme?)
I'd say the theme.json model (configs per block/context) is at odds with loading stylesheets that don't match those elements. I'd also refrain from trying to do this at the moment.
A different approach that was mentioned https://github.com/WordPress/gutenberg/issues/26901 is whether we can/should do some things automatically (like enqueueing block styles, etc) if a theme has a theme.json. I think this could be good to explore to understand the trade-offs better.
Cross-referencing this convo https://github.com/WordPress/theme-experiments/pull/81#discussion_r523098646 TLDR: if we want to remove the stylesheets, we have to update the logic for what WordPress core & WordPress theme directory considers a minimum theme.
Most helpful comment
I think it would be a good idea to allow theme.json to load external stylesheets.
I imagine something like:
Styles loaded in this way would behave exactly like the styles added in PHP, and plugins could interact with them in the same way.
cc: @mtias, @youknowriad