Make WordPress Core

Changeset 50703


Ignore:
Timestamp:
04/13/2021 08:02:33 AM (3 years ago)
Author:
gziolo
Message:

Blocks: Add is_default handling to server side block styles registry

Ensures that register_block_style lets developer pass is_default flag to mark one of the block style variations as the default one.

Props mukesh27, xavivars.
Fixes #53006.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-styles-registry.php

    r49120 r50703  
    3737     * @param string $block_name       Block type name including namespace.
    3838     * @param array  $style_properties Array containing the properties of the style name, label,
    39      *                                 style (name of the stylesheet to be enqueued),
     39     *                                 is_default, style_handle (name of the stylesheet to be enqueued),
    4040     *                                 inline_style (string containing the CSS to be added).
    4141     * @return bool True if the block style was registered with success and false otherwise.
  • trunk/src/wp-includes/script-loader.php

    r50629 r50703  
    23042304    foreach ( $block_styles as $block_name => $styles ) {
    23052305        foreach ( $styles as $style_properties ) {
     2306            $block_style = array(
     2307                'name'  => $style_properties['name'],
     2308                'label' => $style_properties['label'],
     2309            );
     2310            if ( isset( $style_properties['is_default'] ) ) {
     2311                $block_style['isDefault'] = $style_properties['is_default'];
     2312            }
    23062313            $register_script_lines[] = sprintf(
    23072314                '   wp.blocks.registerBlockStyle( \'%s\', %s );',
    23082315                $block_name,
    2309                 wp_json_encode(
    2310                     array(
    2311                         'name'  => $style_properties['name'],
    2312                         'label' => $style_properties['label'],
    2313                     )
    2314                 )
     2316                wp_json_encode( $block_style )
    23152317            );
    23162318        }
Note: See TracChangeset for help on using the changeset viewer.