• Resolved kimsf

    (@kimsf)


    It seems that wp-polyfill was removed from being loaded in WordPress 5.8. What’s the best way to add back wp-polyfill being loaded in wp-admin? It would be great if it’s in functions.php. I need polyfill in wp-admin and currently running in 5.7.2 due to this issue. I’m running custom programs that interact with the dashboard that use IE 11 and I’m unable to switch browsers.

    IE 11 support was removed from WordPress 5.8 according to this post: https://make.www.ads-software.com/core/2021/06/28/miscellaneous-developer-focused-changes-in-wordpress-5-8/

    The following code was removed from WP 5.8 in the file wp-includes/script-loader.php:

    $scripts->add( 'wp-polyfill', null, array( 'wp-polyfill' ) );
    			did_action( 'init' ) && $scripts->add_inline_script(
    				'wp-polyfill',
    				wp_get_script_polyfill(
    					$scripts,
    					array(
    						'\'fetch\' in window' => 'wp-polyfill-fetch',
    						'document.contains'   => 'wp-polyfill-node-contains',
    						'window.DOMRect'      => 'wp-polyfill-dom-rect',
    						'window.URL && window.URL.prototype && window.URLSearchParams' => 'wp-polyfill-url',
    						'window.FormData && window.FormData.prototype.keys' => 'wp-polyfill-formdata',
    						'Element.prototype.matches && Element.prototype.closest' => 'wp-polyfill-element-closest',
    						'\'objectFit\' in document.documentElement.style' => 'wp-polyfill-object-fit',
    					)
    				)
    			);
    		
    
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @kimsf. I think that wp-polyfill is still registered, so does adding the inline script to your functions.php and enqueuing it work?

    function my_theme_scripts() {
    	global $wp_scripts;
    	$wp_scripts->add_inline_script(
    		'wp-polyfill',
    		wp_get_script_polyfill(
    			$scripts,
    			array(
    				'\'fetch\' in window' => 'wp-polyfill-fetch',
    				'document.contains'   => 'wp-polyfill-node-contains',
    				'window.DOMRect'      => 'wp-polyfill-dom-rect',
    				'window.URL && window.URL.prototype && window.URLSearchParams' => 'wp-polyfill-url',
    				'window.FormData && window.FormData.prototype.keys' => 'wp-polyfill-formdata',
    				'Element.prototype.matches && Element.prototype.closest' => 'wp-polyfill-element-closest',
    				'\'objectFit\' in document.documentElement.style' => 'wp-polyfill-object-fit',
    			)
    		)
    	);
    	wp_enqueue_script( 'wp-polyfill' );
    }
    add_action( 'wp_enqueue_scripts', 'my_theme_scripts' );
    
    Thread Starter kimsf

    (@kimsf)

    @noisysocks

    Adding scripts did work after other issues were dealt with.

    I finally got this resolved. It turns out that load-scripts.php is no longer IE 11/Trident friendly and will cause a JS error on line 10. This error prevents jquery from loading which makes the whole backend almost non-functional for internet explorer 11.

    For anyone else with this issue, the most elegant solution I’ve come up with is adding this code to your themes functions.php:

    function load_ie_11_trident_scripts(){ 
    	wp_deregister_script('jquery');
    	wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js');
        wp_enqueue_script('wp-polyfill-dom-rect'); 
    	wp_enqueue_script('wp-polyfill-element-closest'); 
    	wp_enqueue_script('wp-polyfill-fetch'); 
    	wp_enqueue_script('wp-polyfill-formdata'); 
    	wp_enqueue_script('wp-polyfill-node-contains'); 
    	wp_enqueue_script('wp-polyfill-object-fit'); 
    	wp_enqueue_script('wp-polyfill-url'); 
    	wp_enqueue_script('regenerator-runtime');
    }
     	add_action( 'admin_enqueue_scripts', 'load_ie_11_trident_scripts');
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to load wp-polyfill in WP 5.8 admin?’ is closed to new replies.