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

Gutenberg 11.9: Not possible to filter the global style settings anymore #36330

Closed
briceduclos opened this issue Nov 8, 2021 · 7 comments
Closed
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed.

Comments

@briceduclos
Copy link

Description

Before Gutenberg 11.9, it was possible to filter the block editor settings using this solution #27504 (comment) posted by @oandregal.

Testing Gutenberg 11.9 RC-3, this solution doesn't work anymore. So, how can we filter the editor settings?

Thanks

Step-by-step reproduction instructions

Use the filter below to modify the editor settings:
add_filter( 'block_editor_settings_all', 'custom_global_styles_settings', PHP_INT_MAX );

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@Mamaduka
Copy link
Member

Mamaduka commented Nov 9, 2021

Hi, @briceduclos

We tested this during the Core Editor Triage session today, and the block_editor_settings_all filter works expected.

The issue might be with individual settings. Can you share the example code you're using to filter those settings?

Thanks

@Mamaduka Mamaduka added [Feature] Extensibility The ability to extend blocks or the editing experience [Status] Needs More Info Follow-up required in order to be actionable. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Nov 9, 2021
@oandregal
Copy link
Member

Hi Brice, by any chance, are you filtering some of the theme settings we retrofit into theme.json? These are custom-line-height, custom-spacing, custom-units, disable-custom-colors, disable-custom-font-sizes, disable-custom-gradients, editor-color-palette, editor-font-sizes, editor-gradient-presets, experimental-link-color.

If you want to filter one of those settings from the theme the recommended way is to use after_theme_setup instead of the block settings filter. There was a bug in how we retrofit these settings in WordPress 5.8 that we've fixed #36054 for WordPress 5.9.

If you are filtering any other setting, would your specific use case?

@briceduclos
Copy link
Author

Thanks for your replies. I'm using the following code:

function custom_global_styles_settings( $settings ) {

    if ( isset( $settings['__experimentalGlobalStylesBaseConfig'] ) ) {
        $settings['__experimentalGlobalStylesBaseConfig']['settings']['layout']['contentSize'] = '800px';
    }
    
    if ( isset( $settings['__experimentalFeatures'] ) ) {
        $settings['__experimentalFeatures']['layout']['contentSize'] = '800px';
    }   
    
    return $settings;
}
add_filter( 'block_editor_settings_all', 'custom_global_styles_settings', PHP_INT_MAX  );

I've just realized it still works in the page/post editor, but it doesn't work in the site editor (Appearance > Editor).

@briceduclos
Copy link
Author

Hi @Mamaduka, @oandregal,

I've found out that Gutenberg 11.9 doesn't use $settings['__experimentalGlobalStylesBaseConfig'] anymore. Is there a solution?

Thanks.

@oandregal
Copy link
Member

Hey @briceduclos the code above still works for filtering __experimentalFeatures.

__experimentalGlobalStylesBaseConfig has been removed in favor of the rest API endpoint introduced at #35985 The REST API already has a few filters in place, so it should be doable. I don't remember which one would be appropriate off the top of my head. I can try to investigate and post an example here after the betas are in a good place. Please, be welcome to share if you do it before.

It's also worth noting that most of these settings/data flows are experimental until the API is fully matured and changes are expected. The names of the settings communicate that.

@github-actions
Copy link

github-actions bot commented Dec 9, 2021

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Dec 9, 2021
@devinmaeztri devinmaeztri removed the [Status] Needs More Info Follow-up required in order to be actionable. label Jan 12, 2022
@Thelmachido
Copy link

Hi @briceduclos it looks like @oandregal gave more information about the issue you were having and how to resolve that.

I believe it is safe to mark this as resolved, if the suggested Rest API isn't working as expected please feel free to open the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed.
Projects
None yet
Development

No branches or pull requests

5 participants