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 needs "fontSize" and "fontFamily" properties in settings>typography to allow disabling of the controls while keeping the CSS #50330

Open
wwdes opened this issue May 4, 2023 · 1 comment
Labels
Developer Experience Ideas about improving block and theme developer experience [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [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 [Type] Enhancement A suggestion for improvement.

Comments

@wwdes
Copy link

wwdes commented May 4, 2023

What problem does this address?

This issue arises when programmatically changing editor settings via block_editor_settings_all filter.

Lets assume we want to only allow admins to be able to change text color by using themes palette. We can do this by creating a palette in settings>color>palette and setting settings>color>text to true. Then, we can filter the editor settings by hooking to block_editor_settings_all and changing settings>color>text to false for non-admin users. Works great, however, we can not do the same for font size or font family controls because the only way to enable/disable these controls in the editor is by having an array set in settings>typography>fontSizes/fontFamilies. If the only way to remove the control from the editor is by removing the array then the CSS will not be generated for the front end.

What is your proposed solution?

Add a setting similar to settings>color>text to settings->typography. Maybe call these setting fontSize and fontFamily. With these new settings we can keep the frontend CSS that is generated from the arrays but be able to programmatically control if a user should see the controls in the editor.

@wwdes wwdes changed the title theme.json needs "fontSize" and "fontFamily" properties in settings>typography to disable the controls but keep the CSS. theme.json needs "fontSize" and "fontFamily" properties in settings>typography to allow disabling the controls while keeping the CSS. May 4, 2023
@wwdes wwdes changed the title theme.json needs "fontSize" and "fontFamily" properties in settings>typography to allow disabling the controls while keeping the CSS. theme.json needs "fontSize" and "fontFamily" properties in settings>typography to allow disabling of the controls while keeping the CSS. May 4, 2023
@wwdes wwdes changed the title theme.json needs "fontSize" and "fontFamily" properties in settings>typography to allow disabling of the controls while keeping the CSS. theme.json needs "fontSize" and several other properties in settings>typography to allow disabling of the controls while keeping the CSS. May 4, 2023
@wwdes wwdes changed the title theme.json needs "fontSize" and several other properties in settings>typography to allow disabling of the controls while keeping the CSS. theme.json needs "fontSize" and "fontFamily" properties in settings>typography to allow disabling of the controls while keeping the CSS May 4, 2023
@ramonjd ramonjd added [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi Developer Experience Ideas about improving block and theme developer experience [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels May 8, 2023
@ramonjd
Copy link
Member

ramonjd commented May 9, 2023

👋

Hmm, this one is tricky.

If I understand correctly, there should be a way to hide the font size UI control while retaining the generated CSS from thefontSizes array.

Are you looking to remove the font sizes control from the site editor UI?

Would you be able to add steps/or example code you're using and the expected behaviour?

This issue might be related:

I tested some things in the post editor only using WordPress 6.2 (Gutenberg plugin disabled).

I separately assigned an empty array to fontSizes in theme.json,

		"typography": {
			"fontSizes": []
		},

and via the block_editor_settings_all hook (bear in mind the use of __experimentalFeatures might not be supported in the future):

add_filter( 'block_editor_settings_all', function( $settings ) {
    $settings['__experimentalFeatures']['typography']['fontSizes'] = [];
    return $settings;
} );

Both resulted in the font size UI control not being displayed:

Before After
Screenshot 2023-05-09 at 10 22 18 am Screenshot 2023-05-09 at 10 22 01 am

Using the hook only however, I see that the CSS vars and classes are still generated.

For example, I added a new font size to the 2023 theme in theme.json

				{
					"size": "20rem",
					"slug": "huge-mundo"
				}

And in the HTML I see the CSS preset vars and classes:

--wp--preset--font-size--huge-mundo: clamp(15rem, 15rem + ((1vw - 0.48rem) * 9.615), 20rem);
...
.has-huge-mundo-font-size{font-size: var(--wp--preset--font-size--huge-mundo) !important;}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience Ideas about improving block and theme developer experience [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [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 [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants