Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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();
        }
    }   
}
share|improve this question
    
i also use ai1ec and w3 total cache - works fine for me. but please try which type of caching breaks the plugin - i suppose it is the cache database option. if you can specify this, i can take a better look at it. another thing to try is to autoload the ``ai1ec_settings` - you should have a complete object available after doing this. –  fischi May 4 '12 at 9:19
    
@fischi it's the object cache when thatcache is set to "Disk", if i use opcode caching i have no problems –  Nicola Peluchetti May 4 '12 at 9:22
    
okay, here we go. try this: in your functions.php modify the behaviour of ai1ec_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:28
    
@fischi i can't try this now but you got me on the right track, i think that add_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
    
okay, so the other way round ;) please keep me informed which way worked, and if needed modify my answer :) –  fischi May 4 '12 at 9:41
add comment

2 Answers

up vote 1 down vote accepted

okay, here we go. try this: in your functions.php modify the behaviour of ai1ec_options:

$ai1ec_options = get_option('ai1ec_options');
delete_option('ai1ec_options');
add_option('ai1ec_options', $ai1ec_options, '', 'no'); // thanks for your suggestion :)

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.

share|improve this answer
    
This solved the problem (i tested on a fresh installation and if the option was autoloaded i had the error, no error with no autoloading). Now i just need to think a way to solve this for the next release of the plugin withouth erasing saved the options. Thanks for your help :) –  Nicola Peluchetti May 4 '12 at 10:05
    
@NicolaPeluchetti no problem, thank you for the report! –  fischi May 4 '12 at 10:35
add comment

I was just battling with this on page.ly, who uses W3TC and then Memcached for their object cache.

Looking at how ai1ec has solved it the solution seems to be:

wp_cache_delete( 'alloptions', 'options' );

This was confirmed by page.ly found in the support ticket I was discussing the issue at.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.