WordPress.org

Ready to get started?Download WordPress

Forums

Autoptimize
[resolved] Layout breaks after file moving (24 posts)

  1. blog-it-solutions
    Member
    Posted 1 year ago #

    Hi futtta,

    me again and a second problem: I moved my wordpress installation from the root folder to a subfolder. After activating the option "Optimize CSS Code?" the whole page is broken. If I am logged in on wordpress the layout is fine (because Autoptimize doesn't work).

    Do you have any idea what is not correct? Could it be a permission problem?

    Here is the link to my page: Blog IT-Solutions

    Thanks, Josef

    http://wordpress.org/extend/plugins/autoptimize/

  2. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    Layout looks OK now? It's important to change the "wordpress url" (which would be in that case be different from the "site url").

  3. blog-it-solutions
    Member
    Posted 1 year ago #

    At the moment yes, because I set Optimize CSS Code to OFF. If I set the option to ON then the whole layout will break. Yes, the wordpress url is different from the site url. All other things are working fine again. I only have problems with the layout if I active the Optimize CSS Code option in Autoptimize.

    But I want to active the option again.

  4. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    OK, best way forward would be to very briefly activate the option again so we can look at the HTML (and specifically the full URL of the aggregated CSS-file). Could you do that for 5 minutes at let's say 12h45, so I can have a look?

  5. blog-it-solutions
    Member
    Posted 1 year ago #

    Ok, can we do it at 12h30? I will post an entry here if I have done it. Ok?

  6. blog-it-solutions
    Member
    Posted 1 year ago #

    Ok, lets take 12h45. Ok?

  7. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    had lunch, ready when you are :)

  8. blog-it-solutions
    Member
    Posted 1 year ago #

    done :-) Let's go ;-)

  9. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    ok, you can turn it back off now.

  10. blog-it-solutions
    Member
    Posted 1 year ago #

    ok, thanks. Do you have found the problem?

  11. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    not yet, looking at source now, i'll keep you posted :-)

  12. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    Can you describe step by step how you "moved my wordpress installation from the root folder to a subfolder"?

  13. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    disregard the previous question :-)

    the problem is probably caused by the fact that "/bits/" is not in the URL, but is in ABSPATH. if so, this confuses Autoptimize's getpath-function (in classes/autoptimizeBase.php), causing Autoptimize to look for /var/www/yoursite/bits/bits/wp-content/theme/whatever.css instead of /var/www/yoursite/bits/wp-content/theme/whatever.css.

    can you open up /wp-content/plugins/autoptimize/autoptimize.php and after the header comment block add:

    echo WP_CONTENT_DIR."<br />";
    echo ABSPATH."<br />";

    load your blog and post these values here? you can (off course) remove those lines immediately after :-) based on the output of the above, I should be able to confirm my hypothesis and re-write the getpath function.

  14. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    Well, nothing like a good night's sleep to find the most simple of solutions! Forget about all the above, just open up wp-content/plugins/autoptimize/classes/autoptimizeBase.php and at the bottom replace

    //Converts an URL to a full path
    	protected function getpath($url)
    	{
    		$path = str_replace(get_settings('home'),'',$url);
    		if(preg_match('#^(https?|ftp)://#i',$path))
    		{
    			//External script (adsense, etc)
    			return false;
    		}
    		$path = str_replace('//','/',ABSPATH.$path);
    		return $path;
    	}

    with the much more solid

    //Converts an URL to a full path
    	protected function getpath($url)
    	{
            	$path = str_replace(WP_CONTENT_URL,'',$url);
    	        if(preg_match('#^(https?|ftp)://#i',$path))
            	{
                    	/**
    			External script/css (adsense, etc)
    			Or script/ css just not in wp_content
    			*/
                		return false;
                	}
            	$path = str_replace('//','/',WP_CONTENT_DIR.$path);
            	return $path;
    	}

    I'm 99% sure this solves the -slightly obscure ;-) - bug you found.

  15. blog-it-solutions
    Member
    Posted 1 year ago #

    Thanks for your response :-)

    Now I replaced the getpath-function with the new one. But it still doesn't work. After replacing the function I implemented the echo commands you mentioned two post above. I received the following results:

    /var/www/yoursite/html/bits/wp-content
    /var/www/yoursite/html/bits/

    In fact, it seems that the paths are correct now. But the layout still breaks.
    But I found a new hint in the network logs of firebug:

    http://www.blog-it-solutions.de/wp-content/themes/iblog/css/custom.css 404 Not found

    This problem also occurs for all other css-files. In result, there must be another function which is using the wrong path. Do you still have any ideas?

  16. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    damn, I hoped I had nailed this one :-)

    anyway, can you:

    • add the following to wp-content/plugins/autoptimize/autoptimize.php:
      echo WP_CONTENT_DIR."<br />";
      echo WP_CONTENT_URL."<br />";
      $bloginfourl = get_bloginfo('url');
      echo $bloginfourl."<br />";
    • re-enable css optimization?
    • clear both autoptimize & wp super cache cache?
    • send me the resulting html (futtta at gmail dot com)
  17. blog-it-solutions
    Member
    Posted 1 year ago #

    I have sent you a mail with the results :-)

  18. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    Did you get my latest mail Josef? I'd like to have a look at the resulting HTML source when CSS optimization is activated, can you mail that to me?

  19. blog-it-solutions
    Member
    Posted 1 year ago #

    Hey, sorry for the late response. I answered you via e-mail (including the html source code) a few minutes ago :-)

  20. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    OK, we're on to something; the problem is related to the fact that the imports in themes/iblog/style.css are relative.

    Now this in handled in wp-content/plugins/autoptimize/classes/autoptimizeStyles.php in the fixurls function at the bottom.

    So ... can you replace the code there with this and see if that fixes things:

    private function fixurls($file,$code)
            {
                    $file = str_replace(WP_CONTENT_DIR,'/',$file);
                    $dir = dirname($file); //Like /wp-content
    
                    if(preg_match_all('#url\((.*)\)#Usi',$code,$matches))
                    {
                            $replace = array();
                            foreach($matches[1] as $k => $url)
                            {
                                    //Remove quotes
                                    $url = trim($url," \t\n\r\x0B\"'");
                                    if(substr($url,0,1)=='/' || preg_match('#^(https?|ftp)://#i',$url))
                                    {
                                            continue;
                                    }else{
                                            $newurl = WP_CONTENT_URL.str_replace('//','/',$dir.'/'.$url);
                                            $hash = md5($url);
                                            $code = str_replace($matches[0][$k],$hash,$code);
                                            $replace[$hash] = 'url('.$newurl.')';
                                    }
                            }
    
                            $code = str_replace(array_keys($replace),array_values($replace),$code);
                    }
    
                    return $code;
            }

    (crossing my fingers now)

  21. blog-it-solutions
    Member
    Posted 1 year ago #

    Awesome! It works great again :-) Thanks a lot for your help.

  22. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    You're welcome Josef, thanks for you patience & continuous feedback. I'll make sure to mention you in the release notes of the next version (which I'm working on now).

  23. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Josef;
    I'm finalizing 1.6.0 and ran into a problem with the getpath-function I posted above. Can you replace with this one and report if that works for you as well?

    protected function getpath($url)
            {
                    $path = str_replace(site_url(),'',$url);
                    if(preg_match('#^(https?|ftp)://#i',$path))
                    {
                            /**
                            External script/css (adsense, etc)
                            */
                            return false;
                    }
                    $path = str_replace('//','/',ABSPATH.$path);
                    return $path;
            }

    thanks!

  24. Frank Goossens
    Member
    Plugin Author

    Posted 1 year ago #

    Nah, that won't work, as $path will start with /bits/ and ABSPATH will end with that same string. I'll have to think some more.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.