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/tests/phpunit/tests/dependencies/scripts.php

    r60931 r60948  
    19601960     * Testing `wp_script_add_data` with the conditional key.
    19611961     *
     1962     * @expectedDeprecated WP_Dependencies->add_data()
     1963     *
     1964     * @since 6.9.0 Conditional comments should now return an empty string.
     1965     *
    19621966     * @ticket 16024
    19631967     */
     
    19661970        wp_enqueue_script( 'test-only-conditional', 'example.com', array(), null );
    19671971        wp_script_add_data( 'test-only-conditional', 'conditional', 'gt IE 7' );
    1968         $expected = "<!--[if gt IE 7]>\n<script type=\"text/javascript\" src=\"http://example.com\" id=\"test-only-conditional-js\"></script>\n<![endif]-->\n";
    1969 
    1970         // Go!
    1971         $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    1972 
    1973         // No scripts left to print.
    1974         $this->assertSame( '', get_echo( 'wp_print_scripts' ) );
    1975     }
    1976 
    1977     /**
    1978      * Testing `wp_script_add_data` with both the data & conditional keys.
    1979      *
    1980      * @ticket 16024
    1981      */
    1982     public function test_wp_script_add_data_with_data_and_conditional_keys() {
    1983         // Enqueue and add data plus conditional comments for both.
    1984         wp_enqueue_script( 'test-conditional-with-data', 'example.com', array(), null );
    1985         wp_script_add_data( 'test-conditional-with-data', 'data', 'testing' );
    1986         wp_script_add_data( 'test-conditional-with-data', 'conditional', 'lt IE 9' );
    1987         $expected  = "<!--[if lt IE 9]>\n<script type='text/javascript' id='test-conditional-with-data-js-extra'>\n/* <![CDATA[ */\ntesting\n//# sourceURL=test-conditional-with-data-js-extra\n/* ]]> */\n</script>\n<![endif]-->\n";
    1988         $expected .= "<!--[if lt IE 9]>\n<script type='text/javascript' src='http://example.com' id='test-conditional-with-data-js'></script>\n<![endif]-->\n";
    1989         $expected  = str_replace( "'", '"', $expected );
    1990 
    1991         // Go!
    1992         $this->assertEqualHTML( $expected, get_echo( 'wp_print_scripts' ) );
    1993 
    19941972        // No scripts left to print.
    19951973        $this->assertSame( '', get_echo( 'wp_print_scripts' ) );
     
    24042382
    24052383    /**
     2384     * @expectedDeprecated WP_Dependencies->add_data()
     2385     *
    24062386     * @ticket 14853
     2387     * @ticket 63821
    24072388     */
    24082389    public function test_wp_add_inline_script_after_and_before_with_concat_and_conditional() {
     
    24122393        $wp_scripts->default_dirs = array( '/wp-admin/js/', '/wp-includes/js/' ); // Default dirs as in wp-includes/script-loader.php.
    24132394
    2414         $expected_localized  = "<!--[if gte IE 9]>\n";
    2415         $expected_localized .= "<script type='text/javascript' id='test-example-js-extra'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n/* ]]> */\n</script>\n";
    2416         $expected_localized .= "<![endif]-->\n";
    2417         $expected_localized  = str_replace( "'", '"', $expected_localized );
    2418 
    2419         $expected  = "<!--[if gte IE 9]>\n";
    2420         $expected .= "<script type='text/javascript' id='test-example-js-before'>\n/* <![CDATA[ */\nconsole.log(\"before\");\n//# sourceURL=test-example-js-before\n/* ]]> */\n</script>\n";
    2421         $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    2422         $expected .= "<script type='text/javascript' id='test-example-js-after'>\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n";
    2423         $expected .= "<![endif]-->\n";
    2424         $expected  = str_replace( "'", '"', $expected );
     2395        // Conditional scripts should not output.
     2396        $expected_localized = '';
     2397        $expected           = '';
    24252398
    24262399        wp_enqueue_script( 'test-example', 'example.com', array(), null );
     
    24602433
    24612434    /**
     2435     * @expectedDeprecated WP_Dependencies->add_data()
     2436     *
    24622437     * @ticket 36392
     2438     * @ticket 63821
    24632439     */
    24642440    public function test_wp_add_inline_script_after_with_concat_and_conditional_and_core_dependency() {
    2465         global $wp_scripts, $wp_version;
    2466 
     2441        global $wp_scripts;
    24672442        wp_default_scripts( $wp_scripts );
    24682443
    24692444        $wp_scripts->base_url  = '';
    24702445        $wp_scripts->do_concat = true;
    2471 
    2472         $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=jquery-core,jquery-migrate&amp;ver={$wp_version}'></script>\n";
    2473         $expected .= "<!--[if gte IE 9]>\n";
    2474         $expected .= "<script type=\"text/javascript\" src=\"http://example.com\" id=\"test-example-js\"></script>\n";
    2475         $expected .= "<script type=\"text/javascript\" id=\"test-example-js-after\">\n/* <![CDATA[ */\nconsole.log(\"after\");\n//# sourceURL=test-example-js-after\n/* ]]> */\n</script>\n";
    2476         $expected .= "<![endif]-->\n";
     2446        $expected              = '';
    24772447
    24782448        wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null );
Note: See TracChangeset for help on using the changeset viewer.