justintadlock / block-pattern-builder

Build block patterns from the WordPress admin.
GNU General Public License v2.0
41 stars 9 forks source link

Add "Add to Block Patterns" to Block Editor #2

Closed HardeepAsrani closed 4 years ago

HardeepAsrani commented 4 years ago

This commits adds an option to add your blocks to Block Patterns straight from the block editor. It closes https://github.com/justintadlock/block-pattern-builder/issues/1

Block Pattern

(The button is blue, looks gray in the GIF)

A video to demonstrate how it works: https://www.loom.com/share/8f0ee1e7fb854f36a9caa0eedbf134d3

I've added a few constants to define. One defines the version, so make sure to update it accordingly.

It uses React Hooks which won't work below WordPress 5.3. Given that you need at least WordPress 5.4 with the latest Gutenberg to use Block Patterns, that shouldn't be an issue. But you should consider raising the minimum WP version for the plugin to 5.4.

Also worth adding a condition to make sure it only loads on an instance if it has Block Patterns.

On to you @justintadlock

HardeepAsrani commented 4 years ago

One limitation, which I couldn't do much about, is that the block pattern won't appear on the sidebar until you refresh the page.

It won't matter much in reality for most cases if you have the block added to the editor, you can just duplicate it. But that is one limitation of this right now.