4.6.x theme.inc init_theme()
4.7.x theme.inc init_theme()
5.x theme.inc init_theme()
6.x theme.inc init_theme()

Initialize the theme system by loading the theme.

5 calls to init_theme()
block_admin_display_form in modules/block/block.admin.inc
Generate main blocks administration form.
drupal_render_form in includes/form.inc
Renders a structured form array into themed HTML.
path_to_theme in includes/theme.inc
Return the path to the current themed element.
theme in includes/theme.inc
Generates the themed output.
_block_rehash in modules/block/block.module
Update the 'blocks' DB table with the blocks currently exported by modules.

File

includes/theme.inc, line 42
The theme system, which controls the output of Drupal.

Code

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;
  }
  drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
  $themes = list_themes();

  // Only select the user selected theme if it is available in the
  // list of enabled themes.
  $theme = !empty($user->theme) && !empty($themes[$user->theme]->status) ? $user->theme : variable_get('theme_default', 'garland');

  // Allow modules to override the present theme... only select custom theme
  // if it is available in the list of installed themes.
  $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;

  // Store the identifier for retrieving theme settings with.
  $theme_key = $theme;

  // Find all our ancestor themes and put them in an array.
  $base_theme = array();
  $ancestor = $theme;
  while ($ancestor && isset($themes[$ancestor]->base_theme)) {
    $base_theme[] = $new_base_theme = $themes[$themes[$ancestor]->base_theme];
    $ancestor = $themes[$ancestor]->base_theme;
  }
  _init_theme($themes[$theme], array_reverse($base_theme));
}

Comments

Anonymous’s picture

In Drupal 7, the function has been replaced from drupal_theme_initialize().

rooby’s picture

If this function is called, directly or indirectly, from a menu wildcard loader function (see http://drupal.org/node/209056) it can cause problems with your theme.

jvieille’s picture

I fight for a couple of days again a weird bug : theme override by $custom_theme did not work anymore.
The $theme variable was set so $custom_theme was never processed.
I found this post http://www.rdlt.com/drupal-5-views-module-breasks-block-administration.html that gave me the solution.

...
// If $theme is already set, assume the others are set, too, and do nothing
if (isset($theme)) {
return;
}
...
should become

// If $theme is already set, assume the others are set, too, and do nothing
// patchy patchy!
if (isset($theme)) {
if(isset($custom_theme)) {
if($theme == $custom_theme) {
return;
}
} else {
return;
}
}