Once Again: How to Remove Option from Gutenberg Editor for Specific Block in theme.json
Once Again: How to Remove Option from Gutenberg Editor for Specific Block in theme.json
Once Again: How to Remove Option from Gutenberg Editor for Specific Block in theme.json
Your code looks ok and would work in any other component other than colors, because colors need the higher-order-component withColors. In the past I struggled also dealing with the behaviour, that your are describing and found these two solutions: If you want to insert your own color component, check the second example from here https://awhitepixel.com/blog/add-custom-settings-to-existing-wordpress-gutenberg-blocks/. … Read more
I’m not sure if there’s a direct way to inspect an attributes default value but one way would you can indirectly achieve this is to store the default value in a variable. You could then reference it from inside the attribute object and from the edit and save functions. e.g. (untested) const amountDefault = 1; … Read more
There are multiple better ways to get a list of posts in a Gutenberg block, other than rendering serverside. First is to use the Wrodpress wrapper around Redux and select posts exactly like in the Gutenberg Handbook: edit: withSelect( function( select ) { return { posts: select( ‘core’ ).getEntityRecords( ‘postType’, ‘post’ ) }; } )( … Read more
The issue here is on the PHP side. First we need to figure out if the meta key has been saved before and send this information to the editor. Once in the editor we can assign a default value if the meta key is new. The way to check this is using get_post_custom_keys. We need … Read more
The problem is that calling wp.data.select triggers a fetch and the data takes some time to be available. Until that happens the value returned is an empty array. My suggestion here is to use wp.data.useSelect, which is a React hook made specifically for this, so the component re-renders when there is a change in the … Read more
UrlInput uses LinkControl internally, but neither have been built with the sidebar in mind, they’re to be used inside popover components that appear inline such as when a toolbar button is clicked. They aren’t intended to appear directly in toolbars either. Most if not all input components can’t be shown in the toolbar, with the … Read more
You need to call savePost after calling editPost. Referring to the source’s way of handling it:https://github.com/WordPress/gutenberg/blob/trunk/packages/editor/src/components/post-visibility/index.js it shows savePost being called right after changing the visibility. In practice: import { PluginPostStatusInfo } from ‘@wordpress/edit-post’; import { __ } from ‘@wordpress/i18n’; import { registerPlugin } from ‘@wordpress/plugins’; import { ToggleControl } from ‘@wordpress/components’; import { useSelect, … Read more
<RichText> has a property, isSelected. When isSelected is true, the controls show. By default isSelected is representative of the current block being selected. from the docs isSelected: Boolean Optional. Whether to show the input is selected or not in order to show the formatting controls. By default it renders the controls when the block is … Read more
Although I’m unsure on how to achieve this in php, within javascript you can change the category by hooking into the blocks.registerBlockType hook. Here is a small example how it would work, although I’d recommend using lodash to deepClone the settings object to keep everything immutable. const rearrangeBlockCategories = { ‘core/table’: ‘common’, }; wp.hooks.addFilter(‘blocks.registerBlockType’, ‘[namespace]’, … Read more