--- conditional_styles/conditional_styles.theme.inc~	2009-05-25 10:33:03.000000000 -0400
+++ conditional_styles/conditional_styles.theme.inc	2010-06-01 00:04:45.000000000 -0400
@@ -39,63 +39,82 @@ function _conditional_styles_theme($exis
   // implementation: foreach ($array AS $key => &$value) {}
 
   // Process the conditional stylesheets for every active theme.
+  // Grab the list of all active themes.
   global $language;
   $themes = list_themes();
   foreach (array_keys($themes) AS $theme) {
-    // We only need to process active themes.
     if ($themes[$theme]->status) {
-      $paths = conditional_styles_paths_to_basetheme($theme);
+      $active_themes[] = $theme;
+    }
+  }
+  // Grab the current theme and admin theme explicitly just in case neither is
+  // marked "enabled."
+  global $theme_key;
+  $active_themes[] = $theme_key;
+  if (variable_get('admin_theme', NULL)) {
+    $active_themes[] = variable_get('admin_theme', NULL);
+  }
+  // Now walk the list and recursively add any possible base themes which
+  // might also not be marked as "enabled."
+  foreach ($active_themes as $child_theme) {
+    while (isset($themes[$child_theme]->info['base theme'])) {
+      $child_theme = $themes[$child_theme]->info['base theme'];
+      $active_themes[] = $child_theme;
+    }
+  }
+  foreach (array_unique($active_themes) AS $theme) {
+    $paths = conditional_styles_paths_to_basetheme($theme);
 
-      // Grab all the conditional stylesheets.
-      $stylesheets = array();
-      // Start with the base theme and travel up the chain to the active theme.
-      foreach ($paths AS $theme_name => $path) {
-        // Look at the conditional-stylesheets defined in the theme's .info file.
-        if (!empty($themes[$theme_name]->info['conditional-stylesheets'])) {
-          foreach ($themes[$theme_name]->info['conditional-stylesheets'] AS $condition => $css) {
-            // Allow the theme to override its base themes' styles.
-            foreach ($css AS $media => $files) {
-              foreach ($files AS $file) {
-                $stylesheets[$condition][$media][$file] = $path;
-              }
+    // Grab all the conditional stylesheets.
+    $stylesheets = array();
+    // Start with the base theme and travel up the chain to the active theme.
+    foreach ($paths AS $theme_name => $path) {
+      // Look at the conditional-stylesheets defined in the theme's .info file.
+      if (!empty($themes[$theme_name]->info['conditional-stylesheets'])) {
+        foreach ($themes[$theme_name]->info['conditional-stylesheets'] AS $condition => $css) {
+          error_log("DEBUG: $condition => $css");
+          // Allow the theme to override its base themes' styles.
+          foreach ($css AS $media => $files) {
+            foreach ($files AS $file) {
+              $stylesheets[$condition][$media][$file] = $path;
             }
           }
         }
       }
-      // Render the stylesheets to link elements.
-      $conditional_styles = '';
-      if (!empty($stylesheets)) {
-        $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);
-        $base_path = base_path();
-        foreach ($stylesheets AS $condition => $css) {
-          // Each condition requires its own set of links.
-          $output = '';
-          foreach ($css AS $media => $files) {
-            foreach ($files AS $file => $path) {
-              // Don't allow non-existent stylesheets to clutter the logs with 404.
-              if (file_exists("./$path/$file")) {
-                $output .= "<link type=\"text/css\" rel=\"stylesheet\" media=\"$media\" href=\"$base_path$path/$file$query_string\" />\n";
-                if ($language->direction == LANGUAGE_RTL){
-                  $file_rtl = str_replace('.css', '-rtl.css', $file);
-                  if (file_exists("./$path/$file_rtl")) {
-                    $output .= "<link type=\"text/css\" rel=\"stylesheet\" media=\"$media\" href=\"$base_path$path/$file_rtl$query_string\" />\n";
-                  }
+    }
+    // Render the stylesheets to link elements.
+    $conditional_styles = '';
+    if (!empty($stylesheets)) {
+      $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);
+      $base_path = base_path();
+      foreach ($stylesheets AS $condition => $css) {
+        // Each condition requires its own set of links.
+        $output = '';
+        foreach ($css AS $media => $files) {
+          foreach ($files AS $file => $path) {
+            // Don't allow non-existent stylesheets to clutter the logs with 404.
+            if (file_exists("./$path/$file")) {
+              $output .= "<link type=\"text/css\" rel=\"stylesheet\" media=\"$media\" href=\"$base_path$path/$file$query_string\" />\n";
+              if ($language->direction == LANGUAGE_RTL){
+                $file_rtl = str_replace('.css', '-rtl.css', $file);
+                if (file_exists("./$path/$file_rtl")) {
+                  $output .= "<link type=\"text/css\" rel=\"stylesheet\" media=\"$media\" href=\"$base_path$path/$file_rtl$query_string\" />\n";
                 }
               }
             }
           }
-          if ($output) {
-            $conditional_styles .= "<!--[$condition]>\n$output<![endif]-->\n";
-          }
+        }
+        if ($output) {
+          $conditional_styles .= "<!--[$condition]>\n$output<![endif]-->\n";
         }
       }
-      // Save the stylesheets for later retrieval.
-      if ($conditional_styles) {
-        variable_set('conditional_styles_' . $theme, $conditional_styles);
-      }
-      else {
-        variable_del('conditional_styles_' . $theme);
-      }
+    }
+    // Save the stylesheets for later retrieval.
+    if ($conditional_styles) {
+      variable_set('conditional_styles_' . $theme, $conditional_styles);
+    }
+    else {
+      variable_del('conditional_styles_' . $theme);
     }
   }
 
