Make WordPress Core

Ticket #59879: 67890.diff

File 67890.diff, 1.4 KB (added by nightnei, 15 months ago)

This solution is much better, but we expect to have the first item as our custom styles in the code, so I am afraid to break something else if I make changes in the condition

  • src/wp-includes/blocks.php

    diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php
    index 1dc1e66230..110737bdb3 100644
    a b function register_block_style_handle( $metadata, $field_name, $index = 0 ) { 
    258258        }
    259259        // Return the style handle unless it's the first item for every core block that requires special treatment.
    260260        if ( $is_style_handle && ! ( $is_core_block && 0 === $index ) ) {
     261                // Current solution with initial `array_unshift` is broken due hardcode of 0 index ($is_core_block && 0 === $index), so it returns incorrect name
     262                // AFAIU we always expect to have first styles as a custom styles (theme.json)
    261263                return $style_handle;
    262264        }
    263265
    function register_block_type_from_metadata( $file_or_folder, $args = array() ) { 
    397399                if ( current_theme_supports( 'wp-block-styles' ) && wp_should_load_separate_core_block_assets() ) {
    398400                        $metadata['style']   = (array) $metadata['style'];
    399401                        $metadata['style'][] = "wp-block-{$block_name}-theme";
     402
     403                        // we should put "wp-block-{$block_name}-theme" before styles from theme.json and any other styles,
     404                        // since these styles are default, so we should have opportunity to override it
     405                        array_unshift( $metadata['style'], "wp-block-{$block_name}-theme" );
    400406                }
    401407                if ( ! isset( $metadata['editorStyle'] ) ) {
    402408                        $metadata['editorStyle'] = "wp-block-{$block_name}-editor";