Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#54113 new defect (bug)

Override core/gallery block

Reported by: lohic's profile 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)

Capture d’écran 2021-09-12 à 19.33.08.png (860.0 KB) - added by lohic 3 years ago.
The THRON alert when the core/gallery block is not activated

Download all attachments as: .zip

Change History (8)

@lohic
3 years ago

The THRON alert when the core/gallery block is not activated

This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.


3 years ago

#2 @Boniu91
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

  1. Add code mentioned in the ticket to functions.php + my_gallery_render function
  2. Add new page using Gutenberg
  3. Add Two Images Side by Side block
  4. You'll see the error and you'll be asked to install an external WordPress plugin: https://wordpress.org/plugins/thron/

#3 @Boniu91
3 years ago

  • Keywords has-testing-info added

#4 @lohic
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()

This ticket was mentioned in Slack in #core-test by boniu91. View the logs.


3 years ago

This ticket was mentioned in Slack in #core-editor by boniu91. View the logs.


3 years ago

#7 @SergeyBiryukov
3 years ago

  • Component changed from General to Editor
Note: See TracTickets for help on using tickets.