Support » Plugin: Autoptimize » Changing the wp-content path to top level

  • Resolved Noahj

    (@brand-dedication)


    Hi,

    First. I’ve tried multiple plugins for speed, premium and free.

    Autoptimize has gotten me the highest results with no caching plugin use! Speed – 94. It also is playing nicer with the Javascript and inline css.

    I have one thing I am desperately trying to change.

    I want to reference my UPLOADS path instead of the WP_CONTENT_DIR path.

    I don’t want to reference the wp-content at all.

    My uploads path is already…
    MySite.com/data/content/public/

    I would like Autoptimize to be…
    MySite.com/data/content/public/cache/

    I’m not a champion coder and trying to achieve this myself by changing WP_CONTENT_DIR. to something like UPLOADS. obviously doesn’t work totally 🙂 – I get the caching files in the right place but I’m doing something wrong because the stylesheet is not applied.

    And no matter what value I have set for the define values in wp-config everything still references the wp-content path.

    Could you please tell me what I am doing wrong, how to fix it or any thing as to why this would not be good to do with Autoptimize if so?

    Thanks for this plugin!

    Going to write a 5 star review!

    https://wordpress.org/plugins/autoptimize/

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

    (@futtta)

    hi noahj;
    some questions about this part of your post:

    trying to achieve this myself by changing WP_CONTENT_DIR. to something like UPLOADS. obviously doesn’t work totally 🙂 – I get the caching files in the right place but I’m doing something wrong because the stylesheet is not applied.

    1. “changing WP_CONTENT_DIR. to something like UPLOADS” did you also change WP_CONTENT_URL (you should)?
    2. “I get the caching files in the right place” means the URL’s pointing to CSS/ JS in your HTML are correct?
    3. “the stylesheet is not applied” means JS is working? or is that broken as well?
    4. “the stylesheet is not applied” when you look at the contents of the aggregated CSS files, is there anything in there, or are they empty or do you get a 404 (page not found)?

    kind regards,
    frank

    Noahj

    (@brand-dedication)

    Hi Frank!

    Hey, thanks for responding.

    I should clear this up.

    I get the directories in the right place but I get no optimized files there. So this is the problem where I am not covering something.

    Are you referring to the WordPress WP_CONTENT_URL or the plugin’s AUTOPTIMIZE_WP_CONTENT_URL?

    I don’t find ay WP_CONTENT_URL in Autoptimize.

    For changing the WordPress WP_CONTENT_URL sitewide, I chose against it because it slowed the backend of WordPress down quite a bit.

    So the only pathway I have changed is my UPLOADS path.

    Where uploads actually handles all content that would be public.

    And wp-content can be what it is, WordPress related, plugins, themes, etc.

    I tried to seperate the focuses of the 2 directories, public content vs. system (WordPress) content.

    Plugin Author Frank Goossens

    (@futtta)

    Hmmm, as it stands, autoptimize is hardcoded to output aggregated files to the wordpress wp-content-directory, whatever it may be named, relying on wp_content_url (via the function content_url()) and wp_content_dir (both of which are part of WordPress core, they’re not AO-specific).

    So if you’d want autoptimize to output aggregated files elsewhere (i.e. in our uploads directory), you’d have to make changes to the plugin’s code, rather then using API-functions or changes to wp-config.php I’m afraid.

    Pretty surprised that changing wp-content_url sitewide impacted your wordpress backend …

    frank

    Noahj

    (@brand-dedication)

    Hi Frank,

    Making changes to the code is fine.

    Just let me know if you would help me with where I am at or point me to the place I need to focus on.

    Here is what I have in the code. I added the AUTOPTIMIZE_CONTENT_URL definition.

    if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) { define('AUTOPTIMIZE_WP_CONTENT_URL','/data'); }
    if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) { define('AUTOPTIMIZE_WP_CONTENT_NAME','/data'); }
    if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) { define('AUTOPTIMIZE_CACHE_CHILD_DIR','/content/public/cache/'); }
    if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) { define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'cached_'); }

    Either way the only problem I seem to be having is the files are being created in the directories. Not a pro, but I find it weird the directories are being created, the file references in the html output are there as well, but just no actual files created to match those html output references.

    It seems like just a small thing is missing that is not allowing the files to be created.

    Any idea what to look at?

    I’ve been messing with is since and have tried a lot of combinations, etc. I stopped with the code above as to where I think I made the most relevant progress, which leads to me to look somewhere else in the code to change since everything else seems to be working.

    Noahj

    (@brand-dedication)

    I should mention that I cleaned my htaccess to the default to make sure that wasn’t the problem of writing, other the directory permissions either. Autoptimize says that it can write and is, but just not the actual optimized files.

    Plugin Author Frank Goossens

    (@futtta)

    Ah, you’ll also have to change autoptimize_cache_dir (which uses WP_CONTENT_DIR) to tell AO where to write the files (vs autoptimize_cache_url which is for AO to inject the correct URL’s in the HTML). This is how it is set by default:

    if (is_multisite()) {
    	$blog_id = get_current_blog_id();
    	define('AUTOPTIMIZE_CACHE_DIR' , WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/' );
    } else {
    	define('AUTOPTIMIZE_CACHE_DIR',WP_CONTENT_DIR.AUTOPTIMIZE_CACHE_CHILD_DIR);
    }

    frank

    Noahj

    (@brand-dedication)

    Hi Frank,

    Thanks!

    2 things.

    1. I messed around with this. I think it may be something more?
    – If you can’t provide an example off hand of what to make AUTOPTIMIZE_CACHE_DIR don’t sweat it. I don’t want to use up your time for an coding change. It might just be because I had no sleep while trying this, but nothing I did for 30-60 minutes worked. I tried other things as well.

    2. I left it at the default settings because reading and clearing the cache doesn’t work with a different directory or prefix reference at all.
    – I tried even just change the prefix alone. Even just that small change and cleaning the cache from the settings doesn’t work. It also can’t read that area. I checked permissions, and tried other things to test it. No matter what if the default is changed it won’t read or clean up the cache.

    Have you experienced that issue lately?

    Plugin Author Frank Goossens

    (@futtta)

    1. I would probably try to set;

    • AUTOPTIMIZE_CACHE_DIR to something like /var/www/MySite.com/data/content/public/ (so the full path on the filesystem of your server)
    • AUTOPTIMIZE_CACHE_CHILD_DIR to “cache/”
    • AUTOPTIMIZE_CACHE_URL to “/data/content/public/cache/”

    2. I’ll retest that, should work really. I’ll update this thread once I have more info.

    frank

    Plugin Author Frank Goossens

    (@futtta)

    regarding (2); I can confirm there’s a bug when AUTOPTIMIZE_CACHEFILE_PREFIX is set, in which case the cache won’t be flushed as the cache flushing code explicitly looks for “autoptimize” in the filename.

    the fix (which will be in Autoptimize 1.9.3); open up /wp-content/plugins/autoptimize/classes/autoptimizeCache.php and on line 81 change

    if(!in_array($file,array('.','..')) && strpos($file,'autoptimize') !== false && is_file($thisAoCacheDir.$file)) {

    into:

    if(!in_array($file,array('.','..')) && strpos($file,AUTOPTIMIZE_CACHEFILE_PREFIX) !== false && is_file($thisAoCacheDir.$file)) {

    thanks for pointing this out 🙂

    frank

    Noahj

    (@brand-dedication)

    Thanks Frank!

    That looks very complex. Why not make AUTOPTIMIZE_CACHE_DIR a setting?
    The url/content/wp defines are very complex now I’ll break something.

    AUTOPTIMIZE_CACHE_URL gets overwritten with AUTOPTIMIZE_CACHE_CHILD_DIR why do I need to change it?

    Plugin Author Frank Goossens

    (@futtta)

    Hi funsail;
    Creating a settings-page requires finding the right balance between adding enough options and keeping it light. Hence those all that are considered as important to all users are on the settings screen, while for other settings “sensible defaults” are used which can be overridden with the API (of which I consider the constants a part). Using that API one can for example change name of the sub-directory and the prefix of the autoptimized files. Moving outside of wp-content currently is not supported (it might be, in the future)

    AUTOPTIMIZE_CACHE_URL gets overwritten with AUTOPTIMIZE_CACHE_CHILD_DIR why do I need to change it?

    Indeed normally AUTOPTIMIZE_CACHE_URL is not one of the constants one can override, as it is based on AUTOPTIMIZE_WP_CONTENT_URL (which is based on WordPress’s content_url()) and AUTOPTIMIZE_CACHE_CHILD_DIR. As NoahJ described here he made changes in autoptimize.php to be able to break out of the wp-content context. If you absolutely want AO not to write to a subdirectory of /wp-content (or a renamed directory that WordPress knows to be equivalent to wp-content), then you will have to make similar changes to your autoptimize.php as well.

    Hope this explains,
    frank

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Changing the wp-content path to top level’ is closed to new replies.