Make WordPress Core


Ignore:
Timestamp:
07/10/2024 06:17:44 AM (19 months ago)
Author:
isabel_brison
Message:

Editor: enqueue block custom CSS only when block renders on the page.

Updates the global styles custom CSS handling logic to be consistent with other global styles and take advantage of conditional enqueuing of block styles.

Props isabel_brison, aaronrobertshaw, andrewserong.
Fixes #61395.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r58685 r58703  
    50365036
    50375037    /**
    5038      * @ticket 57536
    5039      * @ticket 61165
    5040      */
    5041     public function test_get_custom_css_handles_global_custom_css() {
     5038     * Tests that base custom CSS is generated correctly.
     5039     *
     5040     * @ticket 61395
     5041     */
     5042    public function test_get_stylesheet_handles_base_custom_css() {
    50425043        $theme_json = new WP_Theme_JSON(
    50435044            array(
    50445045                'version' => WP_Theme_JSON::LATEST_SCHEMA,
    50455046                'styles'  => array(
    5046                     'css'    => 'body {color:purple;}',
     5047                    'css' => 'body {color:purple;}',
     5048                ),
     5049            )
     5050        );
     5051
     5052        $custom_css = 'body {color:purple;}';
     5053        $this->assertSame( $custom_css, $theme_json->get_stylesheet( array( 'custom-css' ) ) );
     5054    }
     5055
     5056    /**
     5057     * Tests that block custom CSS is generated correctly.
     5058     *
     5059     * @ticket 61395
     5060     */
     5061    public function test_get_styles_for_block_handles_block_custom_css() {
     5062        $theme_json = new WP_Theme_JSON(
     5063            array(
     5064                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     5065                'styles'  => array(
    50475066                    'blocks' => array(
    50485067                        'core/paragraph' => array(
     
    50545073        );
    50555074
    5056         $custom_css = 'body {color:purple;}:root :where(p){color:red;}';
    5057         $this->assertSame( $custom_css, $theme_json->get_custom_css() );
     5075        $paragraph_node = array(
     5076            'name'      => 'core/paragraph',
     5077            'path'      => array( 'styles', 'blocks', 'core/paragraph' ),
     5078            'selector'  => 'p',
     5079            'selectors' => array(
     5080                'root' => 'p',
     5081            ),
     5082        );
     5083
     5084        $custom_css = ':root :where(p){color:red;}';
     5085        $this->assertSame( $custom_css, $theme_json->get_styles_for_block( $paragraph_node ) );
    50585086    }
    50595087
Note: See TracChangeset for help on using the changeset viewer.