-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Description
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
// 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
The relevant code
class-wp-hook.php 305
https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/class-wp-hook.php#L305
script-loader.php 2451
https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/script-loader.php#L2451-L2453
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
WordPress/wordpress-develop#1482
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
// 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,
)
);