admin管理员组文章数量:1335825
I have built a Gutenberg block which is used on several pages on a client site.
When the block is modified after a client request, it breaks the block on the editor of all the pages which needs to be manually fixed by using the Attempt Recovery
feature.
In addition to this, the front end doesn't update until the block is recovered and saved again.
I was wondering if there is an easy way to fix the blocks whenever they're modified?
I have built a Gutenberg block which is used on several pages on a client site.
When the block is modified after a client request, it breaks the block on the editor of all the pages which needs to be manually fixed by using the Attempt Recovery
feature.
In addition to this, the front end doesn't update until the block is recovered and saved again.
I was wondering if there is an easy way to fix the blocks whenever they're modified?
Share Improve this question asked May 25, 2020 at 13:15 Siddharth ThevarilSiddharth Thevaril 5677 silver badges22 bronze badges 3- When updating a block that has been used, you need to "deprecate" the block, which allows it to be migrated to the new version. The process for that is documented here: developer.wordpress/block-editor/developers/block-api/… – Jacob Peattie Commented May 25, 2020 at 13:40
- Thanks a lot, this is just what I needed! Can you add this as an answer so that I can accept it? – Siddharth Thevaril Commented May 25, 2020 at 14:51
- Block deprecation works to address the rendering issues in the block editor but all of the blocks will still need to be manually updated as the markup is still saved in the database. – Welcher Commented May 26, 2020 at 23:02
1 Answer
Reset to default 2I would recommend moving to a dynamic block as opposed to a static one. The difference being that dynamic blocks are rendered via PHP and don't save the markup in the database. This allows you to make any changes you want to the block output and it will be reflected without needing to update each instance of the block.
In order to convert your static block to a dynamic one, you'll need to modify the save
property to return null
on the JavaScript side and then register the block on the PHP side with a render_callback
. There is a an example in the developer docs that you can review here.
If you update the question with your code, I'd be happy to help you update it.
本文标签: How to update a Gutenberg block without manually recovering it
版权声明:本文标题:How to update a Gutenberg block without manually recovering it? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742399569a2467611.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论