Opened 3 years ago
Last modified 3 years ago
#54113 new defect (bug)
Override core/gallery block
Reported by: | lohic | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.8.1 |
Component: | Editor | Keywords: | has-testing-info |
Focuses: | administration, template | Cc: |
Description
Hello,
I did override the core block for the gallery using in my functions.php file :
<?php function my_register_gallery() { unregister_block_type('core/gallery'); register_block_type( 'core/gallery', array( 'render_callback' => 'my_gallery_render', ) ); } add_action( 'init', 'my_register_gallery', 10 , 1 );
It was perfectly working, but since a few days (I did the last update of wordpress 5.8.1), and maybe a little bit before, but I am not totally sure, I have an issue :
If I use the unregister_block_type function I cannot override it with register_block_type and the block disappear in the editor. And a strange thing occurs, I have this message on the former existing gallery blocks :
Your site doesn’t include support for the THRON block. You can try installing the block, convert it to a Custom HTML block, or remove it entirely.
If I don't use unregister_block_type('core/gallery'); before, I have this message :
Notice: WP_Block_Type_Registry::register was called incorrectly. Block type "core/gallery" is already registered. Please see Debugging in WordPress for more information. (This message was added in version 5.0.0.) in /Users/the_user/wordpress_folder/wp-includes/functions.php on line 5663
All of that was working before with no alert.
I tried with all my plugins deactivated, and with removing all my function.php files actions.
Attachments (1)
Change History (8)
This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.
3 years ago
#2
@
3 years ago
@lohic Thank you for the report, I was able to reproduce it.
Test Report
Env
- WordPress 5.8.1
- Chrome 92.0.4515.159
- Windows 10
- Theme: Twenty Twenty One
Steps to test
- Add code mentioned in the ticket to functions.php +
my_gallery_render
function - Add new page using Gutenberg
- Add
Two Images Side by Side
block - You'll see the error and you'll be asked to install an external WordPress plugin: https://wordpress.org/plugins/thron/
#4
@
3 years ago
@Boniu91 since, I did some more research, and it seems that for core/blocks, we need to use add_filter( ‘render_block’, ‘render_block_function’) instead of unregister_block_type() + register_block_type()
The THRON alert when the core/gallery block is not activated