BoldGrid / w3-total-cache

GNU General Public License v2.0
153 stars 86 forks source link

object-cache.php does not check that the plugin is enabled / object cache is enabled #1003

Open jamieburchell opened 5 days ago

jamieburchell commented 5 days ago

When adding object-cache.php to the wp-content directory, the object cache is enabled and files are written to disk at cache/object/key_version_all even when the W3TC plugin is not installed / the object cache feature is disabled.

In advanced-cache.php there are checks such as if ( $w3tc_config->get_boolean( 'pgcache.enabled' ) ) but there are no such checks in object-cache.php.

This is important to me, because my deployment process ensures that the advanced-cache.php and object-cache.php files are copied to the correct locations (which are not writable by WordPress). In that case, the object cache can become enabled even when I've told it not to be.

Perhaps something like this?

    ...

    require_once W3TC_DIR . '/w3-total-cache-api.php';

    $w3tc_config = \W3TC\Dispatcher::config();
    if ( ! $w3tc_config->get_boolean( 'objectcache.enabled' ) ) {
        return;
    }

    /**
     * Init cache
     *
     * @return void
     */
    function wp_cache_init() {
    ...