Make WordPress Core


Ignore:
Timestamp:
06/13/2023 09:51:11 AM (20 months ago)
Author:
spacedmonkey
Message:

Script Loader: Add a check to see in style is registered in wp_maybe_inline_styles.

Add a check in wp_maybe_inline_styles to check that style is registered before processing items in queue. It is possible that developers may have called wp_deregister_style, unregistering style but the style still be in the queue to be processed. Without this check, typing to access the src property would result in a notice error.

Follow on from [55888].

Props spacedmonkey, flixos90, dd32, kebbet.
See #58394.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r55888 r55909  
    539539
    540540    /**
     541     * @ticket 58394
     542     *
     543     * @covers ::wp_maybe_inline_styles
     544     */
     545    public function test_wp_maybe_inline_styles_dequeue_styles() {
     546        $filter = new MockAction();
     547        add_filter( 'pre_wp_filesize', array( $filter, 'filter' ) );
     548        wp_register_style( 'test-handle', '/' . WPINC . '/css/classic-themes.css' );
     549        wp_style_add_data( 'test-handle', 'path', ABSPATH . WPINC . '/css/classic-themes.css' );
     550
     551        wp_enqueue_style( 'test-handle' );
     552
     553        wp_deregister_style( 'test-handle' );
     554
     555        wp_maybe_inline_styles();
     556
     557        $this->assertSame( 0, $filter->get_call_count() );
     558    }
     559
     560    /**
    541561     * wp_filesize should be only be called once, as on the second run of wp_maybe_inline_styles,
    542562     * src will be set to false and filesize will not be requested.
Note: See TracChangeset for help on using the changeset viewer.