Share examples of using the new filter blockEditor.useSetting.before #38
Replies: 5 comments 2 replies
-
I would like to pick up this topic for the Developers Blog. |
Beta Was this translation helpful? Give feedback.
-
@ndiego: @ingeniumed and I put together a basic example of the const { getBlockName, getBlockParents } = wp.data.select('core/block-editor');
wp.hooks.addFilter(
'blockEditor.useSetting.before',
'test/disable-heading-text-color-in-media-text',
(result, path, clientId, blockName) => {
if (blockName === 'core/heading') {
const blockParents = getBlockParents(clientId, true);
const inMediaText = blockParents.some((ancestorId) => getBlockName(ancestorId) === 'core/media-text');
if (inMediaText && path === 'color.text') {
// Disable text color selection
result = false;
}
}
return result;
}
); Here's what that looks like in action: There's probably other good ways to use this hook that aren't governance related, but this example can be used to show how the hook can be used to accomplish something not possible with |
Beta Was this translation helpful? Give feedback.
-
A Dev Note is in the works on this: Customize settings for any block in WordPress 6.2 |
Beta Was this translation helpful? Give feedback.
-
This topic discussion is now locked. Please add further comment to the issue |
Beta Was this translation helpful? Give feedback.
-
This article has been published: https://developer.wordpress.org/news/2023/05/curating-the-editor-experience-with-client-side-filters/ 🎉 |
Beta Was this translation helpful? Give feedback.
-
Pulled from this PR: WordPress/gutenberg#45089 This would be a great filter to highlight, especially when thinking about additional curation options with the block editor.
This unlocks a ton of neat options but definitely needs to be explained in detail and documented in general.
Beta Was this translation helpful? Give feedback.
All reactions