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

Restrict settings of Gutenberg editor #49493

Closed
JanLynx opened this issue Mar 30, 2023 · 2 comments
Closed

Restrict settings of Gutenberg editor #49493

JanLynx opened this issue Mar 30, 2023 · 2 comments
Labels
[Feature] Block Style Variations Issues or PRs that are related to the style variations for blocks [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Type] Enhancement A suggestion for improvement. [Type] Question Questions about the design or development of the editor.

Comments

@JanLynx
Copy link

JanLynx commented Mar 30, 2023

There are many ways of restricting the settings of the Gutenberg editor, but they all seem to be quite hacky.

In my special case, I want to remove the button's settings in Gutenberg. Therefore I use a javascript file.

wp.blocks.unregisterBlockStyle('core/button', 'fill'); wp.blocks.unregisterBlockStyle('core/button', 'outline');

Afterward, I register a new block inside a PHP file.

register_block_style( 'core/button', array( 'name' => 'primary-button', 'label' => __('Primary Button', 'textdomain'), 'is_default' => true, 'inline_style' => '.is-style-primary-button { color: blue !important; }', ) );

At least I use the Theme.json file to remove leftover settings I don't want to use.
"styles": { "elements": { "button": { "color": { "background": "#17a2b8", "text": "#ffffff", "custom": false }, "border": { "radius": false, "color": false, "style": false, "width": false }, "typography": { "fontSizes": [], "fontFamilies": [] } } } },

Is that the way of removing settings and styles? I used three different files... It feels not that good.

@mrfoxtalbot mrfoxtalbot added [Type] Enhancement A suggestion for improvement. [Feature] UI Components Impacts or related to the UI component system labels Apr 1, 2023
@skorasaurus skorasaurus added the [Type] Question Questions about the design or development of the editor. label Apr 3, 2023
@mirka mirka removed the [Feature] UI Components Impacts or related to the UI component system label Apr 12, 2023
@tellthemachines
Copy link
Contributor

There's some work towards adding the ability to register new style variations from theme.json in #49827, but it's still in early draft mode so at this stage it's hard to say when it'll ship. The idea is that in the future all these things should be configurable via theme.json.

For now, you can register the new block styles with JS too, using registerBlockStyles as shown in this doc.

As for the theme.json part, are you trying to disable some of the controls for the Button block? If so, the way to do that in theme.json would be

"settings": {
    "blocks": {
	"core/button": {
	     "border": {
		 "radius": false
		}
	  }
     }
}

Disabling controls works independently of block style variations; currently they can only be disabled at the block level.

@tellthemachines tellthemachines added the [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi label May 10, 2023
@fabiankaegy fabiankaegy added the [Feature] Block Style Variations Issues or PRs that are related to the style variations for blocks label Oct 24, 2023
@tellthemachines
Copy link
Contributor

This issue has been quiet for a year so I'm going to go ahead and close it. Further work to extend block style variations is tracked in #57537 in case that's of interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Style Variations Issues or PRs that are related to the style variations for blocks [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Type] Enhancement A suggestion for improvement. [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

No branches or pull requests

6 participants