Make WordPress Core


Ignore:
Timestamp:
10/16/2025 07:59:11 PM (4 months ago)
Author:
joedolson
Message:

General: Remove support for IE conditional comments.

Remove the ability to enqueue scripts and styles wrapped in IE conditional comment tags. Conditional comment support was removed from IE in version 10 in 2012, and no core supported browser renders them in any way. IE9 has global usage approaching zero. WordPress dropped support for IE10 and below in version 4.8.

Patch adds a deprecation notice if the conditional data argument is added. Scripts and styles are not printed, and neither are their dependencies if they are not required by other non-conditional scripts. Conditional dependencies are removed from core enqueues.

Props jonsurrell, joedolson, shailu25, siliconforks, dmsnell, sabernhardt, rollybueno.
Fixes #63821.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-scripts.php

    r60931 r60948  
    293293
    294294        $obj = $this->registered[ $handle ];
     295        if ( $obj->extra['conditional'] ?? false ) {
     296            return false;
     297        }
    295298
    296299        if ( null === $obj->ver ) {
     
    304307        }
    305308
    306         $src                   = $obj->src;
    307         $strategy              = $this->get_eligible_loading_strategy( $handle );
    308         $intended_strategy     = (string) $this->get_data( $handle, 'strategy' );
    309         $ie_conditional_prefix = '';
    310         $ie_conditional_suffix = '';
    311         $conditional           = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
     309        $src               = $obj->src;
     310        $strategy          = $this->get_eligible_loading_strategy( $handle );
     311        $intended_strategy = (string) $this->get_data( $handle, 'strategy' );
    312312
    313313        if ( ! $this->is_delayed_strategy( $intended_strategy ) ) {
     
    334334        }
    335335
    336         if ( $conditional ) {
    337             $ie_conditional_prefix = "<!--[if {$conditional}]>\n";
    338             $ie_conditional_suffix = "<![endif]-->\n";
    339         }
    340 
    341336        $before_script = $this->get_inline_script_tag( $handle, 'before' );
    342337        $after_script  = $this->get_inline_script_tag( $handle, 'after' );
    343338
    344339        if ( $before_script || $after_script ) {
    345             $inline_script_tag = $ie_conditional_prefix . $before_script . $after_script . $ie_conditional_suffix;
     340            $inline_script_tag = $before_script . $after_script;
    346341        } else {
    347342            $inline_script_tag = '';
     
    379374                _print_scripts();
    380375                $this->reset();
    381             } elseif ( $this->in_default_dir( $filtered_src ) && ! $conditional ) {
     376            } elseif ( $this->in_default_dir( $filtered_src ) ) {
    382377                $this->print_code     .= $this->print_extra_script( $handle, false );
    383378                $this->concat         .= "$handle,";
     
    390385        }
    391386
    392         $has_conditional_data = $conditional && $this->get_data( $handle, 'data' );
    393 
    394         if ( $has_conditional_data ) {
    395             echo $ie_conditional_prefix;
    396         }
    397 
    398387        $this->print_extra_script( $handle );
    399 
    400         if ( $has_conditional_data ) {
    401             echo $ie_conditional_suffix;
    402         }
    403388
    404389        // A single item may alias a set of items, by having dependencies, but no source.
     
    454439            $attr['fetchpriority'] = $actual_fetchpriority;
    455440        }
     441
    456442        if ( $original_fetchpriority !== $actual_fetchpriority ) {
    457443            $attr['data-wp-fetchpriority'] = $original_fetchpriority;
    458444        }
    459445
    460         $tag  = $translations . $ie_conditional_prefix . $before_script;
     446        $tag  = $translations . $before_script;
    461447        $tag .= wp_get_script_tag( $attr );
    462         $tag .= $after_script . $ie_conditional_suffix;
     448        $tag .= $after_script;
    463449
    464450        /**
     
    850836        if ( ! isset( $this->registered[ $handle ] ) ) {
    851837            return false;
     838        }
     839
     840        if ( 'conditional' === $key ) {
     841            // If a dependency is declared by a conditional script, remove it.
     842            $this->registered[ $handle ]->deps = array();
    852843        }
    853844
Note: See TracChangeset for help on using the changeset viewer.