Skip to content

Conversation

@ALJ
Copy link

@ALJ ALJ commented Feb 15, 2023

Changes

This removes the WordPress-provided style panels on core/button and core/image blocks. This works towards the goal of removing opinionated defaults and unneeded editor options.

Edited to add: This image is old; the core/button block still has its styles.
image

@ALJ ALJ requested a review from braican February 15, 2023 19:29
@ALJ ALJ changed the title V2: Remove style panels on Button and Image core blocks v2: Remove style panels on Button and Image core blocks Feb 15, 2023
@ALJ ALJ changed the title v2: Remove style panels on Button and Image core blocks v2: Remove style panel on Image core block Feb 15, 2023
@ALJ
Copy link
Author

ALJ commented Feb 15, 2023

The PR has been updated to keep the fill and outline styles on the core/button block because WSK has styles baked in for the outline style.

Copy link
Member

@braican braican left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to get your take @ALJ: I know that default and rounded are the defaults that ship with core, but it seems somewhat fragile to hardcode these styles here. WordPress could potentially rename or add additional styles that would then render this code obsolete.

To truly kill the core styles, it may make sense to pull the styles right from the block object:

wp.blocks
  .getBlockType('core/image')
  .styles.forEach(({ name }) => wp.blocks.unregisterBlockStyle('core/image', name));

We could also extend this to more easily extend to other block types as well:

// Add whatever blocks we wanted to zero out here...
['core/image', 'core/quote', 'core/separator', 'core/table'].forEach(blockName => {
  wp.blocks
    .getBlockType(blockName)
    .styles.forEach(({ name: styleName }) => unregisterBlockStyle('core/image', styleName));
});

Since the plugin code runs before the theme's, this would still allow the theme to add their own block styles with either wp.blocks.registerBlockStyle or the server-side register_block_style().

@ALJ
Copy link
Author

ALJ commented Feb 16, 2023

@braican Yes! I think that's a way better path to go down! Specifically the second example where all core styles (except on core/button) are removed in one go. Just remove the hard-coded core/image in your second-to-last line:

['core/button', 'core/image', 'core/quote', 'core/separator', 'core/table'].forEach(blockName => {
  wp.blocks
    .getBlockType(blockName)
    .styles.forEach(({ name: styleName }) => unregisterBlockStyle(blockName, styleName));
});

Want me to bake that in to this PR?

@braican
Copy link
Member

braican commented Feb 16, 2023

@ALJ yeah let's do it in this PR.

@ALJ
Copy link
Author

ALJ commented Feb 21, 2023

@braican I adjusted the PR to the array loop way of doing things, BUT/AND I also added a final commit for your consideration: 3255662

It makes this whole core block style situation configurable in WSK ups-editorial.php. The default enables block styles on the core/button block only, since WSK has styles for that baked-in. In ups-editorial.php that will look like:

'enable_block_styles'  => array(
	'button',
),

Then, theme designers can either enable support for other core block styles, if desired, by adding more config array lines. Or, they can remove the default-on core/button block styles by emptying the enable_block_styles array in config.

@braican
Copy link
Member

braican commented Feb 23, 2023

@ALJ looks great. I just moved everything into the same domReady() callback (if we continue to add stuff there we can refactor into separate functions) and moved to using the .filter() array method for checking the block name config stuff. Also added some docs to the readme to account for our new parameter.

@braican braican merged commit f75bd89 into v2 Feb 23, 2023
@braican braican deleted the v2-remove-image-style-panel branch February 23, 2023 00:18
@braican braican changed the title v2: Remove style panel on Image core block v1: Remove style panel on Image core block Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants