Unable to disable caching in staging environment
-
My
wp-configfile is set to disable caching in my staging environment, however WP Super Cache keeps re-writing mywp_configfile to defineWP_CACHEtotrue.When loading the plugin page
/wp-admin/options-general.php?page=wpsupercache&tab=cdn, the plugin automatically attempts to write theWP_CACHEconstant to my (very customized)wp-config.phpfile, which is causing problems.Here is the relevant block in my
wp-config.phpfile:defined('WP_CACHE') ?: define('WP_CACHE', ENV_PROD); // Used by WP Super Cache define('WPCACHEHOME', '/srv/users/client/apps/client-' . ENV . '/public/wp-content/plugins/wp-super-cache/'); if(!WP_CACHE) define('DISABLE_SUPERCACHE', 1);There are two issues:
- The
$oldsearch param does not detect that the text is part of a conditional. This can be easily remedied, however by adding the^regex character on this line. It will work even on indented lines because you are usingtrim()in the comparison. I have tested this and it resolves the issue – the$oldstring is no longer found in the file. - By resolving issue #1, the
$newstring is then added near the top of thewp-config.phpfile. This causes an error because the constant is already defined in the environment-specific config file which loads beforewp-config… and whywp-configwill check if the constant is defined before setting a default value. - Perhaps the biggest issue here is that I don’t understand why it is necessary to call the
wp_cache_replace_line()function at all ifWP_CACHEis already defined, or ifDISABLE_SUPERCACHEis set to true. It seems it can only cause problems or circumvent existing logic in the config file.
Here are the possible solutions that I have considered…
- Make
wp-confignon-writable. However this may disrupt other plugins. - Perhaps I can set configuration value in
wp-cache-config.php?? But I don’t see anywhere that the value is checked beforewp_cache_check_global_config()is called. - I could try to use a hook, but I don’t see one called by
wp_cache_check_global_config()function.
I have searched the support forum with no success. I have searched for
stagingandenvironmentin the plugin source code, but found nothing. Perhaps I am missing an important part of the puzzle?Key Question:
Is there any way to disable cache on a staging environment, and prevent cache from being re-enabled by the plugin?
Thank you in advance for your help.
- The
The topic ‘Unable to disable caching in staging environment’ is closed to new replies.