Make WordPress Core


Ignore:
Timestamp:
10/16/2025 07:59:11 PM (3 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-styles.php

    r60920 r60948  
    155155
    156156        $obj = $this->registered[ $handle ];
    157 
     157        if ( $obj->extra['conditional'] ?? false ) {
     158
     159            return false;
     160        }
    158161        if ( null === $obj->ver ) {
    159162            $ver = '';
     
    166169        }
    167170
    168         $src                   = $obj->src;
    169         $ie_conditional_prefix = '';
    170         $ie_conditional_suffix = '';
    171         $conditional           = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
    172 
    173         if ( $conditional ) {
    174             $ie_conditional_prefix = "<!--[if {$conditional}]>\n";
    175             $ie_conditional_suffix = "<![endif]-->\n";
    176         }
    177 
     171        $src          = $obj->src;
    178172        $inline_style = $this->print_inline_style( $handle, false );
    179173
     
    190184
    191185        if ( $this->do_concat ) {
    192             if ( $this->in_default_dir( $src ) && ! $conditional && ! isset( $obj->extra['alt'] ) ) {
     186            if ( $this->in_default_dir( $src ) && ! isset( $obj->extra['alt'] ) ) {
    193187                $this->concat         .= "$handle,";
    194188                $this->concat_version .= "$handle$ver";
     
    280274
    281275        if ( $this->do_concat ) {
    282             $this->print_html .= $ie_conditional_prefix;
    283276            $this->print_html .= $tag;
    284277            if ( $inline_style_tag ) {
    285278                $this->print_html .= $inline_style_tag;
    286279            }
    287             $this->print_html .= $ie_conditional_suffix;
    288280        } else {
    289             echo $ie_conditional_prefix;
    290281            echo $tag;
    291282            $this->print_inline_style( $handle );
    292             echo $ie_conditional_suffix;
    293283        }
    294284
     
    372362
    373363        return true;
     364    }
     365
     366    /**
     367     * Overrides the add_data method from WP_Dependencies, to allow unsetting dependencies for conditional styles.
     368     *
     369     * @since 6.9.0
     370     *
     371     * @param string $handle Name of the item. Should be unique.
     372     * @param string $key    The data key.
     373     * @param mixed  $value  The data value.
     374     * @return bool True on success, false on failure.
     375     */
     376    public function add_data( $handle, $key, $value ) {
     377        if ( ! isset( $this->registered[ $handle ] ) ) {
     378            return false;
     379        }
     380
     381        if ( 'conditional' === $key ) {
     382            $this->registered[ $handle ]->deps = array();
     383        }
     384
     385        return parent::add_data( $handle, $key, $value );
    374386    }
    375387
Note: See TracChangeset for help on using the changeset viewer.