diff --git a/core/includes/form.inc b/core/includes/form.inc
index 5634be8..49ed860 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -2690,8 +2690,9 @@ function theme_select($variables) {
  * @param $element
  *   An associative array containing the properties of the element.
  * @param $choices
- *   Mixed: Either an associative array of items to list as choices, or an
- *   object with an 'option' member that is an associative array. This
+ *   Mixed: Normally an associative array of items to list as choices, or an
+ *   array with 'title', 'value', and '#attribute' array. Additionally this can
+ *   be an object with an 'option' member that is an associative array. This
  *   parameter is only used internally and should not be passed.
  *
  * @return
@@ -2701,30 +2702,57 @@ function form_select_options($element, $choices = NULL) {
   if (!isset($choices)) {
     $choices = $element['#options'];
   }
+
   // array_key_exists() accommodates the rare event where $element['#value'] is NULL.
   // isset() fails in this situation.
   $value_valid = isset($element['#value']) || array_key_exists('#value', $element);
   $value_is_array = $value_valid && is_array($element['#value']);
   $options = '';
+
   foreach ($choices as $key => $choice) {
+
+    // Allow overloading options with an array.
     if (is_array($choice)) {
-      $options .= '<optgroup label="' . $key . '">';
-      $options .= form_select_options($element, $choice);
-      $options .= '</optgroup>';
-    }
-    elseif (is_object($choice)) {
-      $options .= form_select_options($element, $choice->option);
+      if (isset($choice['value'])) {
+        // Overloaded option array.
+        $optValue = (string) $choice['value'];
+      }
+      else {
+        if (isset($choice['title'])) {
+          // Optgroup for special menu items.
+          $options .= '<optgroup label="' . $choice['title'] . '"></optgroup>';
+        }
+        else {
+          // Normal optgroups
+          $options .= '<optgroup label="' . $key . '">';
+          $options .= form_select_options($element, $choice);
+          $options .= '</optgroup>';
+        }
+      }
     }
     else {
-      $key = (string) $key;
-      if ($value_valid && (!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'])))) {
+      // Simple options.
+      $optValue = $key;
+      $choice = array(
+        'title' => $choice,
+      );
+    }
+
+    // Create the HTML output.
+    if (isset($optValue)) {
+      if (!isset($choice['#attributes'])) {
+        $choice['#attributes'] = array();
+      }
+      // Note this make the first item no longer selected, but that doesn't matter.
+      if ($value_valid && (!$value_is_array && (string) $element['#value'] === $optValue || ($value_is_array && in_array($optValue, $element['#value'])))) {
         $selected = ' selected="selected"';
       }
       else {
         $selected = '';
       }
-      $options .= '<option value="' . check_plain($key) . '"' . $selected . '>' . check_plain($choice) . '</option>';
+      $options .= '<option value="' . check_plain($optValue) . '"' . $selected . drupal_attributes($choice['#attributes']) . '>' . check_plain($choice['title']) . '</option>';
     }
+    unset($optValue);
   }
   return $options;
 }
