InnerBlocks模板锁定="all" 在WordPress 6.1.1上出现的问题

huangapple go评论108阅读模式
英文:

InnerBlocks templateLock="all" issue on WordPress 6.1.1

问题

我有一个自定义块,使用InnerBlocks创建一个包含3列模板,并使用templateLock="all"属性来防止用户移动/删除或添加模板中的内容。它在WordPress 6.0.3(及以下版本)上正常工作,但当我升级到6.1.1后出现问题。它不是锁定模板并显示我应该能够添加其他块的列,而是隐藏了新插入的列,使它们在编辑器中无法选择。

以下是我创建内部块的方式:

<window.wp.blockEditor.InnerBlocks
    template={new Array(3).fill(['core/column', {}])}
    templateLock="all"
/>

以下是当我复制该块时的内容:

<!-- wp:attest/grid-columns {"numColumnsStr":"3"} -->
<div class="grid grid--columns-3"><!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column -->

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

<!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column --></div>
<!-- /wp:attest/grid-columns -->

我尝试查看自WordPress 6.0.3以来的更改,但找不到有用的信息。

感谢您的帮助。

英文:

I have a custom block that creates a 3 column template with InnerBlocks and a templateLock=&quot;all&quot; attribute to avoid that users move/remove or add something in the template. It used to properly work on WordPress 6.0.3 (and bellow) but then when I updated to 6.1.1 it had issues. Instead of locking the template and showing the columns in which I should be able to add other blocks, it hides the newly inserted columns so that they are unselectable in the editor.

Here is how I create the innerBlocks

&lt;window.wp.blockEditor.InnerBlocks
    template={new Array(3).fill([&#39;core/column&#39;, {}])}
    templateLock=&quot;all&quot;
/&gt;

Here is what I have when I copy the block

&lt;!-- wp:attest/grid-columns {&quot;numColumnsStr&quot;:&quot;3&quot;} --&gt;
&lt;div class=&quot;grid grid--columns-3&quot;&gt;&lt;!-- wp:column --&gt;
&lt;div class=&quot;wp-block-column&quot;&gt;&lt;/div&gt;
&lt;!-- /wp:column --&gt;

&lt;!-- wp:column --&gt;
&lt;div class=&quot;wp-block-column&quot;&gt;&lt;/div&gt;
&lt;!-- /wp:column --&gt;

&lt;!-- wp:column --&gt;
&lt;div class=&quot;wp-block-column&quot;&gt;&lt;/div&gt;
&lt;!-- /wp:column --&gt;&lt;/div&gt;
&lt;!-- /wp:attest/grid-columns --&gt;

I've tried to look at the changes since WordPress 6.0.3 but couldn't find something useful.

Thanks for you help.

答案1

得分: 0

事实上,子块继承了父块的 templateLock 属性,因此这些列是存在的,只是被锁定了,而且由于它们是新插入的,所以它们是空的,因此呈现为不可见。因此,想法是默认解锁 core/column 块及其(未来的)子块。以下是我的更新后的代码:

<window.wp.editor.InnerBlocks
    template={new Array(numColumns).fill(['core/column', {templateLock: false, lock: {move: false, remove: false}}])}
    templateLock='all'
/>
英文:

In fact child blocks inherits from parent's templateLock attribute so the columns were present, they were just locked and as they are newly inserted, they were empty thus rendered invisible. So the idea is to unlock the core/column block and its (future) child blocks by default. Here is my updated code

&lt;window.wp.editor.InnerBlocks
    template={new Array(numColumns).fill([&#39;core/column&#39;, {templateLock: false, lock: {move: false, remove: false}}])}
    templateLock=&#39;all&#39;
/&gt;

huangapple
  • 本文由 发表于 2023年1月9日 15:27:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75054219.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定