kasparsd / minit

A WordPress plugin to combine CSS and Javascript files.
GNU General Public License v2.0
286 stars 46 forks source link

root relative urls in css are being meesed up #87

Open diegodorado opened 8 years ago

diegodorado commented 8 years ago

I have to change minit-css.php on line 88, because root relative urls were being messed up.

this is what i changed:

// Make all local asset URLs absolute
        $content = preg_replace(
            '/url\(["\' ]?+(?!data:|https?:|\/\/|\/)(.*?)["\' ]?\)/i',
            sprintf( "url('%s/$1')", $this->handler->base_url . dirname( $src ) ),
            $content
        );

Note the |\/ addition to the regex, to avoid replacing root relative urls.

I understand that having root relative urls in css isnt a very good practice, at least for wordpress, but it happened that i already have them.

Beside that, the plugin is absolutly great as simple! Just what i needed

kasparsd commented 8 years ago

@diegodorado Thanks you for reporting the issue. Could you please post the "messed up" URL that it generated?

diegodorado commented 8 years ago

Sure:

say I have a style.css file inside wp-content/themes/mytheme/ with the following rule

some.selector{ background: url(/wp-content/uploads/some-img.jpg); }

(I know, I know.... bad practices)

then, after minit run, it concat site_url + css_path + content, so and I end up with

some.selector{ background: url(http://mysite.url/wp-content/themes/mytheme//wp-content/uploads/some-img.jpg); }

Anyway, good or bad practice, I think that following urls shouldnt be touched:

kasparsd commented 8 years ago

Great, thank you @diegodorado! That will help during testing.

szepeviktor commented 8 years ago

@diegodorado I was in your shoe. That is why I developed a ultra-simplified but proper theme options page.

diegodorado commented 8 years ago

And again: great work... i ve been trying out several popular plugins but this is the only only that gave me a single js and a single css output, without breaking the site...I was going to do it by myslef, but you saved me a lot of work.

diegodorado commented 8 years ago

@szepeviktor , sorry, i dont get it, what does proper theme options page do with this respect?

szepeviktor commented 8 years ago

If you have an options page you don't have to hardcode /wp-content/uploads/.