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

reg’s picture

Oops, here's a modified ending needed for when the the default theme is the correct theme.

  if ($GLOBALS['theme'] == 'dummy') {
    unset($GLOBALS['theme']);
  }
  // We have a theme, apply it
  if ($theme && $theme != 'default') {
    if (variable_get('themekey_theme_maintain', 0)) {
      $_SESSION['themekey_theme'] = $theme;
    }
    $custom_theme = $theme;
    init_theme();
  }
}

Please note, this is just a quick workaround and not yet extensively tested, use with caution!

Sunshiney’s picture

Is the maintainer around to incorporate these changes??? I am noticing a long list of bugs

reg’s picture

No 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?

mkalkbrenner’s picture

mkalkbrenner’s picture

Status: Active » Fixed

ThemeKey 6.x-1.2beta doesn't call init_theme() anymore. See #482766: Themekey overriding administration theme on node edit

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.