I came across this because I had my cache turned off which made Drupal execute some additional code - sometimes. That additional code just happened to call init_theme(). However, it was ultimately triggered by line 106 ($theme = _themekey_match_paths($_GET['q']);) in themekey.module in function themekey_init().
init_theme() can be called in all sorts of manner because module_invoke_all() calls are encountered from calling _themekey_match_paths($_GET['q']);. For example in my setup one added module called something that called t() and t() call init_theme(), it got called from node_load() as well when cache was turned off.
If init_theme() is called before it is explicitly called at the bottom of themekey_init() then the result will probably be that the default theme is shown regardless of the setting for themekey.
My workaround is to add this $GLOBALS line at the top of themekey_init() like this:
function themekey_init() {
global $custom_theme;
$theme = NULL;
if (!isset($GLOBALS['theme'])) $GLOBALS['theme'] = 'dummy';
and then to add the logical opposite $GLOBALS line at the bottom like this:
$custom_theme = $theme;
unset($GLOBALS['theme']));
init_theme();
}
}
This takes advantage of these lines in init_theme():
function init_theme() {
global $theme, $user, $custom_theme, $theme_key;
// If $theme is already set, assume the others are set, too, and do nothing
if (isset($theme)) {
return;
}
fooling init_theme() into believing the theme is already set and therefore make it do nothing until we are ready to explicitly call it.
Comments
Comment #1
reg commentedOops, here's a modified ending needed for when the the default theme is the correct theme.
Please note, this is just a quick workaround and not yet extensively tested, use with caution!
Comment #2
Sunshiney commentedIs the maintainer around to incorporate these changes??? I am noticing a long list of bugs
Comment #3
reg commentedNo kidding, I just saw the list and it goes back 39 weeks. What happens when a maintainer apparently has abandoned a project but has not formally done anything about it?
Comment #4
mkalkbrennersee http://drupal.org/node/552994#comment-1947298
Comment #5
mkalkbrennerThemeKey 6.x-1.2beta doesn't call init_theme() anymore. See #482766: Themekey overriding administration theme on node edit