Make WordPress Core


Ignore:
Timestamp:
09/18/2023 06:25:49 AM (20 months ago)
Author:
isabel_brison
Message:

Editor: add block instance element color support for buttons and headings.

Adds support for buttons and headings to the colors and elements block supports, allowing button and heading element colors to be changed on individual blocks.

Props aaronrobertshaw.
Fixes #59309.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-supports/elements.php

    r55235 r56604  
    107107        );
    108108    }
     109
     110    /**
     111     * Test wp_render_elements_support() with a group block that has a button
     112     * element color set.
     113     *
     114     * @ticket 59309
     115     */
     116    public function test_group_with_button_element_style() {
     117        $result = self::make_unique_id_one(
     118            wp_render_elements_support(
     119                '<div class="wp-block-group"><div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex"><div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button</a></div></div></div>',
     120                array(
     121                    'blockName' => 'core/group',
     122                    'attrs'     => array(
     123                        'style' => array(
     124                            'elements' => array(
     125                                'button' => array(
     126                                    'color' => array(
     127                                        'text' => 'var:preset|color|vivid-red',
     128                                    ),
     129                                ),
     130                            ),
     131                        ),
     132                    ),
     133                )
     134            )
     135        );
     136        $this->assertSame(
     137            $result,
     138            '<div class="wp-block-group wp-elements-1"><div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex"><div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button</a></div></div></div>'
     139        );
     140    }
     141
     142    /**
     143     * Test wp_render_elements_support() with a group block that has a heading
     144     * element color set.
     145     *
     146     * @ticket 59309
     147     */
     148    public function test_group_with_heading_element_style() {
     149        $result = self::make_unique_id_one(
     150            wp_render_elements_support(
     151                '<div class="wp-block-group"><h2 class="wp-block-heading">Test</h2></div>',
     152                array(
     153                    'blockName' => 'core/group',
     154                    'attrs'     => array(
     155                        'style' => array(
     156                            'elements' => array(
     157                                'heading' => array(
     158                                    'color' => array(
     159                                        'text' => 'var:preset|color|vivid-red',
     160                                    ),
     161                                ),
     162                            ),
     163                        ),
     164                    ),
     165                )
     166            )
     167        );
     168        $this->assertSame(
     169            $result,
     170            '<div class="wp-block-group wp-elements-1"><h2 class="wp-block-heading">Test</h2></div>'
     171        );
     172    }
    109173}
Note: See TracChangeset for help on using the changeset viewer.