Make WordPress Core


Ignore:
Timestamp:
12/29/2025 06:59:20 PM (3 months ago)
Author:
westonruter
Message:

Script Loader: Warn when a registered style has invalid path data and allow inlining empty stylesheets.

When a stylesheet is registered with a path that does not exist or which is not readable, then a _doing_it_wrong() is now issued. Previously, paths that did not exist were silently skipped; paths for empty styles were also needlessly skipped, since wp_filesize() also returns 0 for the failure case.

Developed in https://github.com/WordPress/wordpress-develop/pull/10653

Follow-up to [50836].

Props westonruter, jonsurrell, soyebsalar01.
See #52620.
Fixes #64447.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/template.php

    r61174 r61416  
    16781678     */
    16791679    public function test_wp_hoist_late_printed_styles( ?Closure $set_up, int $inline_size_limit, array $expected_styles ): void {
     1680        // `_print_emoji_detection_script()` assumes `wp-includes/js/wp-emoji-loader.js` is present:
     1681        self::touch( ABSPATH . WPINC . '/js/wp-emoji-loader.js' );
     1682
    16801683        switch_theme( 'default' );
    16811684        global $wp_styles;
     
    17121715            wp_should_load_separate_core_block_assets() ? 'css/dist/block-library/common.css' : 'css/dist/block-library/style.css'
    17131716        );
     1717        $this->ensure_style_asset_file_created( 'wp-block-library-theme', 'css/dist/block-library/theme.css' );
     1718
    17141719        if ( wp_should_load_separate_core_block_assets() ) {
    17151720            $this->ensure_style_asset_file_created( 'wp-block-separator', 'blocks/separator/style.css' );
     
    18281833        $dependency->src = includes_url( $relative_path );
    18291834        $path            = ABSPATH . WPINC . '/' . $relative_path;
    1830         if ( ! file_exists( $path ) ) {
    1831             $dir = dirname( $path );
    1832             if ( ! file_exists( $dir ) ) {
    1833                 mkdir( $dir, 0777, true );
    1834             }
     1835        self::touch( $path );
     1836        if ( 0 === filesize( $path ) ) {
    18351837            file_put_contents( $path, "/* CSS for $handle */" );
    18361838        }
Note: See TracChangeset for help on using the changeset viewer.