Opened 11 months ago
Closed 11 months ago
#60367 closed defect (bug) (duplicate)
Using style_handle in register_block_style call does not work
Reported by: | lovor | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 6.4.2 |
Component: | Editor | Keywords: | |
Focuses: | Cc: |
Description
When wp_should_load_separate_core_block_assets()
is true, styles which are enqueued by register_block_style
, using style_handle
key in array $style_properties
are not enqueued in front end, only in editor. This most notably happens in FSE themes, since load separate core block assets is by default true in those themes.
Example:
wp_register_style( 'core-list-dashes-style', get_theme_file_uri('assets/css/blocks/core-list-style-dashes.css') ); register_block_style('core/list', [ 'name' => 'dashes', 'label' => 'Dashes as bullets', 'style_handle' => 'core-list-dashes-style' ]);
The reason:
On line 2666 in wp-includes/script-loader.php
, in such cases enqueuing is attempted by adding static anonymous function to render_block
filter. However, this filter fires before function is added and that is the reason why this doesn't work!
Proposed solution:
Adding another property to WP_Block_Styles_Registry which would be array, named e.g. blocks_to_render
. This array would consist of block names (e.g. core/list
) that are about to be rendered. In wp-includes/class-wp-block.php
, in render
function, for every block that is about to be rendered, its name would be added to the list, if it is not already in the list.
Then, on line 2666 in enqueue_block_styles_assets
function in wp-includes/script-loader.php
block would be enqueued if it is in the aforementioned array.
Duplicate of #55184.
Hi, I believe this is a duplicate of https://core.trac.wordpress.org/ticket/55184.
I will close this ticket as a duplicate, if I misunderstood the description, the ticket can be re-opened.