WordUp Pompey!

WordPress Portsmouth Meetup

What can you do to recover from exporting a re-usable block to a pattern?

Using the Create Block Theme plugin I inadvertently/accidentally choose the option to Save Synced Patterns.

This option comes with the notice.

Any synced patterns created in the Editor will be moved to the theme. Note that this will delete all synced patterns from the Editor and any references in templates will be made relative to the theme.

What it doesn’t tell you is that any use of the patterns as reusable blocks in posts, pages or other content will not be changed to refer to the theme’s pattern, and will therefore no longer work.

Problem resolution

There were 4 patterns exported, but the generated PHP gives no indication as to their original block ref nor from where the reusable block was referenced.

Step 1. Find the original patterns’ block refs

  1. Search for all occurrences of wp:block.
  2. For each post or page found, edit the post.
  3. Use the Code editor to find the pattern’s block ref.
  4. Attempt to work out from the context which pattern this represented.

Step 4. is a lot easier if you’re working on a staging site and you’ve got a working live site to refer to.

Original block refPattern title
1553Join our meetup
1487Refreshment other info sponsors
1485Who Can Attend?
1379Sponsor thankyou with links

Step 2. Re-insert the patterns

In a new post, for each of the exported / deleted patterns

  • Re-insert the pattern from the theme.
  • Select all the blocks in the pattern.
  • Create new pattern as a Synced pattern.
  • Determine the new block ref for the synced pattern.

Those are the basic steps. They probably need fleshing out.

Original block refNew block ref
15532703
14872717
14852719
1379 – note that this reusable block was referenced by 14872723

Step 3. Update the block refs across the site

For each block ref, use a plugin, such as Better Search Replace, to change the block refs from the Original block ref to the New block ref.

eg

From:

<!-- wp:block {"ref":1379} /-->

To:

<!-- wp:block {"ref":2723} /-->