admin管理员组

文章数量:1122832

I have a WordPress plugin containing a dynamic Gutenberg block which returns a div on the front-end:

register_block_type(
  PLUGIN_DIR_PATH . 'dist/my-plugin/block.json',
    array(
      'render_callback' => array( $this, 'render_my_plugin_block' ),
    )
  PLUGIN_DIR_PATH . 'dist/my-plugin/block.json'
);

Old end result:

<div class="my-plugin-block"></div>

I am targeting this div with React and populating its contents. Now In a new version I am using InnerBlocks on the save function as opposed to returning null.

export default function Save() {
    const blockProps = useBlockProps.save();

    return (
        <div {...blockProps}>
            <InnerBlocks.Content />
        </div>
    );
}

Which produces the following new end result:

<div class="my-plugin-container">
  <div class="my-plugin-section-1"></div>
  <div class="my-plugin-section-2"></div>
  <div class="my-plugin-section-3"></div>
</div>

I have written a deprecation which fixes this on the editor and once a user saves the post. But this only works until the user saves the post. Is there any way to change all those instances to the new HTML markup without relying on a manual save?

So make old become the new end result without relying on a manual save.

本文标签: deprecationWP dynamic blockchange content without saving