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/src/wp-includes/script-loader.php

    r61415 r61416  
    30113011        if ( $path && $src ) {
    30123012            $size = wp_filesize( $path );
    3013             if ( ! $size ) {
     3013            if ( 0 === $size && ! file_exists( $path ) ) {
     3014                _doing_it_wrong(
     3015                    __FUNCTION__,
     3016                    sprintf(
     3017                        /* translators: 1: 'path', 2: filesystem path, 3: style handle */
     3018                        __( 'Unable to read the "%1$s" key with value "%2$s" for stylesheet "%3$s".' ),
     3019                        'path',
     3020                        esc_html( $path ),
     3021                        esc_html( $handle )
     3022                    ),
     3023                    '7.0.0'
     3024                );
    30143025                continue;
    30153026            }
     
    30493060
    30503061            // Get the styles if we don't already have them.
     3062            if ( ! is_readable( $style['path'] ) ) {
     3063                _doing_it_wrong(
     3064                    __FUNCTION__,
     3065                    sprintf(
     3066                        /* translators: 1: 'path', 2: filesystem path, 3: style handle */
     3067                        __( 'Unable to read the "%1$s" key with value "%2$s" for stylesheet "%3$s".' ),
     3068                        'path',
     3069                        esc_html( $style['path'] ),
     3070                        esc_html( $style['handle'] )
     3071                    ),
     3072                    '7.0.0'
     3073                );
     3074                continue;
     3075            }
    30513076            $style['css'] = file_get_contents( $style['path'] );
    30523077
Note: See TracChangeset for help on using the changeset viewer.