Lock blocks and templates for editorial teams
In a newsroom, the layout of a post type is designed once, and editors should fill in content, not move the header block, delete the author box or change the template. The block editor has several levels of locking for this: lock single blocks against moving or removing, lock whole templates for a post type, restrict editing to content only, and decide per user who may unlock. Together with patterns as starting points, they keep layouts intact without taking flexibility away where it is wanted.
Problem: A magazine’s “Review” post type has a fixed structure: rating box, summary, pros and cons, verdict. Editors accidentally delete the rating box or move the verdict to the top, and fixing it costs the managing editor an hour per week.
Solution: Define the structure as a block template for the post type with template_lock, lock the critical blocks with the lock attribute, use templateLock: "contentOnly" for groups whose layout must stay while their text changes, and allow only editors with a specific capability to unlock blocks through the block_editor_settings_all filter.
A locked template for the post type
add_action( 'init', function (): void {
register_post_type( 'ha_review', array(
'label' => __( 'Reviews', 'textdomain' ),
'public' => true,
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
'template' => array(
array( 'ha/rating-box', array( 'lock' => array( 'move' => true, 'remove' => true ) ) ),
array( 'core/paragraph', array( 'placeholder' => __( 'Summary…', 'textdomain' ) ) ),
array( 'core/columns', array(), array(
array( 'core/column', array(), array( array( 'core/list', array( 'className' => 'is-pros' ) ) ) ),
array( 'core/column', array(), array( array( 'core/list', array( 'className' => 'is-cons' ) ) ) ),
) ),
array( 'core/group', array( 'templateLock' => 'contentOnly', 'className' => 'ha-verdict' ), array(
array( 'core/heading', array( 'content' => __( 'Verdict', 'textdomain' ) ) ),
array( 'core/paragraph' ),
) ),
),
'template_lock' => false,
) );
} );
- The
templatepre-fills new reviews with the structure. - The rating box has
lockwithmoveandremove: it stays at the top and cannot be deleted, but its own settings can be edited. - The verdict group has
templateLock: contentOnly: editors can change the text inside but not add, remove or move blocks, and the inspector hides design settings for the inner blocks. template_lockon the post type (allorinsert) would lock the whole post;falseleaves room for extra content between the fixed parts.
Who may unlock
By default, users who can edit the post can also open the lock menu and unlock blocks. The editor setting canLockBlocks controls that:
add_filter( 'block_editor_settings_all', function ( array $settings, WP_Block_Editor_Context $context ): array {
if ( $context->post && 'ha_review' === $context->post->post_type ) {
$settings['canLockBlocks'] = current_user_can( 'edit_others_posts' );
}
return $settings;
}, 10, 2 );
Authors and contributors can no longer unlock anything in reviews; editors still can. The setting affects the user interface; a determined user with access to the code editor could still change the markup, so it is a guard rail for honest mistakes, not a security boundary.
Patterns as building blocks
For sections that appear in many reviews (a comparison table, a “where to buy” box), register patterns and limit them to the post type with postTypes, so the inserter offers exactly the right building blocks: register block patterns. Synced patterns keep a box identical in every post; unsynced patterns are starting points that each post can change.
NOTE: For block themes, templates in the Site Editor can be locked the same way through the lock attribute in the template markup. Feedback between editors on a locked layout does not need unlocking at all: notes on blocks (WordPress 6.9) let the managing editor comment on a single block: WordPress 6.9 for developers.