Same name and namespace in other branches
  1. 4.6.x includes/theme.inc \init_theme()
  2. 4.7.x includes/theme.inc \init_theme()
  3. 5.x includes/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));
}