Skip to content
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.json properties can't be overridden in PHP #33367

Closed
chrisvanpatten opened this issue Jul 12, 2021 · 6 comments
Closed

theme.json properties can't be overridden in PHP #33367

chrisvanpatten opened this issue Jul 12, 2021 · 6 comments
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Technical Feedback Needs testing from a developer perspective.

Comments

@chrisvanpatten
Copy link
Contributor

Description

theme.json properties cannot be (easily) overridden on the server-side due to the current implementation of filtering the block editor settings at a priority set to PHP_INT_MAX.

Being able to filter theme.json from PHP is a valuable way to ease the on-ramp to theme.json adoption; for example if a theme includes an existing settings panel for configuring colors and fonts, they may be able to use PHP to insert this configuration into the theme.json file until a global style editor is available to client users.

I would propose updating the filter to hook in at 999 which still conveys that the filter is intended to be run late while still allowing developers the option to adjust without a more complex unhook/rehook dance.

@chrisvanpatten chrisvanpatten added Needs Technical Feedback Needs testing from a developer perspective. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Feature] Full Site Editing Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Jul 12, 2021
@aristath
Copy link
Member

As far as I know, theme.json is not intended to run late, it's intended to override PHP.
The "old" method was using theme-supports which can be added at any time, anywhere. The theme.json file must override those theme-supports and therefore it must run last and not just late. I believe that's why it runs on PHP_INT_MAX...

@chrisvanpatten
Copy link
Contributor Author

@aristath I understand conceptually why it’s running late, it just makes the upgrade path unnecessarily complex if you’re migrating from, for example, custom settings pages.

@justintadlock
Copy link
Contributor

One other use case I have had in mind is add-on plugins (or even theme/child options). I'm kind of imagining scenarios where I might build a settings page for configuring certain defaults that are not covered by the Global Styles system. Being able to take custom plugin settings, hook in, and overrule theme.json values would be useful.

Is there even a hook that runs on both the front end and editor for this? I think block_editor_settings_all is just on the admin side, right?

@aristath
Copy link
Member

I believe there are plans to filter theme.json values so it can be overridden, but this has not yet been implemented.

@overclokk
Copy link

Even if you filter the theme.json the result will be sanitized with the schema from the core, but if you only want to have a dynamic theme.json you can follow this issue #33524 where I linked a library for generating the theme.json from a PHP array.

@Soean
Copy link
Member

Soean commented Sep 14, 2022

@Soean Soean closed this as completed Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Technical Feedback Needs testing from a developer perspective.
Projects
None yet
Development

No branches or pull requests

5 participants