Skip to content

templateLock: "contentOnly" displays non-functional "Add Before/After" options in block options #76881

@mrleemon

Description

@mrleemon

Description

When using templateLock: "contentOnly" within a Group block (in a template part, for example), the editor correctly restricts structural changes but incorrectly displays "Add before", "Add after", and "Duplicate" options in the block options (three vertical dots) menu for child Paragraph blocks.

While "Duplicate" works (which is arguably a structural change), "Add before" and "Add after" do nothing when clicked, leading to a broken user experience.

Expected behavior:
According to the documentation, users should only be able to edit the content. The "Add before/after" options should be hidden entirely, as adding new blocks (even if they are the same type) changes the layout/structure defined by the template.

Actual behavior:

  • The options are visible in the menu.
  • "Add before" and "Add after" fail silently (no action taken).
  • "Duplicate" works, which bypasses the intended restriction of the template lock.

Step-by-step reproduction instructions

  1. Create a template part or a block pattern.
  2. Wrap content in a Group block with the attribute "templateLock": "contentOnly" and the attribute "lock":{"move":true,"remove":true}.
  3. Include a Paragraph block inside this group.
  4. In the Site Editor, select the Paragraph block.
  5. Click the "Options" (three vertical dots) menu in the block toolbar.
  6. Observe that "Duplicate", "Add before", and "Add after" are visible.
  7. Click "Add before" or "Add after". Note that no block inserter appears and no block is added.

Screenshots, screen recording, code snippet

This is the code of the template part I used to test this:

<!-- wp:group {"style":{"spacing":{"margin":{"top":"20px","bottom":"20px"}}},"layout":{"type":"constrained"},"templateLock":"contentOnly","lock":{"move":true,"remove":true}} -->
<div class="wp-block-group" style="margin-top:20px;margin-bottom:20px"><!-- wp:columns {"style":{"spacing":{"blockGap":{"left":"50px"}}}} -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:site-title {"level":0} /-->

<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column -->
<div class="wp-block-column"><!-- wp:page-list /--></div>
<!-- /wp:column -->

<!-- wp:column -->
<div class="wp-block-column"><!-- wp:social-links {"iconBackgroundColor":"black","iconBackgroundColorValue":"#000000","openInNewTab":true,"className":"is-style-default","style":{"spacing":{"blockGap":{"left":"5px"}}}} -->
<ul class="wp-block-social-links has-icon-background-color is-style-default"><!-- wp:social-link {"service":"instagram"} /-->
<!-- wp:social-link {"service":"facebook"} /-->
<!-- wp:social-link {"service":"x"} /--></ul>
<!-- /wp:social-links -->

<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"theme/privacy"}}}} -->
<p></p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></div>
<!-- /wp:group -->

Screenshot showing the issue:

Image

Environment info

  • WordPress version: 7.0 RC2
  • Gutenberg plugin: No Gutenberg plugin active
  • Theme: Custom hybrid theme

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Labels

[Feature] PatternsA collection of blocks that can be synced (previously reusable blocks) or unsynced[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type
No fields configured for issues without a type.

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions