• My wp-config file is set to disable caching in my staging environment, however WP Super Cache keeps re-writing my wp_config file to define WP_CACHE to true.

    When loading the plugin page /wp-admin/options-general.php?page=wpsupercache&tab=cdn, the plugin automatically attempts to write the WP_CACHE constant to my (very customized) wp-config.php file, which is causing problems.

    Here is the relevant block in my wp-config.php file:

    
    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:

    1. The $old search 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 using trim() in the comparison. I have tested this and it resolves the issue – the $old string is no longer found in the file.
    2. By resolving issue #1, the $new string is then added near the top of the wp-config.php file. This causes an error because the constant is already defined in the environment-specific config file which loads beforewp-config… and whywp-config will check if the constant is defined before setting a default value.
    3. 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 if WP_CACHE is already defined, or if DISABLE_SUPERCACHE is 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…

    1. Make wp-config non-writable. However this may disrupt other plugins.
    2. Perhaps I can set configuration value in wp-cache-config.php?? But I don’t see anywhere that the value is checked before wp_cache_check_global_config() is called.
    3. 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 staging and environment in 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.

    • This topic was modified 4 years, 6 months ago by skoskie. Reason: Minor formatting issues
    • This topic was modified 4 years, 6 months ago by skoskie. Reason: Minor formatting issues. And some typos
    • This topic was modified 4 years, 6 months ago by skoskie. Reason: Fixed double numbers on list items

The topic ‘Unable to disable caching in staging environment’ is closed to new replies.