Better control over the cache location
Re: https://wordpress.org/support/topic/change-the-location-where-files-are-cached/ https://wordpress.org/support/topic/move-litespeed-folder-location/
On all of my sites, I want the Litespeed cache directory to be wp-content/cache/litespeed, and it seems I'm not the only one. The advice to use wp-config.php constants based on WP_CONTENT_DIR doesn't work, because that constant is only defined later in the code.
Better option 1
Provide filters on all of the constants in litespeed-cache.php, but particularly on LITESPEED_STATIC_DIR and LITESPEED_STATIC_URL, because those will be processed later, when WP_CONTENT_DIR is already defined, and other site-specific definitions can be used.
Using filters will also allow overriding cache locations in a generic way via a plugin, which can then be installed on multiple sites with the same code. Being a developer feature prevents non-technical users from being scared and/or making mistakes.
Better option 2
Provide plugin settings for the cache location directory. One setting to override the use of WP_CONTENT_DIR should do the trick, because it can then be used for both constants.
Better option 3
Use public global variables, which can be changed with code, instead of constants.
3 weeks and no response?
Still nothing? 😞
PLEASE, can I at least get a response?
It's been a while, but no change, although this really seems like an easy thing to implement.
This issue celebrated its first birthday last month...
And still, nothing 😞
Hi @galbaras Sorry for late response. Thanks for following up.
The advice to use wp-config.php constants based on WP_CONTENT_DIR doesn't work, because that constant is only defined later in the code. Can you tell more about why can't use
WP_CONTENT_DIR? Its default value is defined inwp-settings.phpwhich is loaded afterwp-config.phpdefinitions and before LSCWP init. So if you define it inwp-config.php, it will affect LSCWP.
The about question is just out of curiosity. I believe to move /litespeed to /cache/litespeed, changing WP's content constant isn't a good practice.
Another question is, is there any reason you can't define these consts to redirect the folder?
I agree. That's why I suggested a filter, which will be applied in litespeed-cache.php, when all the constants and all the site options can be used. It's both easy to implement and standard for WordPress plugins, so why not just do it?
Just change lines 60 & 61 to this:
!defined( 'LITESPEED_STATIC_URL' ) && define( 'LITESPEED_STATIC_URL', apply_filters( 'litespeed_static_url', $WP_CONTENT_URL . '/litespeed' ) ); // Full static cache folder URL '//example.com/wp-content/litespeed'
!defined('LITESPEED_STATIC_DIR') && define('LITESPEED_STATIC_DIR', apply_filters( 'litespeed_static_dir', LSCWP_CONTENT_DIR . '/litespeed' ) ); // Full static cache folder path '/var/www/html/***/wp-content/litespeed'
It seems not the answer to my question. Why not using constants define but filters to make it? Filters have lower efficiency IMO?
The problem with constants is that they are defined in wp-config.php, and things like home_url() aren't defined by then.
Defining constants in functions.php is too late, because the plugin has been loaded by then. Now that I think about it, it also means that filters defined in function.php won't work either to override the plugin's constants.
Why not add this as an "autoload" plugin setting? Autoloaded options may extend loading time by a small fraction of a second.
Anyway, my motivation for this was related to backups, and I've found a way around it, so I'm just going to close this issue, but I still think site owners should have control over this without programming.
Adding an option to setting is an option, however its kind of advanced and less used for most users, IMO its a bit overkill.
I agree this requirement is a must in certain cases, how do you think we put the folder name to a const so you can define it in any early stage?
If LITESPEED_DATA_FOLDER idea can work, we can add it to next release.
It's easier to define one constant than it is to define two, and using that in both of the other constants is a good idea for sure, especially since it's relative to the WP content folder.
That's a very clever way of doing it so that it doesn't depend on the root path/URL. Well done.
It is added into https://github.com/litespeedtech/lscache_wp/commit/270381e5e102a16436e264be4904420c8b11dfff Please confirm if its as expected or not. TIA.
I've copied only the constant definition changes to the plugin on one of my sites and added this to wp-config.php:
define( 'LITESPEED_DATA_FOLDER', 'cache/litespeed' );
After clearing all caches and reloading the home page, resources are being stored in the right place and retrieved from that place correctly. This works. Thank you!
Great to hear that! Good day!