Error in register_block_style when should_load_separate_core_block_assets is tur

Viewed 52

I posted this on gutenberg issues, but I’m hoping for support here as well. Is anyone else facing this problem? I get an error with register_block_style when I turn on should_load_separate_core_block_assets.

(= add_filter( 'should_load_separate_core_block_assets', '__return_true' ); )

Code

PHP
// Register Style.
wp_register_style(
    'core/heading',
    plugin_dir_url( __FILE__ ) . 'build/core/heading/style.css',
    array()
);

register_block_style(
    'core/heading',
    array(
        'name'       => 'heading-default',
        'label'      => 'Default',
        'style_handle' => 'core/heading',
        'is_default' => true,
    )
);

Error message

Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /var/www/html/wp-includes/class-wp-hook.php on line 305 and exactly 2 expected in /var/www/html/wp-includes/script-loader.php:2447 Stack trace: #0 /var/www/html/wp-includes/class-wp-hook.php(305): {closure}('\n

Expected behavior

If heading-default is set, the CSS (style.css) will be loaded, and if heading-default is not set, the CSS will not be loaded.

Related references

https://make.wordpress.org/core/2021/07/01/block-styles-loading-enhancements-in-wordpress-5-8/#comment-41478 https://core.trac.wordpress.org/ticket/53616 register_block_type is working fine. Is register_block_style still being worked on? If so, please let me know.

Step-by-step reproduction instructions

1.add_filter( 'should_load_separate_core_block_assets', '__return_true' ); for custom plugins etc. 2.Prepare the CSS build/core/heading/style.css 3.Paste the code to add the style for the heading block

PHP

// Register Style.
wp_register_style(
    'core/heading',
    plugin_dir_url( __FILE__ ) . 'build/core/heading/style.css',
    array()
);

register_block_style(
    'core/heading',
    array(
        'name'       => 'heading-default',
        'label'      => 'Default',
        'style_handle' => 'core/heading',
        'is_default' => true,
    )
);

Contract I would be very happy to receive any information.

0 Answers
Related