Skip to content

Instantly share code, notes, and snippets.

@kurtpayne
Created February 21, 2012 00:55
Show Gist options
  • Save kurtpayne/1872650 to your computer and use it in GitHub Desktop.
Save kurtpayne/1872650 to your computer and use it in GitHub Desktop.
W3TC Autoconfigurator
<?php
// Activate W3 Total Cache
if ( file_exists( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' ) )
activate_plugin( WP_PLUGIN_DIR . '/w3-total-cache/w3-total-cache.php' , admin_url() );
// Load host specific W3TC config
if ( defined( 'W3TC_CONFIG_PATH' ) ) {
// Set the configuration path based on the platform's abilities
$config_path = realpath( dirname( __FILE__ ) ) . '/resources/w3-total-cache-config_default.php';
// Copy our config to W3TC's default config path
file_put_contents( W3TC_CONFIG_PATH, file_get_contents( $config_path ) );
// Initialize 2 config objects
$old_config = new W3_Config(); // Default config
$new_config = new W3_Config(); // Our config
// Load our config file
$new_config->read( W3TC_CONFIG_PATH );
// Overwrite the default config with our values
$admin = w3_instance( 'W3_Plugin_TotalCacheAdmin' );
$admin->config_save( $old_config, $new_config );
// Disable W3TC preview mode
if ( file_exists( W3TC_CONFIG_PREVIEW_PATH ) )
unlink( W3TC_CONFIG_PREVIEW_PATH );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment