WP 5.4 – Block validation failed for
-
Hi ??
After update WP 5.4 my custom Gutenberg blocks gave me this error after I save a postblocks.min.js?ver=423068d7079f57cf9f02458ccb4a6131:3 Block validation: Block validation failed for ‘andyandrejka/profile-pic’
Content generated by save function:
<section class=”Componet profile_pic” class=”wp-block-andyandrejka-profile-pic”><div class=”Wrapper”><div class=”img_w”><div class=”img” style=”background-image:url(https://192.150.140.108/wp/wp-content/uploads/2020/03/84958218_486729275350316_8183725397188370510_n.jpg)”></div></div></div></section>Content retrieved from post body:
<section class=”Componet profile_pic” class=”wp-block-andyandrejka-profile-pic”><div class=”Wrapper”><div class=”img_w”><div class=”img” style=”background-image:url(https://192.150.140.108/wp/wp-content/uploads/2020/03/84958218_486729275350316_8183725397188370510_n.jpg)”></div></div></div></section>Has the process of creating your own blocks changed?
PHP registration:
register_block_type('andyandrejka/profile-pic', array( 'editor_script' => 'custom-block-guttenberg' ));
JS:
const { registerBlockType } = wp.blocks; const { RichText, InspectorControls, ColorPalette, MediaUpload } = wp.editor; const { PanelBody, TextControl, IconButton } = wp.components; registerBlockType('andyandrejka/profile-pic', { // Atributes title: 'Profilovy obrázek', description: 'Profilovy obrázek', icon: 'format-image', category: 'layout', // custom attributes attributes: { backgroundImageUrl: { type: 'string', default: null }, }, edit({ attributes, setAttributes }) { const { backgroundImageUrl, } = attributes; function onSelectImage(newImage) { setAttributes({ backgroundImageUrl: newImage.sizes.full.url }); } return ([ <InspectorControls style={{ marginBottom: '40px' }}> <PanelBody title={'Profilovy obrázek'}> <p><strong>Vyberte porfilovy obrázek:</strong></p> <MediaUpload onSelect={onSelectImage} type="image" value={backgroundImageUrl} render={({ open }) => ( <IconButton className="editor-media-placeholder__button is-button is-default is-large" icon="upload" onClick={open}> Obrázek </IconButton> )} /> </PanelBody> </InspectorControls>, <section class="Componet profile_pic"> <div class="Wrapper"> <div class="img_w"> <div class="img" style={{ backgroundImage: <code>url(${backgroundImageUrl})</code> }}></div> </div> </div> </section> ]); }, save({ attributes, setAttributes }) { const { backgroundImageUrl, } = attributes; return ( <section class="Componet profile_pic"> <div class="Wrapper"> <div class="img_w"> <div class="img" style={{ backgroundImage: <code>url(${backgroundImageUrl})</code> }}></div> </div> </div> </section> ) }, });
- The topic ‘WP 5.4 – Block validation failed for’ is closed to new replies.