-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Theme Export: Remove default theme.json properties on export #39848
Theme Export: Remove default theme.json properties on export #39848
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works as described for me. I can see that all three properties are missing if they are set to true, and they are maintained if they are set to false. I can also see they're maintained regardless without this PR. Looks good!
It works well in my test, can be merged once the coding standard issue is fixed. -Should this be extended to include all defaults? It is unclear to me why these three defaults were selected. |
In my testing these were the only ones that were exported. We can add more if we notice others that are exported. |
Exports as:
|
Ah yes, I missed the false ones! Added a commit for them... |
🤔 With the latest update to the PR,
exports as
|
Thanks for testing! Try now... :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I'd like to understand this better before we commit to this path. Why are we removing these properties? Why are they set to true
?
This PR removes these properties on export if they are set to true.
I'm worried about this bit: the WP_Theme_JSON::get_data
method should be totally agnostic about the consumers that use it.
The benefit I see is that the JSON that comes OUT of the FSE matches the JSON that I put in. Meaning that if I wasn't explicit about setting a property on purpose then I don't want that property being explicitly set for me when it's exported. I think @carolinan 's examples above best demonstrates how current behavior doesn't mirror my expectations. The only concerns I have is that if I HAVE explicitly set something to the default value in the source theme.json then (with this change) I lose that explicitly set value when exported. I'm LESS concerned about that then I am properties being explicitly added. |
Absolutely, we need this. Can we first understand why this happens and then discussing the fix? I've pushed 5e67ff8 to use as baseline. |
I believe the reason it happen is that there are a bunch of deprecated theme supports that get opted in to here:
I suppose since these are the defaults then it makes sense that they are set when the theme.json is created. |
Yeah, there's something in WP_Theme_JSON_Resolver_Gutenberg::get_theme_data that needs to be looked at: get_default_block_editor_settings returns them set and then those are processed at get_from_editor_settings. Themes that don't have any theme support shouldn't have the need for these, which are already managed via the core |
34f38da
to
2202357
Compare
I added a commit to separate the theme supports out of get_theme_json so we can not add them on the export. What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since WordPress provides a default theme.json
maybe $tree = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data();
should have an "this is for export" flag that does not add defaults to it?
Later edit: this is what get_theme_data_without_supports is actually 🤦🏻 My question remains if exporting theme JSON should be a public thing. The mechanics should not be something exposed via a public static
method.
e5360c9
to
4e6474f
Compare
8b451bd
to
e05e892
Compare
Ben, what do you think of doing this instead of creating a new method? The rationale would be to avoid increasing the API surface of the resolver. * Andrei and I talked a bit about the current * Ironically, in the initial version of this class (see), the supports were a parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearing my "request for changes" review, as I feel this is in the good direction.
Second attempt to clear my "request for changes".
I don't think this will reduce the number of public methods, since |
We can't have it as a private method, it'd need to be protected. Otherwise, we can't overwrite it in a About the |
Thanks for the feedback, I've updated the approach. |
I don't think this is true. Exporting is not a UI thing, it should be a function of our JSON system itself. I can see exporting via command line as well for instance. I think having export functionality part of the public API is good, but the mechanics of the export should be private/protected. It's unfortunate that we are bound to using protected because of how WordPress Core development via Gutenberg is happening. We need to be as cler as possible via comments and docs that we don't support extensions of the JSON system right now. Edit: I don't think this is a blocker for this PR, the way it loos if we decide to add an |
What?
Three settings in theme.json are enabled by default:
This PR removes these properties on export if they are set to true.
Why?
We don't want to make these settings explicit if they are the default.
How?
We use
unset
on the theme.json for each property.Testing Instructions
Switch to a block theme
Export the theme from the site editor
Confirm that the properties above are missing.
Now try setting these properties to false in the theme.json file for the current theme
Confirm that the properties are maintained on export.
cc @WordPress/block-themers