Roots Discourse

Overcoming bedrock autoloader issues w/ w3-total-cache

I ran into an interesting issue trying to install w3 total cache as a mu-plugin.

The plugin creates an advanced-cache.php file. That file contains a hardcoded reference to the standard plugin directory:

if ( !defined( 'W3TC_DIR' ) ) {
	define( 'W3TC_DIR', ( defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins' ) . '/w3-total-cache' );
}

The simple fix is to define W3TC_DIR in config/application.php:

Config::define('W3TC_DIR', Config::get( 'WP_CONTENT_DIR' ) . '/mu-plugins/w3-total-cache' );

That lead to another issue where I realized a second constant is necessary:

Config::define( 'W3TC_EXTENSION_DIR', ( Config::get('WP_CONTENT_DIR') . '/mu-plugins' ) );

Finally I hope, a redirect is necessary for frontend assets thanks to this gist:

rewrite ^/(?:[_0-9a-zA-Z-]+/)?app/plugins/w3-total-cache/(.*) /app/mu-plugins/w3-total-cache/$1 last;

Is this more trouble than it’s worth? I’m not sure yet.