Gutenberg get index of gutenberg innerblock

You may now retrieve the index of a inner block via the core/block-editor data module. You may pair it with the useSelect hook to keep the indexes up to date on changes. Something like this. Intentionally verbose for clarity. import {useSelect} from ‘@wordpress/data’; const Answer = ( blockProps ) => { const {index} = useSelect( … Read more

Detect if a block has been deleted

Maybe you will find this snippet helpful. I’m still searching for a better way to do this but as far as I can tell blocks are not aware of their own deletion. Instead we have to monitor the blocks from above. If you have a parent block type that has children, you can subscribe to … Read more

WordPress npm run build and start only outputs wp-scripts start but does nothing

I’ve managed to pull and get it to run as I would expect. $ npm run start:random-game > [email protected] start:random-game C:\Users\…\game-review-block > wp-scripts start blocks/random-game/src/index.js –output-path=blocks/random-game/build/ <i> [LiveReloadPlugin] Live Reload listening on port 35729 asset index.js 25.4 KiB [emitted] (name: index) 1 related asset asset style-index.css 858 bytes [emitted] (name: style-index) (id hint: style) 1 … Read more

CheckboxControl does not visible change

Solution found: const { __ } = wp.i18n; const { useSelect, useDispatch } = wp.data; const { PluginDocumentSettingPanel } = wp.editPost; const { CheckboxControl, PanelRow } = wp.components; const Sidebar = () => { const { postMeta } = useSelect( ( select ) => { return { postMeta: select( ‘core/editor’ ).getEditedPostAttribute( ‘meta’ ), }; } … Read more

Adding content to Page settings rather than Block settings

Ahh — I found it. It is called the PluginDocumentSettingPanel and can be imported from @wordpress/edit-post. import { registerPlugin } from ‘@wordpress/plugins’; import { PluginDocumentSettingPanel } from ‘@wordpress/edit-post’; const PluginDocumentSettingPanelDemo = () => ( <PluginDocumentSettingPanel name=”custom-panel” title=”Custom Panel” className=”custom-panel” > Custom Panel Contents </PluginDocumentSettingPanel> ); registerPlugin( ‘plugin-document-setting-panel-demo’, { render: PluginDocumentSettingPanelDemo, icon: ‘palmtree’, } );

Wp-script package stop to work

Finally i found the problem ! There was a problem in the scss file which stop the building script. I had no error message. I think that the problem was that i used a sass variable which was too long.

How to register two blocks in the same plugin

Add a subfolder in your-plugin/src with the block name Put all src files inside this folder Repeat 1 and 2 for other blocks that you want to add. At this moment, the src folder looks like this: Be careful to edit properly each block.json to give them a name, etc. replace de single block registration … Read more