WordPress 5.9 to Introduce New API for Locking Blocks – WP Tavern

The appearance of block themes delivers extra inventive energy into the arms of customers, however there are occasions when theme authors might need to lock down key components of a design and its designated content material areas. First introduced in Gutenberg 11.6, the upcoming WordPress 5.9 launch will embody a brand new API for locking blocks.

Template stage locking has been accessible in Gutenberg for just a few years, permitting builders to lock the template on the UI in order that customers can’t manipulate the blocks. This new API gives extra granular management that may be utilized on the block stage and override template locking.

“As a substitute of making use of a lock to all inside blocks, you may apply it selectively to particular person blocks through the lock attribute,” Marcus Kazmierczak stated within the dev note. “The block stage locking would supersede the inherited templateLock worth. You possibly can select to lock transferring or eradicating a block.”

One of many main use circumstances for locking particular person blocks, cited within the ticket proposing the brand new API, is the place one would possibly lock the “post-content” block of a single template so customers can’t take away it.

“One other use case that we’re constructing for is having a Checkout Block with completely different blocks that act as elementary steps, we don’t need individuals to delete or transfer these steps since they’re elementary and their order can also be vital, however we need to enable individuals to pick them, entry settings, and insert blocks in between them,” WooCommerce engineer Seghir Nadir stated.

Kazmierczak’s dev observe demonstrates how builders can lock a particular block in a sample and defined how block stage locking will not be inheritable.

“If a block is locked from being eliminated, its kids can nonetheless be eliminated,” Kazmierczak stated. “If you wish to apply locking on kids as effectively, add templateLock to the inside block element, or templateLock attribute to supporting blocks.”

For extra data on the brand new locking mechanism, take a look at the Block Editor Handbook and the code examples within the dev note.

Leave a Reply

Your email address will not be published. Required fields are marked *