How to get the ToggleControl Gutenberg component working for a PHP Block

The issue is that in ToggleControl you are using the wrong prop for the value. It should be checked instead of value. Also use the blockEditor package instead of editor for InspectorControls as it will be deprecated. el( ToggleControl, { label: ‘Toogle’, checked: props.attributes.toggle, // here onChange: ( value ) => { props.setAttributes( { toggle: … Read more

Hide gutenberg option blocks

Some of the panels related to the entire post (e.g. the featured image, excerpt) can be removed and https://github.com/WordPress/gutenberg/issues/17281 shows how. e.g. wp.data.dispatch( ‘core/edit-post’).removeEditorPanel( ‘featured-image’ ); wp.data.dispatch( ‘core/edit-post’).removeEditorPanel( ‘post-excerpt’ ); The sidebar is also used for additional block options and there’s currently no cohesive, consistent way to manage whether a block’s options are available to … Read more

All post types with getEntityRecords

It is not possible to query multiple post types simultaneously using the getEntityRecords() selector. This is because the WordPress REST API is not built around the same ideology as the core WordPress back-end. All data-types being “posts” in the traditional PHP APIs is the product of the somewhat controversial underlying database implementation, while the REST … Read more

serialize_blocks breaking html tags in content

This happens in serialize_block_attributes, the docblock explains why: /** … * The serialized result is a JSON-encoded string, with unicode escape sequence * substitution for characters which might otherwise interfere with embedding * the result in an HTML comment. … */ So this is done as an encoding measure to avoid attributes accidentally closing a … Read more

Get loading state of wp data selector

Yes, it’s possible and you’d use wp.data.select( ‘core/data’ ).isResolving(). Example based on your code: const MyComponent = withSelect(select => { const { isResolving } = select( ‘core/data’ ); const query = { _fields: ‘id,name,slug’ }; return { terms: select(‘core’).getEntityRecords(“taxonomy”, “my_taxonomy”, query), isRequesting: isResolving( ‘core’, ‘getEntityRecords’, [ ‘taxonomy’, ‘my_taxonomy’, query ] ) }; })(props => { … Read more

WordPress Value of Undefined in Admin

Your value prop is the wrong format. From <LinkControl>‘s README: value Type: Object Required: No Current link value. A link value is composed of a union between the values of default link properties and any custom link settings. The resulting default properties of value include: url (string): Link URL. title (string, optional): Link title. opensInNewTab … Read more

How to make repeated component/block in Gutenberg

I think the best way to approach this is by creating 2 blocks with a parent -> child relationship. The child block would be a nested block only available within its parent block. Note the parent defined below. registerBlockType( ‘prefix/childblock’, { title: __( ‘Inner Child Block’ ), parent: [‘prefix/parentblock’], attributes:{ …//the rest of your block … Read more