How to enable/Configure WPSC programatically – no WP-Cli?
-
Using WP Super Cache in an oldstyle Webhosting environment was easy:
1) enable plugin
2) enable caching in plugin settings and configure
3) done for good
Just like every other plugin in the world 😉Now we deploy our WordPress Sites into a docker environment from a clean git repo checkout using CI/CD tools, and we’re encountering difficulties fully enabling WP Super Cache after every deployment.
In addition to setting WP_CACHE and WPCACHEHOME (which is done upon deployment), we have to do multiple manual or script-driven steps.
After every fresh deployment, wp-cache-config.php and advanced-cache.php are missing – since they are generated at runtime and contain dynamic information, we can not keep them in the repo. Also the configuration values are not persistent in wp_options, thus every fresh deployed container is coming up unconfigured with no caching in spite of wpsc being enabled. Then, we have to:
1) trigger creation of advanced-cache.php
( using wp_cache_create_advanced_cache() )
2) trigger creation of wp-cache-config.php
( using wp_cache_verify_config_file() )
3) re-configure the plugin-settings, specifically set cache_enabled and super_cache_enabled to 1, otherwise no caching at all takes place
( using a lot of wp_cache_setting() calls )I was hoping there would be wpcli commands to enable and configure WPSC, but it seems as if these are no longer present in 3.x (right?) So we were forced to create a plugin that exposes a wpcli command to perform all the listed activities using the global functions we found in wp-cache.php (not sure whether I picked the best ones ). This wpcli command is then being called after deployment.
This kind of works, but is very clumsy and errorprone, and I lost my trust that the cache will be present after every deployment.
Bottom Line:
What is the most reliable and efficient way to either programmatically enable WPSC in a CD/CI environment, or to keep its activation and configuration persistently in the DB like regular plugins do? Are there any best practices, recommended hooks, or alternative methods within WPSC itself?Regards,
Ulrich
You must be logged in to reply to this topic.