a plugin i'm working on has a conflict with w3 total cache. To be more specific, in my code i have
static function get_instance()
{
if( self::$_instance === NULL ) {
// get the settings from the database
self::$_instance = get_option( 'ai1ec_settings' );
// if there are no settings in the database
// save default values for the settings
if( ! self::$_instance ) {
self::$_instance = new self();
delete_option( 'ai1ec_settings' );
add_option( 'ai1ec_settings', self::$_instance );
} else {
self::$_instance->set_defaults(); // set default settings
}
}
return self::$_instance;
}
The problem lies in self::$_instance = get_option( 'ai1ec_settings' ); because un incomplete object is returned (this happens only when using w3 total cache, i have declared an autoloader, but doing some debugging it seems that the incomplete object is stored in the cache)
This is the error message
Ai1ec_Settings::get_instance(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Ai1ec_Settings" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition
1) Is there a way to tell w3 total cache not to cache that option?
2) If not, it would be correct to handle things like this?
try {
self::$_instance = self::getOptionsFromDb();
} catch (Exception $e) {
//Show a friendly error page
}
private static function getOptionsFromDb(){
$ai1ec_settings = get_option( 'ai1ec_settings' );
if ( ! $ai1ec_settings instanceof self ) {
if (false === $ai1ec_settings) {
return false; //option was not set in the db
} elseif( class_exists('W3_Plugin_TotalCacheAdmin') ){
//let's clear thew cache and try again
$plugin_totalcacheadmin = & w3_instance('W3_Plugin_TotalCacheAdmin');
$plugin_totalcacheadmin->flush_all();
$ai1ec_settings = get_option( 'ai1ec_settings' );
if ( $ai1ec_settings instanceof self ) {
return $ai1ec_settings;
} else {
throw new Exception();
}
} else {
throw new Exception();
}
}
}
functions.phpmodify the behaviour ofai1ec_options:$ai1ec_options = get_option('ai1ec_options'); delete_option('ai1ec_options');add_option('ai1ec_options', $ai1ec_options, '', 'yes');be careful though, as you might lose your set options, so be sure to get them from the database first. or create a backup option. afterwards, clear the caches and try again. – fischi May 4 '12 at 9:28add_option('ai1ec_options', $ai1ec_options, '', 'no');could do the trick, because the problem was in the wp_load_alloptions() function!You should add this as an answer – Nicola Peluchetti May 4 '12 at 9:33