Custom block cannot be hidden
-
We have programmed a custom block using React and in line with the WordPress documentation and standards. When we set the visibility of the block to “Show block to selected” with User Status “Logged In”, the block still appears to visitors who are not logged-in. The add-on “Members – Block Permissions” is active.
Do we need to register the block somehow, so that this setting works correctly?
-
I’ve tested further and the problem seems to be related to all of our own React blocks, not just the one for which I raised the issue.
The block source code is temporarily available at https://gist.github.com/markhowellsmead/c254c68cf5eaa15b287aa8766ec660d9
Additional debugging in the plugin code has led me to the fact that the “Condition” is not saved with the Block when saving a Post or Page containing these custom blocks. After saving the Post or Page and then reloading the editor, the value is always reset back to “Show block to everyone”.
Hi Mark,
Are you experiencing this issue with saving with default WordPress blocks or only or your custom blocks?
Kind regards
Only non-Core blocks.
I can confirm: I also have the same problem.
Theme: GeneratePress Premium.
PHP: 8.0.7
Nginx: 1.20.1
MariaDB: 10.5.10
As soon as I try to save permissions for non-core blocks, they are defaulting back as soon as I save the page.
Core blocks work fine.Hi @markhowellsmead, @hansvaneijsden
@markhowellsmead, your block uses an inner block, so our developer thought that this is related, but the permissions settings apply to inner blocks. If you need to troubleshoot this more, please take a look at this section of code:
https://github.com/caseproof/members/blob/758a28a0f7ca8524a3b6157794b041a379c050d2/addons/members-block-permissions/src/Block.php#L50Best
The same issue applies to custom blocks which don’t use InnerBlocks. The permissions setting on the block isn’t saved.
e.g. #2: https://gist.github.com/markhowellsmead/ab4d6161dd176a103cbb1dec44da832c
Hi @caseproof, thank you for your reply and your hint.
I am using GenerateBlocks to generate the Partner Access button on https://sykam.com/downloads/ and it’s a container block, with then a buttons block and within that buttons block a single button.
But… I just discovered it also happens with non-inner-blocks. Whatever I try, I simply cannot get it to save the permission settings.Just let me know if you need a temporary login. I’m happy to help where possible.
Is there any progress on this problem please, @caseproof? We’re blocked with a couple of projects until the issue has been resolved.
Hi @markhowellsmead , @hansvaneijsden
This is related to the order in which scripts are loaded. When this happens, the custom block scripts are loading before the permission settings (loaded by Members). We’ll release a fix in the next update. In the meantime, you can try to enqueue your block scripts with a lower priority (higher number) on the enqueue_block_editor_assets hook.
Best
@caseproof thank you very much. Desperately looking forward to the update! 🙂
I’ve modified the priority on enqueue_block_editor_assets to 100, but the same problem persists.
Sorry for a bit slow response to your question.
@markhowellsmead Our developer tested a custom block with that method and it worked for him. The only other thing we can think of that might help is to add a dependency to his custom block script. So when you hook into enqueue_block_editor_assets for his custom script, your callback will use wp_enqueue_script(). You can try adding members-block-permissions-editor as a dependency there.
Best
Hi @caseproof,
Currently I’m finishing the website, it has to be ready by tomorrow unfortunately. The only thing I’m waiting for, before I can publish, is the new Members version (or a patch/workaround) to solve the above problem.
Do you have any advice? Is there anything I can do to make the plugin work for me?
Is there a possibility to beta-test the update, eventually?Thanks!
The topic ‘Custom block cannot be hidden’ is closed to new replies.