From b0fe9f059ca310578ac5e26c52861734ff18c454 Mon Sep 17 00:00:00 2001 From: desrosj Date: Tue, 22 Dec 2020 15:44:08 +0000 Subject: [PATCH] Twenty Twenty-One: Only load IE specific polyfills when actually using Internet Exploreer. The `twenty-twenty-one-ie11-polyfills` script now has a `null` source, and the new `twenty-twenty-one-ie11-polyfills-asset` (which points to the actual `polyfills.js` source) will be loaded only if IE is detected by through the use of `wp_get_script_polyfill()`. Because the original script name remains the same, this change is backwards compatible with any code registering `twenty-twenty-one-id11-polyfills` as a script dependency. Props poena, ismail.elkorchi, peterwilsoncc Fixes #52098. Built from https://develop.svn.wordpress.org/trunk@49865 git-svn-id: http://core.svn.wordpress.org/trunk@49584 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../themes/twentytwentyone/functions.php | 23 +++++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/wp-content/themes/twentytwentyone/functions.php b/wp-content/themes/twentytwentyone/functions.php index 652fc50db1..1139c3b659 100644 --- a/wp-content/themes/twentytwentyone/functions.php +++ b/wp-content/themes/twentytwentyone/functions.php @@ -396,7 +396,7 @@ add_action( 'after_setup_theme', 'twenty_twenty_one_content_width', 0 ); function twenty_twenty_one_scripts() { // Note, the is_IE global variable is defined by WordPress and is used // to detect if the current browser is internet explorer. - global $is_IE; + global $is_IE, $wp_scripts; if ( $is_IE ) { // If IE 11 or below, use a flattened stylesheet with static values replacing CSS Variables. wp_enqueue_style( 'twenty-twenty-one-style', get_template_directory_uri() . '/assets/css/ie.css', array(), wp_get_theme()->get( 'Version' ) ); @@ -416,14 +416,33 @@ function twenty_twenty_one_scripts() { wp_enqueue_script( 'comment-reply' ); } + // Register the IE11 polyfill file. wp_register_script( - 'twenty-twenty-one-ie11-polyfills', + 'twenty-twenty-one-ie11-polyfills-asset', get_template_directory_uri() . '/assets/js/polyfills.js', array(), wp_get_theme()->get( 'Version' ), true ); + // Register the IE11 polyfill loader. + wp_register_script( + 'twenty-twenty-one-ie11-polyfills', + null, + array(), + wp_get_theme()->get( 'Version' ), + true + ); + wp_add_inline_script( + 'twenty-twenty-one-ie11-polyfills', + wp_get_script_polyfill( + $wp_scripts, + array( + 'Element.prototype.matches && Element.prototype.closest && window.NodeList && NodeList.prototype.forEach' => 'twenty-twenty-one-ie11-polyfills-asset', + ) + ) + ); + // Main navigation scripts. if ( has_nav_menu( 'primary' ) ) { wp_enqueue_script( diff --git a/wp-includes/version.php b/wp-includes/version.php index a7ff2cce13..58e13eb26f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7-alpha-49864'; +$wp_version = '5.7-alpha-49865'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.