最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to update a Gutenberg block without manually recovering it?

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 2

I 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.

发布评论

评论列表(0)

  1. 暂无评论