-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Global styles: let plugins register global styles with a plugin.json file #20449
Comments
I'd like to work on a PR for this, but have a few questions about the implementation:
|
@nickcernis Personally I like |
Thanks for taking the time and send feedback, Nick. We're in the very early stages, so we're particularly interested in hearing use cases like this. The use case of third-party blocks is definitely in our minds, so ace for commenting on that! I can share a few of our current operating assumptions that perhaps are relevant for this: Third-parties (themes, plugins) can't declare new variables. The reason is the potential design fragmentation caused by every block declaring its own different variables would lead to a bad experience for users. It'd be opt-in. Otherwise, it can potentially break existing themes. There are other things you touch upon that are on our radar, such as how blocks (core and third-party) would declare their "styling hooks" or "public style API", how they should provide defaults, how would UI controls be bound to block declarations, etc. Those are our current areas of work! We need to solve a few things before being able to commit to a specific format to set things up. |
Thanks for the feedback, @nosolosw!
Ah, so the current plan is for WP core to “bless” a group of global style settings and hard-code a UI for each setting, without making it filterable or extensible.
Thanks for highlighting these initiatives. It seems natural that themes and plugins will want to introduce additional styling controls without having to reinvent the global styles UI and APIs, just as it sounds like blocks will be able to do. |
We are going to consider some extension points. However, before crossing that bridge, we want to stabilize the essential components & mechanics. That's why use cases are super helpful at this moment! They help us to bring clarity around the different pieces we're building. |
I'd like to follow up on this. It seems odd that a plugin can't define it's own "theme.json" - or plugin.json - to set template parts, templates and other styles. For instance, if I want to register a post type "books" using 5.9+, I should do this in a plugin (and not the theme - per WP public directory requirements you can't have a CPT registered in a theme) but if I register a CPT in my plugin, I have no way to assign template parts nor templates to the CPT. I'm only allowed to use the templates registered in the theme. CPTs in general have been left out of the recent 5.9 and this is a HUGE issue as tons of us rely on using CPTs for our client sites (portfolios, books, courses, etc.). |
It seems we made a lot of progress to address this issue lately. The |
The excellent Global Styles proposal assumes that:
experimental-default-global-styles.json
).theme.json
in their theme root.Plugin developers do not currently fit into this vision, as far as I can see. But global styles will be very useful to them too.
Proposal
plugin.json
(or similar), in the same format as the existingtheme.json
for themes.gutenberg_experimental_global_styles_has_theme_support()
to make global styles available to end users if:Stories
As a plugin developer, I want to add named styles that theme developers can override and users can adjust.
I want to ensure these global styles are available to users even if the theme does not contain a theme.json, because a user might still want to adjust my plugin styles even if the theme developer does not.
As a theme developer, I want to be able to see which styles a plugin developer thinks are public and safe for theme developers to override, and override the styles in an easy way.
As an end user, I want to adjust the appearance of a plugin in a way that feels native to WordPress, without having to learn the plugin developer's styling UI if they even offer one.
Scenario
My goal is to make styling adjustments easier for blocks that my plugin provides.
I add a
plugin.json
to my plugin root:WordPress loads this between core styles and theme styles, automatically prepending CSS vars with my plugin slug.
Now theme styles can override my plugin styles by:
(WP-CLI or other tooling could potentially automate 1 and 2 via
wp global-styles import plugin-slug theme-slug
or similar.)And users can override via the admin area.
No-one has to work out how to override my plugin's CSS, which I’m now free to refactor as long as I maintain the global vars I exposed via my
plugin.json
, which represents my plugin's “public styling API”.To adjust the vars, I can update
plugin.json
and ship a new version of the plugin.If/when global styling is extended to include block properties that relate to visual styling instead of just CSS properties, theme developers will also be able to override default properties for my blocks to suit their theme.
Implementation
The existing global-styles.php loader could be adjusted to import the
plugin.json
file into the tree for each active plugin.Alternatively, plugins could be asked to call a function such as
register_global_styles()
that defaults toplugin.json
or specify a path to their JSON file in case they are using aplugin.json
file for another purpose already.The text was updated successfully, but these errors were encountered: