enqueue_editor_block_styles_assets

The timeline below displays how wordpress function enqueue_editor_block_styles_assets has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Function responsible for enqueuing the assets required for block styles functionality on the editor.
 *
 * @since 5.3.0
 */
function enqueue_editor_block_styles_assets()
{
    $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
    $register_script_lines = array('( function() {');
    foreach ($block_styles as $block_name => $styles) {
        foreach ($styles as $style_properties) {
            $block_style = array('name' => $style_properties['name'], 'label' => $style_properties['label']);
            if (isset($style_properties['is_default'])) {
                $block_style['isDefault'] = $style_properties['is_default'];
            }
            $register_script_lines[] = sprintf('	wp.blocks.registerBlockStyle( \'%s\', %s );', $block_name, wp_json_encode($block_style));
        }
    }
    $register_script_lines[] = '} )();';
    $inline_script = implode("\n", $register_script_lines);
    wp_register_script('wp-block-styles', false, array('wp-blocks'), true, array('in_footer' => true));
    wp_add_inline_script('wp-block-styles', $inline_script);
    wp_enqueue_script('wp-block-styles');
}

WordPress Version: 5.8

/**
 * Function responsible for enqueuing the assets required for block styles functionality on the editor.
 *
 * @since 5.3.0
 */
function enqueue_editor_block_styles_assets()
{
    $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
    $register_script_lines = array('( function() {');
    foreach ($block_styles as $block_name => $styles) {
        foreach ($styles as $style_properties) {
            $block_style = array('name' => $style_properties['name'], 'label' => $style_properties['label']);
            if (isset($style_properties['is_default'])) {
                $block_style['isDefault'] = $style_properties['is_default'];
            }
            $register_script_lines[] = sprintf('	wp.blocks.registerBlockStyle( \'%s\', %s );', $block_name, wp_json_encode($block_style));
        }
    }
    $register_script_lines[] = '} )();';
    $inline_script = implode("\n", $register_script_lines);
    wp_register_script('wp-block-styles', false, array('wp-blocks'), true, true);
    wp_add_inline_script('wp-block-styles', $inline_script);
    wp_enqueue_script('wp-block-styles');
}

WordPress Version: 5.3

/**
 * Function responsible for enqueuing the assets required for block styles functionality on the editor.
 *
 * @since 5.3.0
 */
function enqueue_editor_block_styles_assets()
{
    $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
    $register_script_lines = array('( function() {');
    foreach ($block_styles as $block_name => $styles) {
        foreach ($styles as $style_properties) {
            $register_script_lines[] = sprintf('	wp.blocks.registerBlockStyle( \'%s\', %s );', $block_name, wp_json_encode(array('name' => $style_properties['name'], 'label' => $style_properties['label'])));
        }
    }
    $register_script_lines[] = '} )();';
    $inline_script = implode("\n", $register_script_lines);
    wp_register_script('wp-block-styles', false, array('wp-blocks'), true, true);
    wp_add_inline_script('wp-block-styles', $inline_script);
    wp_enqueue_script('wp-block-styles');
}