Support » Plugins and Hacks » Autoptimize » Incompatibility with WP 4.7: Aggregate Inline CSS

  • Hi,

    it seems there is an incompatibility with WP 4.7. As soon as the option “Also aggregate inline CSS” is checked, the path for the custom background image in WP is incorrect and background images won’t display anymore.

    Aggregate inline CSS

Viewing 15 replies - 1 through 15 (of 28 total)
  • Plugin Author Frank Goossens

    (@futtta)


    what is the path to the background image before and after autoptimize @mh-themes?

    Before it is:

    /example.com/...

    After it is:

    /example.com/example.com/...

    • This reply was modified 1 month, 1 week ago by  MH Themes.
    Plugin Author Frank Goossens

    (@futtta)


    Just tested in twentysixteen & twentyseventeen and seems to work OK there?

    Plugin Author Frank Goossens

    (@futtta)


    so what theme should I be testing with @mh-themes? 🙂

    As far as we know, Twenty Seventeen doesn’t have a custom background option and with Twenty Sixteen the issue occurs as well.

    We’ve had a few reports from users and after either disabling the Autoptimize plugin or disabling the mentioned option in the plugin, the issue was resolved. You can reproduce the issue with MH Magazine lite as well.

    The theme simply makes use of the WP core background feature:

    add_theme_support('custom-background', array('default-color' => 'f7f7f7'));

    But now with WordPress 4.7 the Autoptimize plugin breaks the path to the uploaded background image as soon as the mentioned “Also aggregate inline CSS” option is enabled.

    It’s worth mentioning though that the “Optimize HTML Code” and “Save aggregated script/css as static files” options are enabled as well. Maybe that helps to replicate the issue.

    Plugin Author Frank Goossens

    (@futtta)


    yeah, was looking at header images instead of background images, can confirm something is wrong, looking into it ..

    Plugin Author Frank Goossens

    (@futtta)


    ok, the problem is the URL is url-encoded;

    
    background-image: url("http:\/\/localhost\/wordpress\/wp-content\/uploads\/layerslider\/Full-width-demo-slider\/left.png");

    wondering why they do this?

    Plugin Author Frank Goossens

    (@futtta)


    well, addslashes-d rather then url-encoded, but still just as painful 🙁

    Thanks for looking into it. 🙂

    Plugin Author Frank Goossens

    (@futtta)


    asking around on slack & fb (adv. wp) if this is a bug or a feature 😉

    Plugin Author Frank Goossens

    (@futtta)


    confirmed to be a bug/ regression; https://core.trac.wordpress.org/ticket/39145#comment:1

    Good to know, thanks. In that case it should be fixed soon. 🙂

    Plugin Author Frank Goossens

    (@futtta)


    workaround snippet;

    add_filter('autoptimize_filter_html_before_minify','fix_encoded_urls');
    function fix_encoded_urls($htmlIn) {
    	if ( strpos($htmlIn,"body.custom-background") !== false ) {
    		preg_match_all("#background-image:\s?url\(?[\"|']((http(s)?)?:\\\/\\\/.*)[\"|']\)?#",$htmlIn,$badUrls);
    	  	if ($badUrls) {
    			foreach ($badUrls[1] as $badUrl) {
    				$htmlIn = str_replace($badUrl, stripslashes($badUrl), $htmlIn);
    			}
    		}
    	}
      	return $htmlIn;
    }

    might need some more testing 😉

    It works – Thank you for your snippet

    Hi

    Could you write me a very simple and very carefully how to do it? I am a beginner and I can not very well programmed

    Where do I paste this fix? I have a child theme

    When I pasted fix to the Function.php file just after <?php in my theme child – it did not work

Viewing 15 replies - 1 through 15 (of 28 total)
  • You must be logged in to reply to this topic.