[wp-hackers] switch_theme cache inconsistency while WP_INSTALLING
raphael.droz at gmail.com
Tue Mar 23 10:49:52 UTC 2010
Potkanski, Jason wrote:
> There is a "Blog Defaults" MU plugin out there as well.
The plugins is stuck with this bug that I also encoutered
in my own hooks :
The problem I spent hours on is in "switch_theme" but maybe affect other
settings as well.
Assume you create a new blog :
If you hook into populate_option | wpmu_new_blog
then WP_INSTALLING is defined.
Well, so if you happen to use update_option in your hook ...
(wpmu_new_blog would imply that template already ='default')
... what happens ? :
/* in update_option : */
if ( ! defined( 'WP_INSTALLING' ) )
/* update cache */
But here WP_INSTALLING is true so our old cached value isn't updated.
Let's have a look at get_option() now :
We can expect that if defined(WP_INSTALLING) we won't use the cache isn't ?
That's not the case, in get_option(), a $value = wp_cache_get(
$setting, 'options' ) is done
if defined(WP_INSTALLING) and we retrieve the wrong value.
You can test by doing the following :
In switch_theme(), replace an update_option() by:
if(update_option('template', $template) === true )
logit(" template update : ok\n")
/* logit can be a fopen(ABSPATH . '/log.log', 'a'); */
logit( " template now = " . get_option('template') . "\n");
So, in the successive call to get_current_theme(), get_option() returns
so current_theme is set to 'WordPress Default', so the
user/hook-requested theme is used,
but not shown as used in the theme menu.
More information about the wp-hackers